Skip to content

Commit 935de84

Browse files
kylemclarenclaude
andcommitted
Add preview deployments for pull requests
- Add fly-preview.yml workflow using superfly/fly-pr-review-apps - Create fly.preview.toml with lighter resources (256MB) for previews - Post preview URL as PR comment, updating on each push 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 9da445e commit 935de84

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.github/workflows/fly-preview.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Preview Deployment
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize, closed]
6+
7+
env:
8+
FLY_API_TOKEN: ${{ secrets.FLY_PREVIEW_API_TOKEN }}
9+
FLY_REGION: iad
10+
FLY_ORG: superfly
11+
12+
jobs:
13+
preview:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
url: ${{ steps.deploy.outputs.url }}
17+
concurrency:
18+
group: pr-${{ github.event.number }}
19+
20+
environment:
21+
name: preview
22+
url: ${{ steps.deploy.outputs.url }}
23+
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Deploy preview app
29+
id: deploy
30+
uses: superfly/[email protected]
31+
with:
32+
config: fly.preview.toml
33+
vmsize: shared-cpu-1x
34+
memory: 256
35+
36+
- name: Comment on PR
37+
if: github.event.action != 'closed'
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const url = '${{ steps.deploy.outputs.url }}';
42+
const sha = context.sha.substring(0, 7);
43+
const body = `### Preview Deployment\n\n| Name | URL |\n|------|-----|\n| Preview | ${url} |\n\nCommit: \`${sha}\``;
44+
45+
// Find existing comment
46+
const { data: comments } = await github.rest.issues.listComments({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
issue_number: context.issue.number,
50+
});
51+
const existing = comments.find(c => c.body.includes('### Preview Deployment'));
52+
53+
if (existing) {
54+
await github.rest.issues.updateComment({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
comment_id: existing.id,
58+
body,
59+
});
60+
} else {
61+
await github.rest.issues.createComment({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
issue_number: context.issue.number,
65+
body,
66+
});
67+
}

fly.preview.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Preview deployment configuration
2+
# Lighter resources for ephemeral preview apps
3+
4+
app = 'sprites-docs'
5+
primary_region = 'iad'
6+
7+
[build]
8+
9+
[http_service]
10+
internal_port = 80
11+
force_https = true
12+
auto_stop_machines = 'stop'
13+
auto_start_machines = true
14+
min_machines_running = 0
15+
processes = ['app']
16+
17+
[[vm]]
18+
memory = '256mb'
19+
cpus = 1
20+
memory_mb = 256

0 commit comments

Comments
 (0)