Skip to content

Commit f8e4fd7

Browse files
committed
feat: support dependency on other GH actions via preview URL readiness polling (#52)
The core use-case (waiting for a Cloudflare/Vercel deploy before recording) is already solvable with GitHub Actions' native `needs:` keyword — no git-glimpse changes required for the orchestration itself. The one gap was that even after a deploy job finishes, the preview URL may not be immediately reachable (DNS/CDN propagation). This PR closes that gap: - Poll the external preview URL for readiness before running the pipeline, reusing the existing `waitForUrl` helper that was already used for local apps. - Add a `ready-timeout` action input (default: 30 s) so consumers can tune the wait for slower CDNs. - Add `examples/cloudflare-deploy/workflow.yml` — a fully annotated example showing the `needs:` pattern with Cloudflare Pages. The same pattern applies to Vercel, Netlify, etc. by swapping the deploy step. - Unit tests for `waitForUrl` covering immediate success, retry-until- ready, and timeout-exceeded cases. https://claude.ai/code/session_0174r6vAgr36hTnDVwhPv8mu
1 parent e0d24fe commit f8e4fd7

7 files changed

Lines changed: 214 additions & 36 deletions

File tree

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ inputs:
2727
description: 'Max recording duration in seconds'
2828
default: '30'
2929
required: false
30+
ready-timeout:
31+
description: 'How long to wait (in seconds) for the preview URL to become reachable before failing'
32+
default: '30'
33+
required: false
3034

3135
outputs:
3236
recording-url:
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 }}

packages/action/action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ inputs:
2727
description: 'Max recording duration in seconds'
2828
default: '30'
2929
required: false
30+
ready-timeout:
31+
description: 'How long to wait (in seconds) for the preview URL to become reachable before failing'
32+
default: '30'
33+
required: false
3034

3135
outputs:
3236
recording-url:

0 commit comments

Comments
 (0)