Bump Version #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bump Version | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump_type: | |
| description: 'Semver component to increment (ignored when version is set)' | |
| required: true | |
| type: choice | |
| default: patch | |
| options: | |
| - major | |
| - minor | |
| - patch | |
| version: | |
| description: 'Explicit version override (semver, e.g. 5.8.0). Leave blank to auto-increment.' | |
| required: false | |
| type: string | |
| concurrency: | |
| group: bump-version | |
| cancel-in-progress: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| bump: | |
| runs-on: ubuntu-latest | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve target version | |
| id: resolve | |
| env: | |
| INPUT_VERSION: ${{ inputs.version }} | |
| INPUT_BUMP_TYPE: ${{ inputs.bump_type }} | |
| run: | | |
| explicit="$INPUT_VERSION" | |
| if [[ -n "$explicit" ]]; then | |
| if ! [[ "$explicit" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "ERROR: '$explicit' is not valid semver (e.g. 5.8.0)" >&2 | |
| exit 1 | |
| fi | |
| printf 'version=%s\n' "$explicit" >> "$GITHUB_OUTPUT" | |
| echo "Resolved version: $explicit (explicit override)" | |
| else | |
| primary=".claude-plugin/plugin.json" | |
| current=$(grep '"version"' "$primary" | head -1 | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([0-9.]*\)".*/\1/p') | |
| if [[ -z "$current" || "$current" == "null" ]]; then | |
| echo "ERROR: Could not detect current version from $primary" >&2 | |
| exit 1 | |
| fi | |
| if ! [[ "$current" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
| echo "ERROR: Current version '$current' is not valid semver; use an explicit version override." >&2 | |
| exit 1 | |
| fi | |
| IFS='.' read -r major minor patch <<< "$current" | |
| case "$INPUT_BUMP_TYPE" in | |
| major) major=$((major + 1)); minor=0; patch=0 ;; | |
| minor) minor=$((minor + 1)); patch=0 ;; | |
| patch) patch=$((patch + 1)) ;; | |
| *) echo "ERROR: Unknown bump_type '$INPUT_BUMP_TYPE'" >&2; exit 1 ;; | |
| esac | |
| new_version="${major}.${minor}.${patch}" | |
| printf 'version=%s\n' "$new_version" >> "$GITHUB_OUTPUT" | |
| echo "Resolved version: $new_version (auto $INPUT_BUMP_TYPE bump from $current)" | |
| fi | |
| - name: Bump version in all manifests | |
| env: | |
| TARGET_VERSION: ${{ steps.resolve.outputs.version }} | |
| run: bash scripts/bump-version.sh "$TARGET_VERSION" | |
| - name: Verify version consistency | |
| run: bash tests/version-check.sh | |
| - name: Create branch, commit, and push | |
| id: branch | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TARGET_VERSION: ${{ steps.resolve.outputs.version }} | |
| run: | | |
| branch="chore/bump-version-${TARGET_VERSION}" | |
| # Check early for an existing open PR to avoid redundant work | |
| existing=$(gh pr list --head "$branch" --base main --state open --json number --jq '.[0].number // empty' || true) | |
| if [[ -n "$existing" ]]; then | |
| echo "PR #$existing already open for $branch; skipping." | |
| echo "branch=" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -u | |
| if git diff --cached --quiet; then | |
| echo "Nothing to commit – version files already at ${TARGET_VERSION}." | |
| echo "branch=" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| git checkout -b "$branch" | |
| git commit -m "chore: bump version to ${TARGET_VERSION}" | |
| # Use --force-with-lease to handle the case where the remote branch already | |
| # exists from a previous interrupted run (safe because we just diverged from main) | |
| git push --force-with-lease -u origin "$branch" | |
| echo "branch=$branch" >> "$GITHUB_OUTPUT" | |
| - name: Open pull request | |
| if: steps.branch.outputs.branch != '' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TARGET_VERSION: ${{ steps.resolve.outputs.version }} | |
| BRANCH: ${{ steps.branch.outputs.branch }} | |
| run: | | |
| existing=$(gh pr list --head "$BRANCH" --base main --state open --json number --jq '.[0].number // empty' || true) | |
| if [[ -n "$existing" ]]; then | |
| echo "PR already open for $BRANCH (#$existing); skipping creation." | |
| exit 0 | |
| fi | |
| body=$(printf 'Automated version bump to `%s`.\n\nWhen this PR merges, the `Release Tag` workflow will create tag `v%s` and dispatch the `superpowers-version-bump` event to `GoCodeAlone/superpowers-marketplace`.\n' "$TARGET_VERSION" "$TARGET_VERSION") | |
| gh pr create \ | |
| --base main \ | |
| --head "$BRANCH" \ | |
| --title "chore: bump version to ${TARGET_VERSION}" \ | |
| --body "$body" |