|
| 1 | +name: Version Bump |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + fork_owner: |
| 7 | + description: GitHub username or org that owns the fork |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + fork_repo: |
| 11 | + description: Repository name of the fork |
| 12 | + required: true |
| 13 | + type: string |
| 14 | + pr_base_branch: |
| 15 | + description: Base branch for the PR. Defaults to repository default branch |
| 16 | + required: false |
| 17 | + type: string |
| 18 | + default: "" |
| 19 | + additional_update_script: |
| 20 | + description: Optional path to a bash script file to execute during version bump. The VERSION environment variable will be available. |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + default: "" |
| 24 | + release_date: |
| 25 | + description: Release date in YYYY-MM-DD format. Defaults to current date |
| 26 | + required: false |
| 27 | + type: string |
| 28 | + default: "" |
| 29 | + git_user_name: |
| 30 | + description: Git user name for commits. Defaults to github-actions[bot] |
| 31 | + required: false |
| 32 | + type: string |
| 33 | + default: "github-actions[bot]" |
| 34 | + git_user_email: |
| 35 | + description: Git user email for commits. Defaults to github-actions[bot]@users.noreply.github.com |
| 36 | + required: false |
| 37 | + type: string |
| 38 | + default: "github-actions[bot]@users.noreply.github.com" |
| 39 | + secrets: |
| 40 | + fork_push_token: |
| 41 | + description: PAT with push access to the fork |
| 42 | + required: true |
| 43 | + pr_create_token: |
| 44 | + description: PAT with permission to create PRs on the upstream repo |
| 45 | + required: true |
| 46 | + |
| 47 | +jobs: |
| 48 | + version-bump: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + steps: |
| 51 | + - name: Checkout repository |
| 52 | + uses: actions/checkout@v6 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Check for CHANGELOG file |
| 57 | + id: check-changelog |
| 58 | + run: | |
| 59 | + source actions_helpers.sh |
| 60 | +
|
| 61 | + if [ ! -f CHANGELOG.md ]; then |
| 62 | + log_error "CHANGELOG.md not found in repository root" |
| 63 | + exit 1 |
| 64 | + fi |
| 65 | + log_notice "CHANGELOG.md found" |
| 66 | +
|
| 67 | + - name: Extract release version |
| 68 | + id: extract-version |
| 69 | + uses: cockroachdb/actions/release-version-extract@v0 |
| 70 | + |
| 71 | + - name: Set up git and auto-fork remote |
| 72 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 73 | + env: |
| 74 | + FORK_PUSH_TOKEN: ${{ secrets.fork_push_token }} |
| 75 | + run: | |
| 76 | + # Configure git |
| 77 | + git config user.name "${{ inputs.git_user_name }}" |
| 78 | + git config user.email "${{ inputs.git_user_email }}" |
| 79 | + git config --local credential.helper "!f() { echo \"username=${{ inputs.fork_owner }}\"; echo \"password=\${FORK_PUSH_TOKEN}\"; }; f" |
| 80 | +
|
| 81 | + # Set up auto-fork remote |
| 82 | + fork_url="https://github.com/${{ inputs.fork_owner }}/${{ inputs.fork_repo }}.git" |
| 83 | +
|
| 84 | + if git remote | grep --quiet --fixed-strings --line-regexp "auto-fork"; then |
| 85 | + git remote set-url auto-fork "$fork_url" |
| 86 | + else |
| 87 | + git remote add auto-fork "$fork_url" |
| 88 | + fi |
| 89 | +
|
| 90 | + git remote -v |
| 91 | +
|
| 92 | + - name: Create and checkout version bump branch |
| 93 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 94 | + id: create-branch |
| 95 | + run: | |
| 96 | + source actions_helpers.sh |
| 97 | +
|
| 98 | + branch_name="update-version-${{ steps.extract-version.outputs.next_version }}" |
| 99 | + git checkout -b "$branch_name" |
| 100 | + set_output "branch_name" "$branch_name" |
| 101 | +
|
| 102 | + - name: Update CHANGELOG with new version |
| 103 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 104 | + run: | |
| 105 | + source actions_helpers.sh |
| 106 | +
|
| 107 | + version="${{ steps.extract-version.outputs.next_version }}" |
| 108 | +
|
| 109 | + if [ -n "${{ inputs.release_date }}" ]; then |
| 110 | + release_date="${{ inputs.release_date }}" |
| 111 | + else |
| 112 | + release_date=$(date +%Y-%m-%d) |
| 113 | + fi |
| 114 | +
|
| 115 | + # Insert new version header under [Unreleased] header |
| 116 | + awk -v version="$version" -v date="$release_date" ' |
| 117 | + /^## \[Unreleased\]/ { |
| 118 | + print |
| 119 | + print "" |
| 120 | + print "## [" version "] - " date |
| 121 | + next |
| 122 | + } |
| 123 | + { print } |
| 124 | + ' CHANGELOG.md > CHANGELOG.md.tmp && mv CHANGELOG.md.tmp CHANGELOG.md |
| 125 | +
|
| 126 | + log_notice "Updated CHANGELOG.md with version $version dated $release_date" |
| 127 | +
|
| 128 | + - name: Run additional update script |
| 129 | + if: steps.extract-version.outputs.has_unreleased == 'true' && inputs.additional_update_script != '' |
| 130 | + env: |
| 131 | + VERSION: ${{ steps.extract-version.outputs.next_version }} |
| 132 | + run: | |
| 133 | + source actions_helpers.sh |
| 134 | +
|
| 135 | + log_notice "Running additional update script: ${{ inputs.additional_update_script }}" |
| 136 | + bash -e "${{ inputs.additional_update_script }}" |
| 137 | +
|
| 138 | + - name: Commit version bump changes |
| 139 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 140 | + id: commit-changes |
| 141 | + run: | |
| 142 | + source actions_helpers.sh |
| 143 | +
|
| 144 | + version="${{ steps.extract-version.outputs.next_version }}" |
| 145 | +
|
| 146 | + # Get all changed files (unstaged, staged, and untracked) |
| 147 | + changed_files=$(git diff --name-only && git diff --name-only --cached && git ls-files --others --exclude-standard | sort --unique) |
| 148 | +
|
| 149 | + if [ -z "$changed_files" ]; then |
| 150 | + log_error "No changes to commit after version bump" |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | +
|
| 154 | + # Stage each changed file |
| 155 | + echo "$changed_files" | while read -r file; do |
| 156 | + if [ -n "$file" ]; then |
| 157 | + git add "$file" |
| 158 | + fi |
| 159 | + done |
| 160 | +
|
| 161 | + git commit -m "Prepare release v${version}" \ |
| 162 | + -m "${{ steps.extract-version.outputs.unreleased_changes }}" |
| 163 | +
|
| 164 | + log_notice "Changes committed successfully" |
| 165 | +
|
| 166 | + - name: Push branch to auto-fork |
| 167 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 168 | + run: | |
| 169 | + source actions_helpers.sh |
| 170 | +
|
| 171 | + branch_name="${{ steps.create-branch.outputs.branch_name }}" |
| 172 | + git push auto-fork "$branch_name" |
| 173 | + log_notice "Pushed branch $branch_name to auto-fork" |
| 174 | +
|
| 175 | + - name: Determine base branch for PR |
| 176 | + id: determine-base |
| 177 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 178 | + env: |
| 179 | + GH_TOKEN: ${{ secrets.pr_create_token }} |
| 180 | + run: | |
| 181 | + source actions_helpers.sh |
| 182 | +
|
| 183 | + if [ -n "${{ inputs.pr_base_branch }}" ]; then |
| 184 | + base_branch="${{ inputs.pr_base_branch }}" |
| 185 | + log_notice "Using provided base branch: $base_branch" |
| 186 | + else |
| 187 | + # Get repository default branch |
| 188 | + base_branch=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name') |
| 189 | + if [ -z "$base_branch" ]; then |
| 190 | + base_branch="main" |
| 191 | + log_warning "Could not determine default branch, falling back to 'main'" |
| 192 | + else |
| 193 | + log_notice "Using repository default branch: $base_branch" |
| 194 | + fi |
| 195 | + fi |
| 196 | + set_output "base_branch" "$base_branch" |
| 197 | +
|
| 198 | + - name: Create version bump pull request |
| 199 | + if: steps.extract-version.outputs.has_unreleased == 'true' |
| 200 | + env: |
| 201 | + GH_TOKEN: ${{ secrets.pr_create_token }} |
| 202 | + run: | |
| 203 | + source actions_helpers.sh |
| 204 | +
|
| 205 | + version="${{ steps.extract-version.outputs.next_version }}" |
| 206 | + branch_name="${{ steps.create-branch.outputs.branch_name }}" |
| 207 | + base_branch="${{ steps.determine-base.outputs.base_branch }}" |
| 208 | +
|
| 209 | + pr_body="## Summary |
| 210 | +
|
| 211 | + This PR updates the version to \`${version}\` in preparation for release. |
| 212 | +
|
| 213 | + ### Changes |
| 214 | + - Updated CHANGELOG.md with release version and date |
| 215 | + ${{ inputs.additional_update_script != '' && '- Applied additional version bump updates' || '' }} |
| 216 | +
|
| 217 | + ### Changelog Entries |
| 218 | +
|
| 219 | + ${{ steps.extract-version.outputs.unreleased_changes }}" |
| 220 | +
|
| 221 | + gh pr create \ |
| 222 | + --repo "${{ github.repository }}" \ |
| 223 | + --title "Release v${version}" \ |
| 224 | + --body "$pr_body" \ |
| 225 | + --base "$base_branch" \ |
| 226 | + --head "${{ inputs.fork_owner }}:$branch_name" |
| 227 | +
|
| 228 | + log_notice "Pull request created successfully" |
0 commit comments