Repository navigation
144 lines (139 loc) · 6.11 KB
/
Copy pathci.yml
File metadata and controls
144 lines (139 loc) · 6.11 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
135
136
137
138
139
140
141
142
143
144
name: Foundation checks
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
verify:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: '24.13.0'
cache: npm
- uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
cache: true
cache-dependency-path: app/api/packages.lock.json
- run: npm ci
- run: dotnet restore app/api --locked-mode
- run: dotnet tool restore
- run: npx playwright install --with-deps chromium
- run: npm run lint
- run: npm run typecheck
- run: dotnet format app/api --verify-no-changes --no-restore
- run: npm test
- name: Upload Playwright artifacts on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: playwright-failure-${{ github.run_id }}
path: |
playwright-report/
test-results/
if-no-files-found: ignore
retention-days: 7
# Render deploys the API from this Dockerfile only after a merge (render.yaml). Build and boot
# the same image here, so a broken image or Production startup fails the PR instead.
api-image:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v5
- name: Build the image Render deploys
run: docker build --tag specthread-api:ci .
- name: Start it as Render runs it
# Production, port 8080, and no database or issuer: /health must not need them.
run: docker run --detach --name api --publish 8080:8080 specthread-api:ci
- name: Wait for /health
run: |
for attempt in $(seq 1 30); do
if [ "$(docker inspect --format '{{.State.Running}}' api)" != "true" ]; then
echo "::error::The API container exited during startup."; exit 1
fi
body=$(curl --silent --fail --max-time 2 http://127.0.0.1:8080/health) && break
sleep 2
done
test "$body" = '{"status":"ok"}' || { echo "::error::/health answered '$body', expected {\"status\":\"ok\"}."; exit 1; }
- name: Check Production behavior
run: |
me=$(curl --silent --output /dev/null --write-out '%{http_code}' http://127.0.0.1:8080/me)
test "$me" = 401 || { echo "::error::Anonymous /me answered $me, expected 401."; exit 1; }
openapi=$(curl --silent --output /dev/null --write-out '%{http_code}' http://127.0.0.1:8080/openapi/v1.json)
test "$openapi" != 200 || { echo "::error::Production serves the OpenAPI document."; exit 1; }
- name: Check the image runs unprivileged and trusts the Supabase CA
run: |
test "$(docker exec api id -u)" != 0 || { echo "::error::The API runs as root."; exit 1; }
docker exec api test -e /etc/ssl/certs/supabase-root-2021.pem ||
{ echo "::error::The Supabase root CA is not in the system trust store (ADR-011)."; exit 1; }
- name: Show API logs
if: failure()
run: docker logs api || true
- name: Remove the container
if: always()
run: docker rm --force api || true
# After a merge, apply pending EF Core migrations to Supabase, then deploy that same commit
# to Render, so the new API never starts before its schema exists (ADR-044). Render's own
# auto-deploy is off (render.yaml). The `api-deploy` environment holds the two secrets.
deploy-api:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [verify, api-image]
runs-on: ubuntu-latest
timeout-minutes: 15
environment: api-deploy
# One deploy at a time. A newer merge waits for the running one instead of cancelling it
# halfway through a migration.
concurrency:
group: deploy-api
cancel-in-progress: false
steps:
- uses: actions/checkout@v5
- uses: actions/setup-dotnet@v5
with:
global-json-file: global.json
cache: true
cache-dependency-path: app/api/packages.lock.json
- run: dotnet restore app/api --locked-mode
- run: dotnet tool restore
- name: Build the migration bundle
# Building constructs the DbContext, which needs some connection string. This one is
# never contacted; the bundle reads the real one when it runs.
env:
ConnectionStrings__Database: Host=bundle-build.invalid;Database=unused
run: dotnet ef migrations bundle --project app/api --configuration Release --output efbundle --force
- name: Trust the Supabase root CA
# The connection string uses SSL Mode=VerifyFull, as on Render (ADR-011).
run: |
sudo cp app/api/certs/prod-ca-2021.crt /usr/local/share/ca-certificates/supabase-root-2021.crt
sudo update-ca-certificates
- name: Apply pending migrations
env:
ConnectionStrings__Database: ${{ secrets.DATABASE_MIGRATION_CONNECTION_STRING }}
run: |
test -n "$ConnectionStrings__Database" ||
{ echo "::error::Set the DATABASE_MIGRATION_CONNECTION_STRING secret in the api-deploy environment."; exit 1; }
./efbundle
- name: Deploy this commit to Render
env:
RENDER_DEPLOY_HOOK_URL: ${{ secrets.RENDER_DEPLOY_HOOK_URL }}
run: |
test -n "$RENDER_DEPLOY_HOOK_URL" ||
{ echo "::error::Set the RENDER_DEPLOY_HOOK_URL secret in the api-deploy environment."; exit 1; }
curl --silent --show-error --fail --request POST --output /dev/null "${RENDER_DEPLOY_HOOK_URL}&ref=${GITHUB_SHA}"
- name: Wait for Render API health
run: |
for attempt in $(seq 1 30); do
body=$(curl --silent --fail --max-time 2 https://specthread-api.onrender.com/health) || body=""
if [ "$body" = '{"status":"ok"}' ]; then
echo "Render API health check passed."
exit 0
fi
if [ "$attempt" -lt 30 ]; then sleep 8; fi
done
echo "::error::Render API did not become healthy within five minutes."
exit 1