-
Notifications
You must be signed in to change notification settings - Fork 225
100 lines (84 loc) · 3.06 KB
/
Copy pathpreview-deploy.yml
File metadata and controls
100 lines (84 loc) · 3.06 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
99
100
name: Preview Deploy
on:
pull_request:
types: [opened, synchronize, reopened, closed]
concurrency:
group: preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
env:
FLY_APP: docs-preview-pr-${{ github.event.pull_request.number }}
FLY_ORG: ${{ vars.FLY_ORG || 'personal' }}
jobs:
build-and-deploy:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v6
with:
# Full history (and all branches) is needed to diff against the merge
# base with the PR's base branch, which isn't always main
fetch-depth: 0
- name: Generate change manifest
env:
PREVIEW_URL: https://${{ env.FLY_APP }}.fly.dev
# Diff against the branch the PR targets, so a stacked PR lists only
# its own changes instead of the whole stack
PREVIEW_BASE_REF: origin/${{ github.event.pull_request.base.ref }}
# The PR head commit (GITHUB_SHA is the synthetic merge ref on PRs)
GITHUB_SHA: ${{ github.event.pull_request.head.sha }}
run: node scripts/generate-preview-changes.mjs
- name: Set up Fly CLI
uses: superfly/flyctl-actions/setup-flyctl@fc53c09e1bc3be6f54706524e3b82c4f462f77be # v1.5
- name: Create Fly app (if not exists)
run: |
flyctl apps create "${{ env.FLY_APP }}" --org "${{ env.FLY_ORG }}" 2>/dev/null || true
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Generate fly.toml
run: |
cat > fly.toml <<EOF
app = "${{ env.FLY_APP }}"
primary_region = "ams"
[build]
dockerfile = "Dockerfile.preview"
[http_service]
internal_port = 8210
force_https = true
auto_stop_machines = "stop"
min_machines_running = 0
[[vm]]
size = "shared-cpu-1x"
memory = "256mb"
EOF
- name: Deploy to Fly.io
run: |
flyctl deploy \
--ha=false \
--remote-only \
--build-arg VAADIN_PRO_KEY="${{ secrets.VAADIN_PRO_KEY }}"
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
- name: Comment preview URL on PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: preview-deploy
path: preview-comment.md
cleanup:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Set up Fly CLI
uses: superfly/flyctl-actions/setup-flyctl@fc53c09e1bc3be6f54706524e3b82c4f462f77be # v1.5
- name: Destroy Fly app
run: |
if flyctl apps list --json | jq -e --arg name "${{ env.FLY_APP }}" '.[] | select(.Name == $name)' > /dev/null; then
flyctl apps destroy "${{ env.FLY_APP }}" --yes
else
echo "App ${{ env.FLY_APP }} does not exist, nothing to destroy"
fi
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}