|
| 1 | +name: Dependabot Commit Dist - CodeQL Development MCP Server |
| 2 | + |
| 3 | +## Auto-rebuild and commit 'server/dist/**' on Dependabot PRs. |
| 4 | +## |
| 5 | +## Two-workflow handoff: 'build-server.yml' rebuilds with no write token |
| 6 | +## (npm ci --ignore-scripts), uploads the 'server-dist' artifact. This |
| 7 | +## workflow runs in the trusted default-branch context, downloads the |
| 8 | +## artifact, and pushes it to the PR branch. No PR-supplied code executes |
| 9 | +## here. |
| 10 | + |
| 11 | +on: |
| 12 | + workflow_run: |
| 13 | + workflows: ['Build Server - CodeQL Development MCP Server'] |
| 14 | + types: [completed] |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | +jobs: |
| 20 | + commit-dist: |
| 21 | + name: Commit Rebuilt server/dist to Dependabot PR Branch |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + if: >- |
| 25 | + github.event.workflow_run.event == 'pull_request' && |
| 26 | + github.event.workflow_run.conclusion == 'success' && |
| 27 | + github.event.workflow_run.actor.login == 'dependabot[bot]' |
| 28 | +
|
| 29 | + permissions: |
| 30 | + contents: write |
| 31 | + actions: read |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Commit Dist - Validate workflow_run head |
| 35 | + id: pr |
| 36 | + env: |
| 37 | + HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} |
| 38 | + HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }} |
| 39 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 40 | + REPO: ${{ github.repository }} |
| 41 | + run: | |
| 42 | + set -euo pipefail |
| 43 | + if [ "${HEAD_REPO}" != "${REPO}" ]; then |
| 44 | + echo "::error::Refusing to push: head repo '${HEAD_REPO}' != '${REPO}'" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + if [ -z "${HEAD_BRANCH}" ] || [ -z "${HEAD_SHA}" ]; then |
| 48 | + echo "::error::Missing head_branch or head_sha" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | + echo "branch=${HEAD_BRANCH}" >> "${GITHUB_OUTPUT}" |
| 52 | + echo "sha=${HEAD_SHA}" >> "${GITHUB_OUTPUT}" |
| 53 | +
|
| 54 | + - name: Commit Dist - Checkout PR branch |
| 55 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 |
| 56 | + with: |
| 57 | + ref: ${{ steps.pr.outputs.branch }} |
| 58 | + persist-credentials: true |
| 59 | + fetch-depth: 1 |
| 60 | + |
| 61 | + ## Abort if the branch advanced since the build started; the next |
| 62 | + ## build-server run will re-trigger this workflow. |
| 63 | + - name: Commit Dist - Verify checkout matches build SHA |
| 64 | + id: verify |
| 65 | + env: |
| 66 | + EXPECTED_SHA: ${{ steps.pr.outputs.sha }} |
| 67 | + run: | |
| 68 | + set -euo pipefail |
| 69 | + ACTUAL_SHA="$(git rev-parse HEAD)" |
| 70 | + if [ "${ACTUAL_SHA}" != "${EXPECTED_SHA}" ]; then |
| 71 | + echo "::warning::Branch advanced from ${EXPECTED_SHA} to ${ACTUAL_SHA}; skipping." |
| 72 | + echo "skip=true" >> "${GITHUB_OUTPUT}" |
| 73 | + else |
| 74 | + echo "skip=false" >> "${GITHUB_OUTPUT}" |
| 75 | + fi |
| 76 | +
|
| 77 | + - name: Commit Dist - Download server-dist artifact |
| 78 | + if: steps.verify.outputs.skip == 'false' |
| 79 | + uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0 |
| 80 | + with: |
| 81 | + name: server-dist |
| 82 | + path: artifact/ |
| 83 | + run-id: ${{ github.event.workflow_run.id }} |
| 84 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + |
| 86 | + ## Defence in depth: confirm the artifact contains exactly the two |
| 87 | + ## expected bundle files before copying into the repo. |
| 88 | + - name: Commit Dist - Verify artifact contents |
| 89 | + if: steps.verify.outputs.skip == 'false' |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + for f in codeql-development-mcp-server.js codeql-development-mcp-server.js.map; do |
| 93 | + if [ ! -f "artifact/${f}" ]; then |
| 94 | + echo "::error::Missing expected artifact file: ${f}" |
| 95 | + exit 1 |
| 96 | + fi |
| 97 | + done |
| 98 | + UNEXPECTED="$(find artifact -type f \ |
| 99 | + ! -name 'codeql-development-mcp-server.js' \ |
| 100 | + ! -name 'codeql-development-mcp-server.js.map' \ |
| 101 | + -print)" |
| 102 | + if [ -n "${UNEXPECTED}" ]; then |
| 103 | + echo "::error::Unexpected files in artifact:" |
| 104 | + echo "${UNEXPECTED}" |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | +
|
| 108 | + - name: Commit Dist - Commit and push (if changed) |
| 109 | + if: steps.verify.outputs.skip == 'false' |
| 110 | + env: |
| 111 | + BRANCH: ${{ steps.pr.outputs.branch }} |
| 112 | + run: | |
| 113 | + set -euo pipefail |
| 114 | + cp artifact/codeql-development-mcp-server.js server/dist/ |
| 115 | + cp artifact/codeql-development-mcp-server.js.map server/dist/ |
| 116 | +
|
| 117 | + git config user.name 'dependabot[bot]' |
| 118 | + git config user.email '49699333+dependabot[bot]@users.noreply.github.com' |
| 119 | + git add server/dist/codeql-development-mcp-server.js \ |
| 120 | + server/dist/codeql-development-mcp-server.js.map |
| 121 | +
|
| 122 | + if git diff --cached --quiet; then |
| 123 | + echo "::notice::server/dist already up to date." |
| 124 | + exit 0 |
| 125 | + fi |
| 126 | +
|
| 127 | + git commit -m "chore(deps): rebuild server/dist after dependency update |
| 128 | +
|
| 129 | + [dependabot skip]" |
| 130 | + git push origin "HEAD:${BRANCH}" |
0 commit comments