-
Notifications
You must be signed in to change notification settings - Fork 128
*: bump-minor-version gh action #4084
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
base: main
Are you sure you want to change the base?
Changes from all commits
f3647a2
bedc4f3
4db3809
61e2110
a25e871
0b865b0
3270a72
4093b1a
ca6bced
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| name: Bump Minor Version | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| create_minor_release_pr: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: 1. Checkout main branch | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 # Required to get all tags for versioning | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: 2. Get and Increment Version | ||
| id: bump | ||
| uses: mathieudutour/github-tag-action@a22cf08638b34d5badda920f9daf6e72c477b07b # v6.2 | ||
| with: | ||
| github_token: ${{ secrets.GITHUB_TOKEN }} | ||
| # NOTE: This workflow ignores conventional commit messages and always bumps the minor version. | ||
| default_bump: minor # Will go from v1.7.X -> v1.8.0 | ||
| dry_run: true # Don't create tag yet, just calculate the new version | ||
|
|
||
| - name: 3. Set Variables for New Release | ||
| id: vars | ||
| run: | | ||
| # Use the 'new_tag' output, e.g., "v1.8.0" | ||
| BUMPED_VERSION="${{ steps.bump.outputs.new_tag }}" | ||
|
|
||
| # Extract major and minor version numbers | ||
| # Handles formats: v1.8.0, v1.8-dev, v1.8-rc1, etc. | ||
| MAJOR=$(echo "$BUMPED_VERSION" | sed -E 's/^v([0-9]+)\.([0-9]+).*/\1/') | ||
| MINOR=$(echo "$BUMPED_VERSION" | sed -E 's/^v([0-9]+)\.([0-9]+).*/\2/') | ||
|
|
||
| # Validate that we successfully extracted major and minor versions | ||
| if [[ -z "$MAJOR" ]] || [[ -z "$MINOR" ]]; then | ||
| echo "::error::Failed to extract major/minor version from: $BUMPED_VERSION" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Validate that major and minor are numeric | ||
| if ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::Invalid version format. MAJOR=$MAJOR, MINOR=$MINOR (expected numeric values)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Create RC version format: v1.8-rc | ||
| NEW_V_VERSION="v${MAJOR}.${MINOR}-rc" | ||
|
|
||
| # Create branch names | ||
| RELEASE_BRANCH="main-v${MAJOR}.${MINOR}" | ||
| WORK_BRANCH="gh-actions/bump-version-to-v${MAJOR}.${MINOR}" | ||
|
|
||
| echo "NEW_V_VERSION=${NEW_V_VERSION}" >> $GITHUB_OUTPUT | ||
| echo "MAJOR=${MAJOR}" >> $GITHUB_OUTPUT | ||
| echo "MINOR=${MINOR}" >> $GITHUB_OUTPUT | ||
| echo "RELEASE_BRANCH=${RELEASE_BRANCH}" >> $GITHUB_OUTPUT | ||
| echo "WORK_BRANCH=${WORK_BRANCH}" >> $GITHUB_OUTPUT | ||
|
|
||
| echo "::notice::Extracted versions - MAJOR: ${MAJOR}, MINOR: ${MINOR}" | ||
| echo "::notice::Creating release branch: ${RELEASE_BRANCH}" | ||
| echo "::notice::Creating work branch: ${WORK_BRANCH}" | ||
| echo "::notice::New version: ${NEW_V_VERSION}" | ||
|
|
||
| - name: 4. Create Release Branch | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where did we get this one from?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the default action bot's email, see https://github.com/orgs/community/discussions/119597 |
||
|
|
||
| RELEASE_BRANCH="${{ steps.vars.outputs.RELEASE_BRANCH }}" | ||
|
|
||
| # Create the release branch from main (use -B to reset if exists) | ||
| git checkout -B "$RELEASE_BRANCH" | ||
| git push origin "$RELEASE_BRANCH" | ||
pinebit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| # The release branch is already checked out; no need to checkout again. | ||
|
|
||
|
|
||
| echo "::notice::Created and pushed release branch: $RELEASE_BRANCH" | ||
|
|
||
| - name: 5. Modify App Version in Code | ||
| run: | | ||
| VERSION_FILE="app/version/version.go" | ||
| NEW_VERSION="${{ steps.vars.outputs.NEW_V_VERSION }}" | ||
|
|
||
| echo "::notice file=$VERSION_FILE,line=18::Bumping version in $VERSION_FILE to $NEW_VERSION" | ||
|
|
||
| # Use sed to find the line and replace only the version string | ||
| sed -i -E "s/^(var version = ).*/\1\"$NEW_VERSION\"/" "$VERSION_FILE" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will essentially update
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Overlooked the -rc part..
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
|
|
||
| # Verify the change | ||
| echo "--- Verifying change in $VERSION_FILE" | ||
| grep "var version" "$VERSION_FILE" | ||
| echo "---" | ||
|
|
||
| - name: 6. Create Pull Request to Release Branch | ||
| uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v7.0.5 | ||
| with: | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
| commit-message: "app: bump minor version to ${{ steps.vars.outputs.NEW_V_VERSION }}" | ||
| committer: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" | ||
| author: "github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>" | ||
| branch: ${{ steps.vars.outputs.WORK_BRANCH }} | ||
| base: ${{ steps.vars.outputs.RELEASE_BRANCH }} | ||
| delete-branch: true | ||
| title: "app: bump minor version to ${{ steps.vars.outputs.NEW_V_VERSION }}" | ||
| body: | | ||
| This pull request was automatically generated by the 'Bump Minor Version' GitHub Action. | ||
|
|
||
| - **Previous Release:** ${{ steps.bump.outputs.previous_tag }} | ||
| - **New Version:** ${{ steps.vars.outputs.NEW_V_VERSION }} | ||
| - **Target Branch:** `${{ steps.vars.outputs.RELEASE_BRANCH }}` | ||
|
|
||
| ## Changes | ||
| - Updated version in `app/version/version.go` from `${{ steps.bump.outputs.previous_tag }}` to `${{ steps.vars.outputs.NEW_V_VERSION }}` | ||
pinebit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Next Steps | ||
| After this PR is merged, the `${{ steps.vars.outputs.RELEASE_BRANCH }}` branch will have the updated version and can be used for further release processes. | ||
|
|
||
| category: misc | ||
| ticket: none | ||
Uh oh!
There was an error while loading. Please reload this page.