-
Notifications
You must be signed in to change notification settings - Fork 3
98 lines (82 loc) · 3.03 KB
/
Copy pathpreview.yml
File metadata and controls
98 lines (82 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Disabled - requires FLY_API_TOKEN secret to be configured
# To re-enable: remove 'if: false' from the preview job
name: Preview Deployment
on:
pull_request_target:
types: [opened, synchronize, reopened]
workflow_dispatch:
inputs:
pr_number:
description: 'PR number to deploy'
required: true
concurrency:
group: preview-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
PREVIEW_APP: yaci-explorer-pr-${{ github.event.pull_request.number || github.event.inputs.pr_number }}
jobs:
preview:
if: false # Disabled until FLY_API_TOKEN is configured
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Create or update preview app
run: |
if ! flyctl apps list | grep -q "$PREVIEW_APP"; then
echo "Creating preview app: $PREVIEW_APP"
flyctl apps create "$PREVIEW_APP" --org personal
fi
cat > fly.preview.toml << EOF
app = "$PREVIEW_APP"
primary_region = "sjc"
[http_service]
internal_port = 80
force_https = true
auto_stop_machines = "stop"
auto_start_machines = true
min_machines_running = 0
processes = ["app"]
[[vm]]
memory = "256mb"
cpu_kind = "shared"
cpus = 1
EOF
flyctl deploy --config fly.preview.toml --remote-only --no-cache
- name: Post preview URL
uses: actions/github-script@v7
with:
script: |
const previewUrl = `https://${process.env.PREVIEW_APP}.fly.dev`;
const sha = context.payload.pull_request.head.sha.slice(0, 7);
const timestamp = new Date().toISOString().replace('T', ' ').slice(0, 19) + ' UTC';
const body = `**Preview deployment ready!**\n\n${previewUrl}\n\nLast deployed: \`${sha}\` at ${timestamp}`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('Preview deployment')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body
});
}