|
| 1 | +# Example: git-glimpse with a Cloudflare Pages deploy preview |
| 2 | +# |
| 3 | +# Pattern: run the Cloudflare deploy first (job: deploy), then run |
| 4 | +# git-glimpse against the resulting preview URL (job: glimpse). |
| 5 | +# GitHub's `needs:` keyword handles the dependency — no extra |
| 6 | +# git-glimpse configuration required. |
| 7 | +# |
| 8 | +# The same pattern works for any deploy-preview service (Vercel, |
| 9 | +# Netlify, Railway, …). Just swap the deploy action and the output |
| 10 | +# name that carries the preview URL. |
| 11 | + |
| 12 | +name: Preview & Demo |
| 13 | + |
| 14 | +on: |
| 15 | + pull_request: |
| 16 | + types: [opened, synchronize] |
| 17 | + issue_comment: |
| 18 | + types: [created] |
| 19 | + |
| 20 | +jobs: |
| 21 | + # ── 1. Deploy to Cloudflare Pages ───────────────────────────────── |
| 22 | + deploy: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + # Skip deployment for comment-triggered runs — the preview |
| 25 | + # already exists; we only need to record a new demo. |
| 26 | + if: github.event_name == 'pull_request' |
| 27 | + outputs: |
| 28 | + preview-url: ${{ steps.cf.outputs.url }} |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + pull-requests: write |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + |
| 35 | + - name: Deploy to Cloudflare Pages |
| 36 | + id: cf |
| 37 | + uses: cloudflare/pages-action@v1 |
| 38 | + with: |
| 39 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 40 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 41 | + projectName: my-project # replace with your project name |
| 42 | + directory: dist # replace with your build output dir |
| 43 | + gitHubToken: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + # ── 2. Record a visual demo ──────────────────────────────────────── |
| 46 | + glimpse: |
| 47 | + # Wait for the deploy job when it ran; the job is skipped on |
| 48 | + # comment events so we use `always()` + a guard to still run. |
| 49 | + needs: [deploy] |
| 50 | + if: >- |
| 51 | + always() && ( |
| 52 | + github.event_name == 'issue_comment' || |
| 53 | + needs.deploy.result == 'success' |
| 54 | + ) && ( |
| 55 | + github.event_name == 'pull_request' || |
| 56 | + (github.event_name == 'issue_comment' && |
| 57 | + github.event.issue.pull_request != null && |
| 58 | + contains(github.event.comment.body, '/glimpse')) |
| 59 | + ) |
| 60 | + runs-on: ubuntu-latest |
| 61 | + permissions: |
| 62 | + contents: write |
| 63 | + pull-requests: write |
| 64 | + issues: write |
| 65 | + steps: |
| 66 | + - uses: actions/checkout@v4 |
| 67 | + with: |
| 68 | + fetch-depth: 0 |
| 69 | + ref: >- |
| 70 | + ${{ |
| 71 | + github.event_name == 'issue_comment' |
| 72 | + && format('refs/pull/{0}/head', github.event.issue.number) |
| 73 | + || '' |
| 74 | + }} |
| 75 | +
|
| 76 | + # Lightweight check — skip expensive installs if not needed |
| 77 | + - uses: DeDuckProject/git-glimpse/check-trigger@v1 |
| 78 | + id: check |
| 79 | + env: |
| 80 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + |
| 82 | + - name: Install FFmpeg |
| 83 | + if: steps.check.outputs.should-run == 'true' |
| 84 | + run: sudo apt-get install -y ffmpeg |
| 85 | + |
| 86 | + - name: Cache Playwright |
| 87 | + if: steps.check.outputs.should-run == 'true' |
| 88 | + uses: actions/cache@v4 |
| 89 | + with: |
| 90 | + path: ~/.cache/ms-playwright |
| 91 | + key: playwright-chromium-${{ hashFiles('**/package-lock.json', '**/pnpm-lock.yaml') }} |
| 92 | + |
| 93 | + - name: Install Playwright Chromium |
| 94 | + if: steps.check.outputs.should-run == 'true' |
| 95 | + run: npx playwright install chromium --with-deps |
| 96 | + |
| 97 | + - uses: DeDuckProject/git-glimpse@v1 |
| 98 | + if: steps.check.outputs.should-run == 'true' |
| 99 | + with: |
| 100 | + # On PR events the deploy job provided a fresh URL. |
| 101 | + # On comment events the deploy job was skipped, so fall back |
| 102 | + # to the environment variable set by Cloudflare on earlier runs, |
| 103 | + # or supply a static staging URL if you have one. |
| 104 | + preview-url: ${{ needs.deploy.outputs.preview-url || vars.STAGING_URL }} |
| 105 | + # Give the preview a moment to fully propagate (default: 30s). |
| 106 | + # Raise this if your CDN takes longer to warm up. |
| 107 | + ready-timeout: '30' |
| 108 | + env: |
| 109 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 110 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments