File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 push :
55 pull_request :
66
7+ permissions :
8+ contents : read
9+ issues : write
10+ pull-requests : write
11+
712jobs :
813 build :
914 runs-on : ubuntu-24.04
@@ -20,10 +25,49 @@ jobs:
2025 - name : Build
2126 run : npm run build
2227 - name : Check dist freshness
28+ id : dist_freshness
29+ continue-on-error : true
2330 run : |
2431 git diff --exit-code --stat -- dist/index.js \
2532 || (echo "##[error] found changed dist/index.js after build. please run 'npm run build' and commit the updated bundle" \
2633 && exit 1)
34+ - name : Comment on stale dist bundle
35+ if : github.event_name == 'pull_request' && steps.dist_freshness.outcome == 'failure'
36+ env :
37+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
38+ GH_REPO : ${{ github.repository }}
39+ PR_NUMBER : ${{ github.event.pull_request.number }}
40+ run : |
41+ marker='<!-- dist-freshness-check -->'
42+ diff_stat="$(git diff --stat -- dist/index.js)"
43+ body=$(cat <<EOF
44+ $marker
45+ \`dist/index.js\` changed after \`npm run build\`.
46+
47+ Please run \`npm run build\` and commit the regenerated bundle.
48+
49+ \`\`\`text
50+ $diff_stat
51+ \`\`\`
52+ EOF
53+ )
54+
55+ existing_id="$(
56+ gh api "repos/$GH_REPO/issues/$PR_NUMBER/comments" \
57+ --jq '.[] | select(.user.login == "github-actions[bot]" and (.body | contains("<!-- dist-freshness-check -->"))) | .id' \
58+ | tail -n 1
59+ )"
60+
61+ if [ -n "$existing_id" ]; then
62+ gh api --method PATCH "repos/$GH_REPO/issues/comments/$existing_id" -f body="$body" >/dev/null
63+ else
64+ gh api --method POST "repos/$GH_REPO/issues/$PR_NUMBER/comments" -f body="$body" >/dev/null
65+ fi
66+ - name : Fail on stale dist bundle
67+ if : steps.dist_freshness.outcome == 'failure'
68+ run : |
69+ echo "##[error] found changed dist/index.js after build. please run 'npm run build' and commit the updated bundle"
70+ exit 1
2771 - name : Test
2872 run : npm run test
2973 - name : Format
You can’t perform that action at this time.
0 commit comments