|
| 1 | +name: Rebuild dist |
| 2 | + |
| 3 | +# Why this exists: |
| 4 | +# pancake-frontend imports `@pancakeswap/storybook/widgets` from a git ref, |
| 5 | +# resolving to the committed `dist/` (no `prepare` script — that path was |
| 6 | +# OOMing on Vercel). That means whenever someone edits `src/` and forgets to |
| 7 | +# run `pnpm build:lib` before pushing, downstream consumers see stale code. |
| 8 | +# This workflow rebuilds dist on push and commits it back so devs only have |
| 9 | +# to touch src/. |
| 10 | +# |
| 11 | +# Plan B (later, before launch): publish as a real npm package via GitHub |
| 12 | +# Packages and pin a version in pancake-frontend; this workflow becomes a |
| 13 | +# release/publish job instead of a commit-back job. |
| 14 | + |
| 15 | +on: |
| 16 | + push: |
| 17 | + branches-ignore: |
| 18 | + - 'gh-pages' |
| 19 | + paths: |
| 20 | + - 'src/**' |
| 21 | + - 'package.json' |
| 22 | + - 'pnpm-lock.yaml' |
| 23 | + - 'vite.lib.config.ts' |
| 24 | + - 'tsconfig*.json' |
| 25 | + |
| 26 | +# Default GITHUB_TOKEN can write to the repo with `contents: write`. No PAT |
| 27 | +# required. |
| 28 | +permissions: |
| 29 | + contents: write |
| 30 | + |
| 31 | +# Avoid stacking redundant rebuilds when a branch gets multiple pushes in |
| 32 | +# quick succession — the most recent push wins. |
| 33 | +concurrency: |
| 34 | + group: rebuild-dist-${{ github.ref }} |
| 35 | + cancel-in-progress: true |
| 36 | + |
| 37 | +jobs: |
| 38 | + rebuild: |
| 39 | + runs-on: ubuntu-latest |
| 40 | + |
| 41 | + # Belt-and-braces guard against the bot triggering itself. The |
| 42 | + # `[skip ci]` token in the commit message is the primary mechanism |
| 43 | + # (GitHub honors it), this `if` catches any path where it gets |
| 44 | + # stripped (rebases, force-pushes, etc.). |
| 45 | + if: github.actor != 'github-actions[bot]' |
| 46 | + |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + # Need full ref so we can push back without "shallow update not |
| 51 | + # allowed". |
| 52 | + fetch-depth: 0 |
| 53 | + # Use the default token; explicit so the push step inherits it. |
| 54 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - uses: pnpm/action-setup@v4 |
| 57 | + with: |
| 58 | + # pnpm-lock.yaml is v9 → pin pnpm major to match. action-setup@v4 |
| 59 | + # requires either this `version` key or a `packageManager` field |
| 60 | + # in package.json; we don't have the latter. |
| 61 | + version: 9 |
| 62 | + |
| 63 | + - uses: actions/setup-node@v4 |
| 64 | + with: |
| 65 | + node-version: 20 |
| 66 | + cache: pnpm |
| 67 | + |
| 68 | + - run: pnpm install --frozen-lockfile |
| 69 | + |
| 70 | + - name: Build library bundle |
| 71 | + run: pnpm build:lib |
| 72 | + |
| 73 | + - name: Commit dist if changed |
| 74 | + run: | |
| 75 | + if [[ -z "$(git status --porcelain dist/)" ]]; then |
| 76 | + echo "dist/ unchanged — nothing to commit" |
| 77 | + exit 0 |
| 78 | + fi |
| 79 | + git config user.name 'github-actions[bot]' |
| 80 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 81 | + git add dist/ |
| 82 | + git commit -m "ci: rebuild dist [skip ci]" |
| 83 | + git push origin HEAD:${GITHUB_REF#refs/heads/} |
0 commit comments