|
| 1 | +name: rebuild-dist |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +on: |
| 12 | + pull_request: |
| 13 | + |
| 14 | +jobs: |
| 15 | + # Rebuilds the bundled dist/ on Dependabot PRs and pushes it back to the PR |
| 16 | + # branch, so a dependency bump and its matching dist/ land in a single PR and |
| 17 | + # the validate workflow stays green. |
| 18 | + # |
| 19 | + # Dependabot runs get a read-only GITHUB_TOKEN, and commits pushed with it do |
| 20 | + # not re-trigger checks. Pushing the dist commit therefore uses GH_PAT, which |
| 21 | + # can re-run workflows. Note: Dependabot runs only expose Dependabot secrets, |
| 22 | + # so GH_PAT must exist as a Dependabot secret (org or repo) with contents:write |
| 23 | + # on this repo. Until it does this job is a no-op. |
| 24 | + rebuild-dist: |
| 25 | + if: github.actor == 'dependabot[bot]' |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - name: Check token |
| 29 | + id: token |
| 30 | + env: |
| 31 | + GH_PAT: ${{ secrets.GH_PAT }} |
| 32 | + run: | |
| 33 | + if [ -n "$GH_PAT" ]; then |
| 34 | + echo "available=true" >> "$GITHUB_OUTPUT" |
| 35 | + else |
| 36 | + echo "available=false" >> "$GITHUB_OUTPUT" |
| 37 | + echo "::notice::GH_PAT Dependabot secret is not set; skipping automatic dist rebuild." |
| 38 | + fi |
| 39 | + - name: Checkout |
| 40 | + if: steps.token.outputs.available == 'true' |
| 41 | + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 |
| 42 | + with: |
| 43 | + ref: ${{ github.head_ref }} |
| 44 | + token: ${{ secrets.GH_PAT }} |
| 45 | + - name: Setup Node.js |
| 46 | + if: steps.token.outputs.available == 'true' |
| 47 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 48 | + with: |
| 49 | + node-version-file: '.node-version' |
| 50 | + cache: npm |
| 51 | + - name: Install dependencies |
| 52 | + if: steps.token.outputs.available == 'true' |
| 53 | + run: npm ci --ignore-scripts |
| 54 | + - name: Rebuild dist |
| 55 | + if: steps.token.outputs.available == 'true' |
| 56 | + run: npm run build |
| 57 | + - name: Commit and push dist if changed |
| 58 | + if: steps.token.outputs.available == 'true' |
| 59 | + env: |
| 60 | + HEAD_REF: ${{ github.head_ref }} |
| 61 | + run: | |
| 62 | + if [ -z "$(git status --porcelain -- dist)" ]; then |
| 63 | + echo "dist is already up to date." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + git config user.name "github-actions[bot]" |
| 67 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 68 | + git add dist |
| 69 | + git commit -m "build: rebuild dist" |
| 70 | + git push origin "HEAD:${HEAD_REF}" |
0 commit comments