Repository navigation
264 lines (229 loc) · 9.53 KB
/
Copy pathci.yml
File metadata and controls
264 lines (229 loc) · 9.53 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
# Only one run per branch/PR; a new push cancels the previous run.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
# Every action is pinned to the commit SHA of the release tag named in the
# trailing comment; `.github/dependabot.yml` keeps the pins current. Never
# replace a pin with a floating `@vN` tag: this workflow holds a repository
# token, and a moved tag would silently change what runs.
#
# The required status checks on `main` are "Commit messages",
# "Verify (Node 20.x)" and "Verify (Node 22.x)". The `windows` and `docker`
# jobs below are additive and must never take over those names.
jobs:
commit-messages:
name: Commit messages
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Check out the full history
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
# Every job runs `pnpm install --frozen-lockfile` with dependency build
# scripts allowed, so the checkout must not leave the repository token
# in `.git/config` for those scripts to read.
persist-credentials: false
- name: Set up pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6
with:
# Pinned to the version in `packageManager`; `allowBuilds` in
# pnpm-workspace.yaml is a pnpm 10+ feature. Bump both together.
version: 12.25.1
- name: Set up Node.js
uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 22.x
cache: pnpm
- name: Install the dependencies
run: pnpm install --frozen-lockfile
# The range is the commits the event actually introduced: the PR's
# base..head, or everything a push added. Merge commits are ignored
# through config-conventional's default ignores.
- name: Lint the commit messages
env:
EVENT_NAME: ${{ github.event_name }}
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PUSH_BEFORE_SHA: ${{ github.event.before }}
PUSH_HEAD_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "$EVENT_NAME" = "pull_request" ]; then
from="$PR_BASE_SHA"
to="$PR_HEAD_SHA"
elif [ -n "${PUSH_BEFORE_SHA:-}" ] \
&& [ "$PUSH_BEFORE_SHA" != "0000000000000000000000000000000000000000" ] \
&& git cat-file -e "${PUSH_BEFORE_SHA}^{commit}" 2>/dev/null; then
from="$PUSH_BEFORE_SHA"
to="$PUSH_HEAD_SHA"
else
# No usable base revision - the first push of a branch. `--to`
# without `--from` lints every commit reachable from that revision.
echo "No usable base revision; linting the whole history."
pnpm exec commitlint --to "$PUSH_HEAD_SHA" --verbose
exit 0
fi
echo "Linting the commit range $from..$to"
pnpm exec commitlint --from "$from" --to "$to" --verbose
# A squash merge turns the pull request title into the commit subject,
# so the title has to satisfy the same convention.
- name: Lint the pull request title
if: github.event_name == 'pull_request'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: printf '%s\n' "$PR_TITLE" | pnpm exec commitlint --verbose
verify:
name: Verify (Node ${{ matrix.node }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
# 20.x is the oldest supported release (`engines.node`), 22.x the
# current LTS line.
node: ["20.x", "22.x"]
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Set up pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6
with:
version: 12.25.1
- name: Set up Node.js ${{ matrix.node }}
uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: ${{ matrix.node }}
cache: pnpm
- name: Install the dependencies
run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Build
run: pnpm build
- name: Test
run: pnpm test
# `pnpm test` runs the TypeScript sources through vitest, so nothing above
# proves that the emitted `dist/` actually boots. Start it and probe /health.
- name: Smoke the built output
run: pnpm smoke:dist
- name: Audit the production dependencies
run: pnpm audit --prod
# The step above is the merge gate (`--prod` covers what ships). This one
# reports advisories in the dev toolchain too, without blocking: a
# vulnerable vitest or commitlint is worth seeing but not worth a red PR.
- name: Audit all dependencies (informational)
continue-on-error: true
run: pnpm audit
# Windows coverage. The suite has platform-specific paths the Ubuntu matrix
# never runs: `OPEN_NOFOLLOW` collapses to 0 on Windows, the local-file read
# has a Windows fallback, and CLI discovery walks `%APPDATA%`/`%LOCALAPPDATA%`.
# The three media tests that pin POSIX `O_NOFOLLOW` semantics stay skipped here
# (`it.skipIf(platform === "win32")`) and keep running on Ubuntu; this job
# covers the rest of the suite. It is additive and not one of the required
# checks, but it is a real gate: a Windows-only regression must not merge.
windows:
name: Verify on Windows (Node 22.x)
runs-on: windows-latest
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Set up pnpm
uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6
with:
version: 12.25.1
- name: Set up Node.js 22.x
uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: 22.x
cache: pnpm
- name: Install the dependencies
run: pnpm install --frozen-lockfile
- name: Typecheck
run: pnpm typecheck
- name: Build
run: pnpm build
- name: Test
run: pnpm test
# The README documents a Docker deployment; nothing verified the Dockerfile
# until this job existed, so a broken image could merge unnoticed. Building is
# not enough: the image is started and probed so `pnpm prune --prod`, the
# copied file set and the runtime entry point are exercised too.
docker:
name: Docker image
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
steps:
- name: Check out the repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Build the image
run: docker build --tag opencode-api:ci .
# `env_file: .env` has to exist for the file to parse, and the repository
# does not ship a `.env`; the example file is a valid stand-in. This
# validates the compose contract the README documents.
- name: Validate the compose file
run: |
cp .env.example .env
docker compose config --quiet
# The image does not contain the OpenCode CLI, so the container is started
# with OPENCODE_AUTOSTART=false: /health must answer without any upstream
# being reachable. `-p 127.0.0.1:0:20123` lets Docker choose a free host
# port, which is then read back with `docker port`, so this never
# conflicts with a gateway already listening on the runner.
- name: Run the image and probe /health
run: |
set -euo pipefail
container_id="$(docker run --detach --rm \
--name opencode-api-ci \
-p 127.0.0.1:0:20123 \
--env OPENCODE_AUTOSTART=false \
--env OPENCODE_API_KEYS=ci-docker-smoke-key \
opencode-api:ci)"
# Always stop and remove the container, also when the probe fails.
cleanup() {
docker stop "$container_id" >/dev/null 2>&1 || true
docker rm --force "$container_id" >/dev/null 2>&1 || true
}
trap cleanup EXIT
probing="$(docker port "$container_id" 20123/tcp)"
port="${probing##*:}"
echo "Probing http://127.0.0.1:${port}/health"
healthy="false"
for _ in $(seq 1 30); do
if [ "$(docker inspect --format '{{.State.Running}}' "$container_id")" != "true" ]; then
echo "::error::the gateway container exited before answering /health"
docker logs "$container_id" || true
exit 1
fi
if curl --fail --silent --show-error --max-time 2 \
"http://127.0.0.1:${port}/health" >/dev/null; then
healthy="true"
break
fi
sleep 1
done
if [ "$healthy" != "true" ]; then
echo "::error::/health did not answer within 30 s"
docker logs "$container_id" || true
exit 1
fi
echo "The image answers /health."