-
Notifications
You must be signed in to change notification settings - Fork 0
134 lines (120 loc) · 4.76 KB
/
Copy pathdeploy.yml
File metadata and controls
134 lines (120 loc) · 4.76 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
name: Deploy to Appwrite Sites
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: appwrite-deploy
cancel-in-progress: true
env:
APPWRITE_ENDPOINT: https://fra.cloud.appwrite.io/v1
APPWRITE_PROJECT: 69e62515000e9e781653
jobs:
deploy-static:
name: Deploy static site (rollback target)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
# Static site: ship the repo as-is (minus git/CI/SSR internals).
- name: Package site
run: |
tar --exclude='.git' --exclude='.github' --exclude='ssr' -czf /tmp/code.tar.gz .
ls -la /tmp/code.tar.gz
- name: Create + activate deployment
env:
APPWRITE_API_KEY: ${{ secrets.APPWRITE_API_KEY }}
run: |
set -euo pipefail
resp=$(curl -sS -X POST \
"$APPWRITE_ENDPOINT/sites/portfolio/deployments" \
-H "X-Appwrite-Project: $APPWRITE_PROJECT" \
-H "X-Appwrite-Key: $APPWRITE_API_KEY" \
-F "code=@/tmp/code.tar.gz" \
-F "activate=true")
dep_id=$(echo "$resp" | python3 -c "import json,sys; print(json.load(sys.stdin)['\$id'])")
echo "deployment: $dep_id"
for i in $(seq 1 30); do
sleep 10
status=$(curl -sS \
"$APPWRITE_ENDPOINT/sites/portfolio/deployments/$dep_id" \
-H "X-Appwrite-Project: $APPWRITE_PROJECT" \
-H "X-Appwrite-Key: $APPWRITE_API_KEY" \
| python3 -c "import json,sys; print(json.load(sys.stdin)['status'])")
echo "status: $status"
case "$status" in
ready) echo "static deployed ✔"; exit 0 ;;
failed|canceled) echo "deployment $status" >&2; exit 1 ;;
esac
done
echo "timed out waiting for deployment" >&2
exit 1
deploy-ssr:
name: Deploy SSR wrapper (tapiwa.me)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 22
# The repo root IS the static site; snapshot it into the wrapper.
- name: Assemble site payload
run: |
mkdir -p ssr/site
rsync -a --exclude='.git' --exclude='.github' --exclude='ssr' ./ ssr/site/
- name: Install + test
working-directory: ssr
run: |
npm ci
npm test
- name: Build bundle
working-directory: ssr
run: |
npm run build:bundle
printf '{\n "name": "portfolio-ssr",\n "private": true,\n "scripts": { "start": "node server.js" }\n}\n' > dist-bundle/package.json
# esbuild ESM->CJS can produce a bundle that boots differently from the
# source; always smoke-run the exact artifact we ship.
- name: Smoke-run bundle
working-directory: ssr/dist-bundle
run: |
PORT=4399 node server.js &
SRV=$!
for i in $(seq 1 20); do
sleep 0.5
code=$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4399/ || true)
[ "$code" = "200" ] && break
done
[ "$code" = "200" ] || { echo "bundle smoke failed (got $code)" >&2; kill $SRV; exit 1; }
hdr=$(curl -s -D- -o /dev/null http://127.0.0.1:4399/ | grep -ci 'x-frame-options: DENY' || true)
kill $SRV
[ "$hdr" = "1" ] || { echo "bundle missing security headers" >&2; exit 1; }
echo "bundle smoke ✔ (200 + headers)"
- name: Package bundle
run: tar -C ssr/dist-bundle -czf /tmp/ssr.tar.gz .
- name: Create + activate deployment
env:
APPWRITE_API_KEY: ${{ secrets.APPWRITE_API_KEY }}
run: |
set -euo pipefail
resp=$(curl -sS -X POST \
"$APPWRITE_ENDPOINT/sites/portfolio-ssr-preview/deployments" \
-H "X-Appwrite-Project: $APPWRITE_PROJECT" \
-H "X-Appwrite-Key: $APPWRITE_API_KEY" \
-F "code=@/tmp/ssr.tar.gz" \
-F "activate=true")
dep_id=$(echo "$resp" | python3 -c "import json,sys; print(json.load(sys.stdin)['\$id'])")
echo "deployment: $dep_id"
for i in $(seq 1 30); do
sleep 10
status=$(curl -sS \
"$APPWRITE_ENDPOINT/sites/portfolio-ssr-preview/deployments/$dep_id" \
-H "X-Appwrite-Project: $APPWRITE_PROJECT" \
-H "X-Appwrite-Key: $APPWRITE_API_KEY" \
| python3 -c "import json,sys; print(json.load(sys.stdin)['status'])")
echo "status: $status"
case "$status" in
ready) echo "SSR deployed ✔"; exit 0 ;;
failed|canceled) echo "deployment $status" >&2; exit 1 ;;
esac
done
echo "timed out waiting for deployment" >&2
exit 1