From 3af44f870db70655ac7e47eb0fd040617e164657 Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Wed, 28 Aug 2024 16:47:49 +0200 Subject: [PATCH] chore: always create a new release branch and delete all old ones during new release action (#894) #### What this PR does / why we need it When we create a new release, then let's always be prepared for a potential hotfix and create the release branch. On the other hand, this will create a lot of unused branches over the time, so the PR will delete all older release branches. In case of serious situation, where we really need to fix older versions, we still have the tags in place and would need to create manually a patched old release. #### Which issue(s) this PR fixes releates https://github.com/open-component-model/ocm-project/issues/240 --- .../config/goreleaser.yaml | 0 .github/pull_request_template.md | 4 --- .github/workflows/lint_and_test.yaml | 4 +-- .github/workflows/release.yaml | 32 +++++++++---------- 4 files changed, 17 insertions(+), 23 deletions(-) rename .goreleaser.yaml => .github/config/goreleaser.yaml (100%) diff --git a/.goreleaser.yaml b/.github/config/goreleaser.yaml similarity index 100% rename from .goreleaser.yaml rename to .github/config/goreleaser.yaml diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index a88b718453..d9fe330b63 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,7 +1,3 @@ ---- -labels: kind/skip-release-notes ---- - #### What this PR does / why we need it diff --git a/.github/workflows/lint_and_test.yaml b/.github/workflows/lint_and_test.yaml index 08a037170f..ab1a855220 100644 --- a/.github/workflows/lint_and_test.yaml +++ b/.github/workflows/lint_and_test.yaml @@ -67,7 +67,6 @@ jobs: - name: Setup lint run: | make -f hack/Makefile golangci-lint - #curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 - name: Lint run: | PATH=$PATH:$(go env GOPATH)/bin make check @@ -78,7 +77,7 @@ jobs: steps: - name: Self Hosted Runner Post Job Cleanup Action uses: TooMuch4U/actions-clean@v2.2 - + - name: Checkout uses: actions/checkout@v4 with: @@ -103,4 +102,3 @@ jobs: - name: Check for diff run: | git diff --exit-code --shortstat - diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b3f9191562..e8f59d6413 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -5,19 +5,14 @@ on: inputs: release_candidate: type: boolean - description: "Release Candidate" - required: false - default: false - create_branch: - type: boolean - description: "Create Release Branch" + description: 'Release Candidate' required: false default: false prerelease: type: string - description: "Release Candidate Name" + description: 'Release Candidate Name' required: false - default: "" + default: '' jobs: check: @@ -46,11 +41,6 @@ jobs: else v="v$(go run $GITHUB_WORKSPACE/api/version/generate print-version)" echo "Final Release: $v" - if ${{ github.event.inputs.create_branch }}; then - echo "with release branch creation" - else - echo "without release branch creation" - fi fi - name: Set Base Version @@ -79,7 +69,7 @@ jobs: fi - name: Check Branch - if: inputs.release_candidate == false && inputs.create_branch + if: inputs.release_candidate == false && github.ref == 'refs/heads/main' run: | set -e if git ls-remote --exit-code origin refs/heads/releases/${{ env.RELEASE_VERSION }} ; then @@ -225,7 +215,7 @@ jobs: with: distribution: goreleaser version: 2.1.0 - args: release --clean --timeout 60m --skip=validate --config=./.goreleaser.yaml --release-notes=${{ env.RELEASE_NOTES_FILE }} + args: release --clean --timeout 60m --skip=validate --config=.github/config/goreleaser.yaml --release-notes=${{ env.RELEASE_NOTES_FILE }} env: GITHUBORG: ${{ github.repository_owner }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -240,7 +230,7 @@ jobs: run: make plain-push - name: Create Release Branch - if: inputs.release_candidate == false && inputs.create_branch + if: inputs.release_candidate == false && github.ref == 'refs/heads/main' run: | n="releases/${{env.RELEASE_VERSION}}" git checkout -b "$n" @@ -262,6 +252,16 @@ jobs: git push origin ${GITHUB_REF#refs/heads/} echo "Next branch version is $v" + - name: Delete Older Release Branches + if: github.ref == 'refs/heads/main' + run: | + set -e + git fetch --prune + for branch in $(git branch -r | grep 'origin/releases/' | grep -v 'origin/releases/${{ env.RELEASE_VERSION }}'); do + branch_name=$(echo $branch | sed 's|origin/||') + echo "Deleting branch $branch_name" + done + - name: Publish Release Event if: inputs.release_candidate == false uses: peter-evans/repository-dispatch@v3