From bb7c5f7639d35c2ab3b718571f80445a9a7fc3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20M=C3=B6ller?= Date: Fri, 15 Nov 2024 21:57:07 +0100 Subject: [PATCH] chore: make sure that version bumping happens everytime (#1090) #### What this PR does / why we need it This makes sure that we dont only do a patch bump on main after a successful branch cut, but we also do a bump on the release branch (for the next z / patch version) after the minor has been released. Creates a shared workflow that can be called from other workflows. #### Which issue(s) this PR fixes Ensures more automated workflows after the rework from https://github.com/open-component-model/ocm/issues/995 Example run at https://github.com/open-component-model/ocm-cicd-playground/actions/runs/11838213132/job/32986884073 --- .github/workflows/release-branch.yaml | 56 +++----------- .github/workflows/release-bump-version.yaml | 85 +++++++++++++++++++++ .github/workflows/release.yaml | 28 +++---- api/version/generate/release_generate.go | 10 +-- 4 files changed, 112 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/release-bump-version.yaml diff --git a/.github/workflows/release-branch.yaml b/.github/workflows/release-branch.yaml index e19a45abe3..f63d279c5f 100644 --- a/.github/workflows/release-branch.yaml +++ b/.github/workflows/release-branch.yaml @@ -88,49 +88,15 @@ jobs: git checkout -b "$branch" git push origin $branch + # Make sure main contains the next minor after cutoff bump-main-pr: - runs-on: ubuntu-latest - needs: [create-branch, cutoff-preconditions] # wait for the release branch to be created, then create a version bump - steps: - - name: Generate token - id: generate_token - uses: tibdex/github-app-token@v2 - with: - app_id: ${{ secrets.OCMBOT_APP_ID }} - private_key: ${{ secrets.OCMBOT_PRIV_KEY }} - - name: Checkout - uses: actions/checkout@v4 - with: - ref: main - token: ${{ steps.generate_token.outputs.token }} - - name: Version Bump - id: version-bump - run: | - set -e - - echo "determining next version" - version=$(go run ./api/version/generate bump-version) - - echo "bumping main branch to $version" - echo $version > VERSION - - echo "version=$version" >> $GITHUB_OUTPUT - echo "version after bump: $version" - - - name: Create Pull Request - uses: peter-evans/create-pull-request@v7 - with: - token: ${{ steps.generate_token.outputs.token }} - title: "chore: bump VERSION to ${{ steps.version-bump.outputs.version }}" - commit-message: "[github-actions] Bump to ${{ steps.version-bump.outputs.version }} after branch cutoff" - branch: "chore/bump-main/v${{ steps.version-bump.outputs.version }}" - delete-branch: true - sign-commits: true - add-paths: | - VERSION - body: | - Update OCM Version to ${{ steps.version-bump.outputs.version }} - - After the release branch cutoff into ${{ needs.cutoff-preconditions.outputs.branch }}, - this bumps the OCM version so that future development continues on the next minor release. - + uses: ./.github/workflows/release-bump-version.yaml + needs: create-branch + permissions: + contents: write + id-token: write + packages: write + secrets: inherit + with: + bump-type: minor + ref: ${{ github.ref }} \ No newline at end of file diff --git a/.github/workflows/release-bump-version.yaml b/.github/workflows/release-bump-version.yaml new file mode 100644 index 0000000000..1286cda04f --- /dev/null +++ b/.github/workflows/release-bump-version.yaml @@ -0,0 +1,85 @@ +name: Bump VERSION + +on: + workflow_call: + inputs: + ref: + description: "The branch to bump, use the branch the workflow is called on by default" + required: true + default: "" + type: string + bump-type: + description: "The type of bump to perform, one of 'minor' or 'patch'" + required: true + default: "patch" + type: string + +jobs: + create-bump-pr: + name: "Pull Request" + runs-on: ubuntu-latest + permissions: + contents: write + id-token: write + packages: write + env: + REF: ${{ inputs.ref == '' && github.ref || inputs.ref }} + steps: + - name: Validate Input + run: | + set -e + if [[ ${{ inputs.bump-type }} != "minor" && ${{ inputs.bump-type }} != "patch" ]]; then + >&2 echo "Invalid bump type: ${{ inputs.bump-type }}" + exit 1 + fi + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.OCMBOT_APP_ID }} + private_key: ${{ secrets.OCMBOT_PRIV_KEY }} + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ env.REF }} + sparse-checkout: | + api/version + VERSION + go.mod + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version-file: '${{ github.workspace }}/go.mod' + cache: 'false' + - name: Version Bump + id: version-bump + run: | + set -e + + echo "determining next version" + version=$(go run ./api/version/generate bump-${{ inputs.bump-type }}) + + echo "bumping main branch to $version" + echo $version > VERSION + + echo "version=$version" >> $GITHUB_OUTPUT + echo "version after bump: $version" + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + token: ${{ steps.generate_token.outputs.token }} + title: "chore: bump VERSION to ${{ steps.version-bump.outputs.version }}" + commit-message: "[github-actions] Bump to ${{ steps.version-bump.outputs.version }}" + branch: "chore/bump-${{ inputs.bump-type }}/v${{ steps.version-bump.outputs.version }}" + delete-branch: true + sign-commits: true + add-paths: | + VERSION + body: | + Update OCM Version to ${{ steps.version-bump.outputs.version }} + + This makes sure that the branch contains the next valid version. + + ${{ inputs.bump-type == 'minor' && 'This is a minor bump, the next release will be a new minor version and signals opening of the development branch for new features.' || '' }} + ${{ inputs.bump-type == 'patch' && 'This is a patch bump, intended to allow creation of the next patch release without manually incrementing the VERSION.' || '' }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9c6fdb5d27..5abef69138 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -189,20 +189,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: make plain-push - - name: Bump Version File - if: inputs.release_candidate == false - run: | - set -e - git checkout ${GITHUB_REF#refs/heads/} - v="$(go run ./api/version/generate bump-version)" - echo "$v" > VERSION - # Trigger a bump of any potential files that depend on a new version - make -f hack/Makefile mdref && make -f hack/Makefile go-bindata && make generate - git add --all - git commit -m "Update version to $v" - git push origin ${GITHUB_REF#refs/heads/} - echo "Next branch version is $v" - - name: Publish Release Event if: inputs.release_candidate == false uses: peter-evans/repository-dispatch@v3 @@ -222,3 +208,17 @@ jobs: repository: ${{ github.repository_owner }}/ocm event-type: publish-ocm-cli client-payload: '{"version":"${{ env.RELEASE_VERSION }}","push-to-aur":true,"push-to-chocolatey":true,"push-to-winget":true}' + + # make sure that the branch contains the next valid patch + bump-release-branch-pr: + if: inputs.release_candidate == false + uses: ./.github/workflows/release-bump-version.yaml + needs: release + permissions: + contents: write + id-token: write + packages: write + secrets: inherit + with: + bump-type: patch + ref: ${{ github.ref }} \ No newline at end of file diff --git a/api/version/generate/release_generate.go b/api/version/generate/release_generate.go index d28b4e2122..c5549205d8 100644 --- a/api/version/generate/release_generate.go +++ b/api/version/generate/release_generate.go @@ -94,14 +94,8 @@ func main() { } else { fmt.Printf("%s-%s", v, pre) } - case "bump-version": - var next string - if nonpre.Patch() > 0 { - next = nonpre.IncPatch().String() - } else { - next = nonpre.IncMinor().String() - } - next += "-dev" + case "bump-minor": + next := nonpre.IncMinor().String() + "-dev" fmt.Printf("%s", next) case "bump-patch": next := nonpre.IncPatch().String() + "-dev"