.github/workflows/ci-api.yml
222 lines · 5888 bytes
1# CI checks for the API, run on PRs touching api/ and manually via dispatch
2name: 🚦 API CI
3
4on:
5 pull_request:
6 paths:
7 - 'api/**'
8 - 'awesome-privacy.yml'
9 - '.github/workflows/ci-api.yml'
10 workflow_dispatch:
11
12permissions:
13 contents: read
14
15concurrency:
16 group: ${{ github.workflow }}-${{ github.ref }}
17 cancel-in-progress: true
18
19jobs:
20 lint:
21 name: 🛡️ Lint
22 runs-on: ubuntu-latest
23 defaults:
24 run:
25 working-directory: api
26 steps:
27 - uses: actions/checkout@v6
28 with:
29 persist-credentials: false
30 - uses: oven-sh/setup-bun@v2
31 with:
32 bun-version: 1.3.10
33 - run: bun install --frozen-lockfile
34 - run: bun run lint
35
36 format:
37 name: 💅 Format
38 runs-on: ubuntu-latest
39 defaults:
40 run:
41 working-directory: api
42 steps:
43 - uses: actions/checkout@v6
44 with:
45 persist-credentials: false
46 - uses: oven-sh/setup-bun@v2
47 with:
48 bun-version: 1.3.10
49 - run: bun install --frozen-lockfile
50 - run: bun run format:check
51
52 typecheck:
53 name: 🧩 Typecheck
54 runs-on: ubuntu-latest
55 defaults:
56 run:
57 working-directory: api
58 steps:
59 - uses: actions/checkout@v6
60 with:
61 persist-credentials: false
62 - uses: oven-sh/setup-bun@v2
63 with:
64 bun-version: 1.3.10
65 - run: bun install --frozen-lockfile
66 - run: bun run build:data
67 - run: bun run typecheck
68
69 test:
70 name: 🧪 Test
71 runs-on: ubuntu-latest
72 defaults:
73 run:
74 working-directory: api
75 steps:
76 - uses: actions/checkout@v6
77 with:
78 persist-credentials: false
79 - uses: oven-sh/setup-bun@v2
80 with:
81 bun-version: 1.3.10
82 - run: bun install --frozen-lockfile
83 - run: bun run build:data
84 - run: bun run test
85
86 build:
87 name: 🏗️ Build
88 runs-on: ubuntu-latest
89 defaults:
90 run:
91 working-directory: api
92 steps:
93 - uses: actions/checkout@v6
94 with:
95 persist-credentials: false
96 - uses: oven-sh/setup-bun@v2
97 with:
98 bun-version: 1.3.10
99 - run: bun install --frozen-lockfile
100 - run: bun run build
101 - name: Verify bundle output
102 run: test -f dist/index.workers.js || { echo "❌ worker bundle not produced"; exit 1; }
103
104 smoke:
105 name: 💨 Smoke Test
106 runs-on: ubuntu-latest
107 defaults:
108 run:
109 working-directory: api
110 steps:
111 - uses: actions/checkout@v6
112 with:
113 persist-credentials: false
114 - uses: oven-sh/setup-bun@v2
115 with:
116 bun-version: 1.3.10
117 - run: bun install --frozen-lockfile
118 - run: bun run smoke
119
120 docker-smoke:
121 name: 🐳 Docker Smoke
122 runs-on: ubuntu-latest
123 outputs:
124 result: ${{ steps.run.outcome }}
125 defaults:
126 run:
127 working-directory: api
128 steps:
129 - uses: actions/checkout@v6
130 with:
131 persist-credentials: false
132 - name: Build and run container
133 id: run
134 continue-on-error: true
135 run: bash tests/docker-smoke.sh
136 timeout-minutes: 10
137
138 dependency-review:
139 name: 🔒 Dependency Audit
140 runs-on: ubuntu-latest
141 if: github.event_name == 'pull_request'
142 steps:
143 - uses: actions/checkout@v6
144 with:
145 persist-credentials: false
146 - uses: actions/dependency-review-action@v5
147 with:
148 fail-on-severity: moderate
149
150 secret-scan:
151 name: 🔑 Secret Scan
152 runs-on: ubuntu-latest
153 if: github.event_name == 'pull_request'
154 steps:
155 - uses: actions/checkout@v6
156 with:
157 fetch-depth: 0
158 persist-credentials: false
159 - name: Scan PR diff for secrets
160 uses: trufflesecurity/trufflehog@v3.95.5
161 with:
162 base: ${{ github.event.pull_request.base.sha }}
163 head: ${{ github.event.pull_request.head.sha }}
164 extra_args: --only-verified
165
166 # Renders a markdown table of every check at the end
167 summary:
168 name: 📋 Summary
169 runs-on: ubuntu-latest
170 if: always()
171 continue-on-error: true
172 needs:
173 - lint
174 - format
175 - typecheck
176 - test
177 - build
178 - smoke
179 - docker-smoke
180 - dependency-review
181 - secret-scan
182 steps:
183 - name: Render summary
184 env:
185 NEEDS: ${{ toJSON(needs) }}
186 run: |
187 label() {
188 case "$1" in
189 lint) echo "🛡️ Lint" ;;
190 format) echo "💅 Format" ;;
191 typecheck) echo "🧩 Typecheck" ;;
192 test) echo "🧪 Test" ;;
193 build) echo "🏗️ Build" ;;
194 smoke) echo "💨 Smoke Test" ;;
195 docker-smoke) echo "🐳 Docker Smoke" ;;
196 dependency-review) echo "🔒 Dependency Audit" ;;
197 secret-scan) echo "🔑 Secret Scan" ;;
198 *) echo "$1" ;;
199 esac
200 }
201 status() {
202 case "$1" in
203 success) echo "✅ Passed" ;;
204 skipped) echo "⏭️ Skipped" ;;
205 cancelled) echo "🚫 Cancelled" ;;
206 failure) [ "$2" = docker-smoke ] && echo "⚠️ Warnings" || echo "❌ Failed" ;;
207 *) echo "❔ $1" ;;
208 esac
209 }
210 {
211 echo "## API CI Summary"
212 echo ""
213 echo "| Check | Status |"
214 echo "|-------|--------|"
215 } >> "$GITHUB_STEP_SUMMARY"
216 for job in $(echo "$NEEDS" | jq -r 'keys[]'); do
217 result=$(echo "$NEEDS" | jq -r --arg j "$job" '.[$j].result')
218 if [ "$job" = docker-smoke ]; then
219 result=$(echo "$NEEDS" | jq -r '."docker-smoke".outputs.result // "skipped"')
220 fi
221 echo "| $(label "$job") | $(status "$result" "$job") |" >> "$GITHUB_STEP_SUMMARY"
222 done