Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make sure that version bumping happens everytime #1090

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 11 additions & 45 deletions .github/workflows/release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
85 changes: 85 additions & 0 deletions .github/workflows/release-bump-version.yaml
Original file line number Diff line number Diff line change
@@ -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.' || '' }}
28 changes: 14 additions & 14 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
10 changes: 2 additions & 8 deletions api/version/generate/release_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down