Skip to content

Lock file maintenance #96

Lock file maintenance

Lock file maintenance #96

Workflow file for this run

# `dist/index.js` is what the runner actually executes, so it must always be
# the build output of the current source.
#
# Human PRs are expected to commit a rebuilt dist/ - the check-dist job fails
# when source and dist drift. Renovate PRs are exempt: Renovate only bumps
# manifests and can't rebuild dist, so the sync-dist job rebuilds dist on
# every push to main and commits the result if it changed. That keeps main
# releasable after auto-merged dependency updates.
name: Check dist
on:
push:
branches:
- main
pull_request:
permissions:
contents: read
jobs:
check-dist:
if: github.event_name == 'pull_request' && !startsWith(github.head_ref, 'renovate/')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
- run: pnpm install --frozen-lockfile
- run: pnpm build
- name: Compare expected and actual dist
run: |
if [ "$(git diff --ignore-space-at-eol --text dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. Run 'pnpm build' and commit dist/."
git diff --stat --ignore-space-at-eol --text dist/
exit 1
fi
sync-dist:
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: sync-dist-main
steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6.0.9
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6
with:
node-version: 24
cache: pnpm
cache-dependency-path: pnpm-lock.yaml
# Always rebuild against the fetched tip of main, not the trigger
# commit: main may have moved since this run was triggered. If the
# push still loses a race, the rebuild retries once against the new
# tip - and the push that moved main has its own sync-dist run queued
# behind this one anyway.
- name: Rebuild dist against the tip of main and commit if drifted
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
for attempt in 1 2; do
git fetch origin main
git reset --hard FETCH_HEAD
pnpm install --frozen-lockfile
pnpm build
if [ -z "$(git status --porcelain dist/)" ]; then
echo "dist matches the build output - nothing to sync"
exit 0
fi
git add dist/
git commit -m "Rebuilt dist after dependency updates"
if git push origin HEAD:main; then
exit 0
fi
echo "main moved during the rebuild (attempt $attempt), retrying against the new tip"
done
echo "Failed to push the rebuilt dist after 2 attempts"
exit 1