Repository navigation
Merge pull request #386 from PastaPastaPasta/refactor/post-card-split #321
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to GitHub Pages | |
| # Unified deploy: the Pages artifact always contains the production site | |
| # (built from master, served at the root / yap.pr), the testing site (built | |
| # from the same master commit against the test contracts, served under | |
| # /testing), the staging site (built from the staging branch, served under | |
| # /staging) and the devnet site (the same staging commit built against | |
| # .env.devnet, served under /devnet). A push to either branch rebuilds all four | |
| # so no deploy can wipe another. | |
| on: | |
| # Master deploys are gated on CI: CI runs on every push to master, and this | |
| # workflow starts once that run completes (see the job-level `if`). Staging | |
| # pushes are not gated — they deploy directly, as before. | |
| workflow_run: | |
| workflows: ["CI"] | |
| types: [completed] | |
| branches: [master] | |
| push: | |
| branches: [staging] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| # workflow_run runs only proceed when the CI run they follow passed and was | |
| # a real push to master (a fork PR whose head branch happens to be named | |
| # "master" also matches the branch filter). Staging pushes and manual | |
| # dispatches are unconditional. | |
| if: >- | |
| ${{ github.event_name != 'workflow_run' | |
| || (github.event.workflow_run.conclusion == 'success' | |
| && github.event.workflow_run.event == 'push') }} | |
| outputs: | |
| staging_ok: ${{ steps.staging-build.outcome }} | |
| steps: | |
| # Both checkouts pin an explicit ref, so they resolve identically for | |
| # push, workflow_dispatch and workflow_run events (for workflow_run, | |
| # github.ref points at the default branch, never at the triggering run's | |
| # head — nothing here relies on it). | |
| - name: Checkout master | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: master | |
| path: master | |
| - name: Checkout staging | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: staging | |
| path: staging | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| cache-dependency-path: | | |
| master/package-lock.json | |
| staging/package-lock.json | |
| - name: Build production (master) | |
| working-directory: master | |
| run: | | |
| npm ci | |
| npm run build | |
| env: | |
| # Set BASE_PATH via GitHub repository variables | |
| # Leave unset for root deployments (custom domains), set to /repo-name for subpath deployments | |
| BASE_PATH: ${{ vars.BASE_PATH }} | |
| # continue-on-error so a broken staging build can never block a | |
| # production deploy; the deploy job re-raises the failure when the | |
| # push that triggered this run was to staging itself. | |
| - name: Build staging | |
| id: staging-build | |
| continue-on-error: true | |
| working-directory: staging | |
| run: | | |
| npm ci | |
| npm run build | |
| mv out out-staging | |
| env: | |
| BASE_PATH: /staging | |
| # Same staging checkout and the same commit as the /staging build, rebuilt | |
| # against .env.devnet (BASE_PATH=/devnet, so client-side storage is scoped | |
| # to `devnet:` and stays isolated from / , /staging and /testing). | |
| # continue-on-error because the devnet chain is disposable and resets | |
| # without notice — a broken /devnet must never hold back /staging. | |
| - name: Build devnet (staging) | |
| id: devnet-build | |
| if: steps.staging-build.outcome == 'success' | |
| continue-on-error: true | |
| working-directory: staging | |
| run: | | |
| rm -rf .next | |
| npm run build:devnet | |
| mv out out-devnet | |
| # Same master checkout and the same commit as the production build, so no | |
| # second `npm ci` — but the production output has to be moved aside first | |
| # and .next dropped so the /testing build cannot inherit its artifacts. | |
| # Not continue-on-error: identical code must build both ways. | |
| - name: Build testing (master) | |
| working-directory: master | |
| run: | | |
| mv out out-production | |
| rm -rf .next | |
| npm run build:testing | |
| - name: Combine site artifact | |
| run: | | |
| mkdir -p site | |
| cp -R master/out-production/. site/ | |
| mkdir -p site/testing | |
| cp -R master/out/. site/testing/ | |
| if [ "${{ steps.staging-build.outcome }}" = "success" ] && [ -d staging/out-staging ]; then | |
| mkdir -p site/staging | |
| cp -R staging/out-staging/. site/staging/ | |
| else | |
| echo "::warning::staging build failed — deploying without an updated /staging" | |
| fi | |
| if [ "${{ steps.devnet-build.outcome }}" = "success" ] && [ -d staging/out-devnet ]; then | |
| mkdir -p site/devnet | |
| cp -R staging/out-devnet/. site/devnet/ | |
| else | |
| echo "::warning::devnet build failed or was skipped — deploying without an updated /devnet" | |
| fi | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./site | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| # Redundant with `needs` (a skipped build skips this job too), but kept | |
| # explicit so the CI gate is readable from either job. | |
| if: >- | |
| ${{ github.event_name != 'workflow_run' | |
| || (github.event.workflow_run.conclusion == 'success' | |
| && github.event.workflow_run.event == 'push') }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| - name: Fail if the staging push did not deploy | |
| if: github.ref_name == 'staging' && needs.build.outputs.staging_ok != 'success' | |
| run: | | |
| echo "This run was triggered from staging but the staging build failed." | |
| exit 1 |