fix: bump the all-updates group across 1 directory with 7 updates #30
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
| #file: noinspection GithubFunctionSignatureValidation | |
| name: Auto Bump | |
| on: | |
| issue_comment: | |
| types: [created] | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: write | |
| id-token: write | |
| pull-requests: write | |
| jobs: | |
| respond: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.issue.pull_request && | |
| github.event.action == 'created' && | |
| (contains(github.event.comment.body, '@github-bot') && contains(github.event.comment.body, 'bump')) | |
| steps: | |
| - name: Check permissions (maintainer-only) | |
| id: perm | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const username = context.payload.comment?.user?.login; | |
| if (!username) { | |
| core.setFailed('No commenter found in payload.'); | |
| return; | |
| } | |
| // Determine the commenter's permission level on this repo | |
| const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ | |
| owner, | |
| repo, | |
| username, | |
| }); | |
| const allowed = ['admin', 'maintain'].includes(data.permission); | |
| core.setOutput('allowed', String(allowed)); | |
| - name: Deny if not maintainer | |
| if: steps.perm.outputs.allowed != 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { owner, repo } = context.repo; | |
| const issue_number = context.issue.number; | |
| const login = context.payload.comment?.user?.login || 'user'; | |
| await github.rest.issues.createComment({ | |
| owner, | |
| repo, | |
| issue_number, | |
| body: `❌ @${login}, only maintainers can bump versions. Please ask a maintainer to run "@github-bot bump".` | |
| }); | |
| - name: React 👍 to triggering comment | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const { eventName, repo, payload } = context; | |
| const { owner, repo: repoName } = repo; | |
| const commentId = payload?.comment?.id; | |
| if (!commentId) { | |
| core.setFailed('No triggering comment found in payload.'); | |
| return; | |
| } | |
| if (eventName === 'issue_comment') { | |
| await github.rest.reactions.createForIssueComment({ | |
| owner, | |
| repo: repoName, | |
| comment_id: commentId, | |
| content: '+1', | |
| }); | |
| } else if (eventName === 'pull_request_review_comment') { | |
| await github.rest.reactions.createForPullRequestReviewComment({ | |
| owner, | |
| repo: repoName, | |
| comment_id: commentId, | |
| content: '+1', | |
| }); | |
| } else { | |
| core.setFailed(`Unsupported event: ${eventName}. Use issue_comment or pull_request_review_comment.`); | |
| } | |
| - name: Get PR branch name | |
| id: pr_branch | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| // Get the PR number from the issue_comment event | |
| const prNumber = context.payload.issue.pull_request | |
| ? context.payload.issue.number | |
| : null; | |
| if (!prNumber) { | |
| core.setFailed('No PR number found in issue payload.'); | |
| return; | |
| } | |
| // Fetch the PR data | |
| const { data: pr } = await github.rest.pulls.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: prNumber, | |
| }); | |
| if (pr.state !== 'open') { | |
| core.setFailed('PR is not open. Aborting.'); | |
| return; | |
| } | |
| core.setOutput('branch', pr.head.ref); | |
| - name: Checkout | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ steps.pr_branch.outputs.branch }} | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Add comment to PR | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `Okay BOSS, ⏳ Bumping version from ${pkg.version}...` | |
| }) | |
| - name: Setup Node & pnpm | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '23' | |
| - name: Install pnpm | |
| if: steps.perm.outputs.allowed == 'true' | |
| run: npm install -g pnpm | |
| - name: Install dependencies | |
| if: steps.perm.outputs.allowed == 'true' | |
| run: pnpm install | |
| - name: Configure Git | |
| if: steps.perm.outputs.allowed == 'true' | |
| run: | | |
| git config --global user.name 'GitHub Action' | |
| git config --global user.email 'action@github.com' | |
| - name: Bump version | |
| if: steps.perm.outputs.allowed == 'true' | |
| run: | | |
| pnpm run bump | |
| - name: Retrieve new version | |
| if: steps.perm.outputs.allowed == 'true' | |
| id: ver | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8')); | |
| core.setOutput('version', String(pkg.version)); | |
| - name: Commit changes | |
| if: steps.perm.outputs.allowed == 'true' | |
| run: | | |
| if [ -z "${{ steps.pr_branch.outputs.branch }}" ]; then | |
| echo "No PR branch found. Aborting push." | |
| exit 1 | |
| fi | |
| git add package.json | |
| git commit -m "chore: bump version to ${{ steps.ver.outputs.version }}" | |
| git push origin HEAD:${{ steps.pr_branch.outputs.branch }} | |
| - name: Add comment to PR | |
| if: steps.perm.outputs.allowed == 'true' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const version = "${{ steps.ver.outputs.version }}" | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `✅ Version bumped to ${version}` | |
| }) |