Skip to content

Commit 8fbbdb0

Browse files
authored
Add preview deployments for pull requests (#16)
1 parent 52405b3 commit 8fbbdb0

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

.github/workflows/fly-preview.yml

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

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)