diff --git a/.github/workflows/bump-minor-version.yml b/.github/workflows/bump-minor-version.yml new file mode 100644 index 000000000..b09a6dd8f --- /dev/null +++ b/.github/workflows/bump-minor-version.yml @@ -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" + + 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" + + # 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" + + # 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 }}` + + ## 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