From a9ae07cdde2739a530b65fba9487703ff1d87f30 Mon Sep 17 00:00:00 2001 From: Marco Ebert Date: Thu, 25 Jul 2024 15:34:42 +0200 Subject: [PATCH] GitHub: Development. --- .github/workflows/create-release.yaml | 78 +++++++++++++++++++++++++++ .github/workflows/release.yaml | 67 +++++++++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 .github/workflows/create-release.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/create-release.yaml b/.github/workflows/create-release.yaml new file mode 100644 index 000000000..03a660a03 --- /dev/null +++ b/.github/workflows/create-release.yaml @@ -0,0 +1,78 @@ +name: Create GitHub release + +on: + pull_request: + types: [closed] + +jobs: + create_release: + if: github.event.pull_request.merged == true + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: '0' + fetch-tags: 'true' + - name: Set up git identity + run: | + git config --local user.email "dev@giantswarm.io" + git config --local user.name "taylorbot" + - name: Create new release tag + run: | + git fetch --tags + for provider_dir in capa/v* azure/v*; do + provider="" + if [[ $provider_dir == capa/* ]]; then + provider="aws" + elif [[ $provider_dir == azure/* ]]; then + provider="azure" + fi + if [[ ! -f $provider_dir/release.yaml || -z $provider ]]; then + echo "Skipping file or unknown provider $provider_dir" + continue + fi + release_version="$(basename $provider_dir)" + echo "Found $provider release $release_version." + tag_name="$provider/$release_version" + if [ $(git tag -l "$tag_name") ]; then + echo "Found existing tag $tag_name for release version $release_version, new tag is not needed." + else + echo "Tag $tag_name for release version $release_version not found, will create it." + tag_message="Workload cluster release $release_version for $provider" + git tag -a "$tag_name" -m "$tag_message" + git push origin "$tag_name" + fi + done + - name: Create new GitHub release + env: + GITHUB_TOKEN: "${{ secrets.TAYLORBOT_GITHUB_ACTION }}" + run: | + for provider_dir in capa/v* azure/v*; do + provider="" + if [[ $provider_dir == capa/* ]]; then + provider="aws" + elif [[ $provider_dir == azure/* ]]; then + provider="azure" + fi + if [[ ! -f $provider_dir/release.yaml || -z $provider ]]; then + echo "Skipping file or unknown provider $provider_dir" + continue + fi + release_version="$(basename $provider_dir)" + tag_name="$provider/$release_version" + github_release=$(gh release --repo giantswarm/releases view "$tag_name" --json "id,name,tagName,assets,isDraft,isPrerelease,url" 2>&1 || true) + current_commit="$(git rev-parse HEAD)" + release_title="Workload cluster release $release_version for $provider" + release_note="This release has been created automatically by GitHub action. CI will be updated to have better release notes here." + if [ "$github_release" = "release not found" ]; then + echo "Didn't find a GitHub release for release version $release_version and tag $tag_name. Creating a new release." + if [[ $release_version == *-* ]]; then + gh release create --repo giantswarm/releases --target "$current_commit" --title "$release_title" --notes "$release_note" "$tag_name" "$provider_dir/release.yaml" --prerelease + else + gh release create --repo giantswarm/releases --target "$current_commit" --title "$release_title" --notes "$release_note" "$tag_name" "$provider_dir/release.yaml" + fi + else + echo "Found existing GitHub release for release version $release_version and tag $tag_name." + fi + done diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..6aa553524 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,67 @@ +name: Release + +on: + push: + branches: + - liljx + +jobs: + get-releases: + name: Get releases + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Get releases + id: get-releases + run: | + # Get releases. + releases="$(dirname azure/v*/release.yaml capa/v*/release.yaml)" + + # Convert releases into JSON. + releases="$(echo "${releases}" | jq --raw-input --slurp 'split("\n")[:-1]' --compact-output)" + + # Store releases. + echo releases="${releases}" >> "${GITHUB_OUTPUT}" + - name: Print releases + run: echo "${{ steps.get-releases.outputs.releases }}" + + outputs: + releases: ${{ steps.get-releases.outputs.releases }} + + print-release: + name: Print release + runs-on: ubuntu-latest + needs: get-releases + + strategy: + matrix: + release: ${{ fromJSON(needs.get-releases.outputs.releases) }} + + steps: + - name: Print release + env: + release: ${{ matrix.release }} + run: echo "${release}" + - name: Get provider + id: get-provider + env: + release: ${{ matrix.release }} + run: | + # Get provider. + provider="${release:h}" + + # Switch release. + case "${provider}" in + capa) + provider="aws" + ;; + esac + + # Store provider. + echo provider="${provider}" >> "${GITHUB_OUTPUT}" + - name: Print provider + env: + provider: ${{ steps.get-provider.outputs.provider }} + run: echo "${provider}"