bump-dependency #331
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 Deps | |
| on: | |
| repository_dispatch: | |
| types: [ bump-dependency ] | |
| jobs: | |
| sanitize-payload: | |
| name: Sanitize Payload | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| label: ${{ steps.sanitize.outputs.label }} | |
| safe_module: ${{ steps.sanitize.outputs.safe_module }} | |
| safe_head: ${{ steps.sanitize.outputs.safe_head }} | |
| safe_assignee: ${{ steps.sanitize.outputs.safe_assignee }} | |
| safe_email: ${{ steps.sanitize.outputs.safe_email }} | |
| safe_branch: ${{ steps.sanitize.outputs.safe_branch }} | |
| safe_short: ${{ steps.sanitize.outputs.safe_short }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Validate & Sanitize Payload (script) | |
| id: sanitize | |
| env: | |
| RAW_DEP: ${{ github.event.client_payload.dependency }} | |
| RAW_SHA: ${{ github.event.client_payload.head_commit_sha }} | |
| RAW_USER: ${{ github.event.client_payload.assignee }} | |
| RAW_MAIL: ${{ github.event.client_payload.assignee_email }} | |
| run: bash .github/workflows/scripts/sanitize_payload.sh | |
| stale-bump-prs: | |
| name: Retrieving Stale Bump PRs | |
| needs: sanitize-payload | |
| outputs: | |
| stale-pulls: ${{ steps.get-stale-prs.outputs.open-pulls }} | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Get Open Bump PRs | |
| id: get-stale-prs | |
| uses: actions/github-script@v7 | |
| env: | |
| LABEL: ${{ needs.sanitize-payload.outputs.label }} | |
| with: | |
| debug: true | |
| github-token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
| script: | | |
| try { | |
| const { LABEL } = process.env; | |
| const { owner, repo } = context.repo; | |
| const res = await github.rest.pulls.list({ | |
| owner, | |
| repo, | |
| state: 'open', | |
| sort: 'created', | |
| direction: 'desc', | |
| }); | |
| const { data } = res; | |
| const reduced = data.reduce((acc, p) => { | |
| if (p.labels.length < 1) return acc; | |
| let keepAlive = false; | |
| let shouldPush = false; | |
| for (const label of p.labels) { | |
| if (label.name === LABEL) { | |
| shouldPush = true; | |
| } | |
| if (label.name === "keep-alive") { | |
| keepAlive = true; | |
| } | |
| } | |
| if (shouldPush) { | |
| acc.push({ | |
| number: p.number, | |
| keepAlive, | |
| headRef: p.head.ref, | |
| }); | |
| } | |
| return acc; | |
| }, []); | |
| console.log(reduced); | |
| if (reduced.length > 0) core.setOutput("open-pulls", JSON.stringify(reduced)); | |
| process.exit(0); | |
| } catch(err) { | |
| console.log("Error:", err); | |
| process.exit(1); | |
| } | |
| open-bump-pr: | |
| needs: [sanitize-payload, stale-bump-prs] | |
| name: Open Bump PR | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| latest-pr: ${{ steps.latest-pr.outputs.pr_url }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.REPO_ACCESS_TOKEN || secrets.GITHUB_TOKEN }} | |
| - name: Set up Go 1.x | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version-file: go.mod | |
| - name: Bump dependency (safe) | |
| env: | |
| SAFE_MODULE: ${{ needs.sanitize-payload.outputs.safe_module }} | |
| SAFE_HEAD: ${{ needs.sanitize-payload.outputs.safe_head }} | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| echo "Installing ${SAFE_MODULE}@${SAFE_HEAD}" | |
| GOOS=linux go get "${SAFE_MODULE}@${SAFE_HEAD}" | |
| - name: Get Assignee and Reviewer (safe) | |
| id: get_reviewer | |
| env: | |
| ASSIGNEE: ${{ needs.sanitize-payload.outputs.safe_assignee }} | |
| run: | | |
| set -euo pipefail | |
| if [ "${ASSIGNEE}" = "zachmu" ]; then | |
| echo "reviewer=Hydrocharged" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "reviewer=zachmu" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Create and Push new branch (safe) | |
| env: | |
| GIT_USER: ${{ needs.sanitize-payload.outputs.safe_assignee }} | |
| GIT_MAIL: ${{ needs.sanitize-payload.outputs.safe_email }} | |
| BRANCH: ${{ needs.sanitize-payload.outputs.safe_branch }} | |
| COMMIT_BY: ${{ needs.sanitize-payload.outputs.safe_assignee }} | |
| run: | | |
| set -euo pipefail | |
| IFS=$'\n\t' | |
| git config --global user.name "${GIT_USER}" | |
| git config --global user.email "${GIT_MAIL}" | |
| git checkout -b "${BRANCH}" | |
| git add . | |
| # Commit message uses sanitized assignee only | |
| git commit -m "[ga-bump-dep] Bump dependency in GMS by ${COMMIT_BY}" | |
| git push origin "${BRANCH}" | |
| - name: pull-request | |
| uses: repo-sync/pull-request@v2 | |
| id: latest-pr | |
| with: | |
| source_branch: ${{ needs.sanitize-payload.outputs.safe_branch }} | |
| destination_branch: "main" | |
| github_token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
| pr_title: "[auto-bump] [no-release-notes] dependency by ${{ needs.sanitize-payload.outputs.safe_assignee }}" | |
| pr_template: ".github/markdown-templates/dep-bump.md" | |
| pr_reviewer: ${{ steps.get_reviewer.outputs.reviewer }} | |
| pr_assignee: ${{ needs.sanitize-payload.outputs.safe_assignee }} | |
| pr_label: ${{ needs.sanitize-payload.outputs.label }} | |
| comment-on-stale-prs: | |
| needs: [open-bump-pr, stale-bump-prs] | |
| if: ${{ needs.stale-bump-prs.outputs.stale-pulls != '' }} | |
| runs-on: ubuntu-22.04 | |
| strategy: | |
| matrix: | |
| pull: ${{ fromJson(needs.stale-bump-prs.outputs.stale-pulls) }} | |
| steps: | |
| - name: Comment/Close Stale PRs | |
| id: get-stale-prs | |
| uses: actions/github-script@v7 | |
| env: | |
| PULL: ${{ toJson(matrix.pull) }} | |
| SUPERSEDED_BY: ${{ needs.open-bump-pr.outputs.latest-pr }} | |
| with: | |
| debug: true | |
| github-token: ${{ secrets.REPO_ACCESS_TOKEN }} | |
| script: | | |
| try { | |
| const { owner, repo } = context.repo; | |
| const { PULL, SUPERSEDED_BY } = process.env; | |
| const pull = JSON.parse(PULL); | |
| if (pull.keepAlive) process.exit(0); | |
| const checkSuiteRes = await github.rest.checks.listSuitesForRef({ | |
| owner, | |
| repo, | |
| ref: pull.headRef, | |
| }); | |
| if (checkSuiteRes.data) { | |
| for (const suite of checkSuiteRes.data.check_suites) { | |
| console.log("suite id:", suite.id); | |
| console.log("suite app slug:", suite.app.slug); | |
| console.log("suite status:", suite.status); | |
| console.log("suite conclusion:", suite.conclusion); | |
| if (suite.app.slug === "github-actions") { | |
| if (suite.status !== "completed" || suite.conclusion !== "success") { | |
| console.log(`Leaving pr open due to status:${suite.status} conclusion${suite.conclusion}`); | |
| process.exit(0); | |
| } | |
| } | |
| } | |
| console.log(`Closing open pr ${pull.number}`); | |
| await github.rest.issues.createComment({ | |
| issue_number: pull.number, | |
| owner, | |
| repo, | |
| body: `This PR has been superseded by ${SUPERSEDED_BY}` | |
| }); | |
| await github.rest.pulls.update({ | |
| owner, | |
| repo, | |
| pull_number: pull.number, | |
| state: 'closed', | |
| }); | |
| } | |
| process.exit(0); | |
| } catch(err) { | |
| console.log("Error:", err); | |
| process.exit(1); | |
| } |