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