Repository navigation
195 lines (187 loc) · 8.29 KB
/
Copy pathci.yml
File metadata and controls
195 lines (187 loc) · 8.29 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
# SPDX-License-Identifier: Apache-2.0
# Copyright 2026 Aaron K. Clark
#
# CI for the GitHub mirror. Codeberg/Forgejo runs the audit-only workflow in
# .forgejo/workflows/ (its container runner has no Docker, so it can't host the
# Testcontainers .NET suite). GitHub's hosted ubuntu runners ship Docker, so here
# we run *both* test suites end to end plus the same dependency audit.
name: ci
on:
push:
branches: [main]
pull_request:
schedule:
- cron: "0 6 * * 1" # weekly Mon 06:00 UTC — catch CVEs disclosed after merge
jobs:
web:
name: Web — WCAG checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: "24"
cache: npm
- name: Install and audit development dependencies
run: |
npm ci
npm audit --audit-level=high
- name: Install Playwright Chromium
run: npx playwright install --with-deps chromium
- name: Test keyboard, responsive, and automated accessibility behavior
run: npm run test:web
dotnet:
name: .NET — test + audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-dotnet@v5
with:
dotnet-version: "10.0.x"
- name: Verify migration naming (NNNN_lowercase_name.sql)
run: |
fail=0
for f in api/ApplyTrack.Api/Migrations/*.sql; do
base=$(basename "$f")
if ! printf '%s' "$base" | grep -Eq '^[0-9]{4}_[a-z0-9_]+\.sql$'; then
echo "::error file=$f::Migration '$base' must match NNNN_lowercase_name.sql"
fail=1
fi
done
exit $fail
# The browser submitter test drives a real Playwright server (the Node package
# the web job uses) at a loopback fixture form; it skips itself when absent.
- uses: actions/setup-node@v6
with:
node-version: "22"
cache: npm
- run: npm ci && npx playwright install --with-deps chromium
- name: Test (xUnit + Testcontainers-Postgres)
working-directory: api
run: dotnet test --logger "console;verbosity=normal"
- name: Audit NuGet packages
working-directory: api
run: |
dotnet list package --vulnerable --include-transitive 2>&1 | tee /tmp/audit.txt
if grep -q "has the following vulnerable packages" /tmp/audit.txt; then
echo "::error::Vulnerable NuGet packages found"; exit 1
fi
# The agent runs from the api image as uid 1654 under the production hardening
# (read-only root, noexec /tmp, no capabilities, no-new-privileges). Nothing ran
# the image that way, so a Playwright driver only root could execute shipped and
# broke every packet build (#392). Start the driver exactly as the agent would.
image:
name: Image — agent starts Playwright as uid 1654
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Build the api image
run: docker build -t osapplytrack-api:ci -f api/ApplyTrack.Api/Dockerfile api
- name: Run the Playwright driver under the agent's hardening
run: |
node=$(docker run --rm --entrypoint sh osapplytrack-api:ci -c 'ls /app/.playwright/node/*/node')
hardened() {
docker run --rm --user 1654:1654 --read-only --tmpfs /tmp:rw,noexec,nosuid \
--cap-drop ALL --security-opt no-new-privileges --entrypoint "$node" \
osapplytrack-api:ci "$@"
}
hardened --version
hardened /app/.playwright/package/cli.js --version
python:
name: Python — lint + test + audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install
run: |
python -m pip install --upgrade pip # keep the toolchain current so pip-audit isn't tripped by a stale runner pip
pip install --no-cache-dir -e ".[dev]" pip-audit
- name: Lint (ruff + mypy)
run: |
ruff check src tests
mypy src
- name: Security scan (bandit)
run: bandit -c pyproject.toml -r src/applytrack -q
- name: Test (pytest)
run: pytest -q
- name: Audit Python packages
run: pip-audit
# The step above audits a fresh resolution, which can be clean while uv.lock
# still pins a vulnerable version (anyio 4.14.0 did, #390). Audit the locked
# set too; --locked also fails if uv.lock has drifted from pyproject.toml.
# The lock forks by Python version (anyio 4.14.x on 3.10, 4.15.x on 3.11+), and
# pip-audit skips pins whose marker doesn't match this runner's 3.12 — so the
# markers are stripped and every fork's pins audited. pip-audit refuses a name
# twice in one file, so the Nth pin of each name goes to locked-N.txt.
- name: Audit locked Python packages (uv.lock, every fork)
run: |
pip install --no-cache-dir uv
d="$RUNNER_TEMP/locked"; mkdir -p "$d"
uv export --locked --all-extras --no-emit-project --no-hashes --no-header --no-annotate \
| sed 's/ *;.*//' \
| awk -F'==' -v d="$d" '{ print > (d "/locked-" (++seen[$1]) ".txt") }'
for f in "$d"/locked-*.txt; do
pip-audit --disable-pip --no-deps -r "$f"
done
# A red build on main is visible only to whoever happens to open the Actions tab.
# The weekly schedule makes that worse: an advisory published after a merge turns
# main red with no commit to blame and nobody watching — GHSA-q939-rpr3-3284 sat
# unnoticed for five days that way. File an issue instead, once per outage: a
# second failure comments on the open issue rather than opening a new one every
# Monday. Pull requests are excluded — their author already sees the failing check.
notify:
name: File an issue when main is broken
needs: [web, dotnet, image, python]
if: failure() && github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
steps:
- name: Open or update the CI failure issue
env:
# Values reach the script through env, never ${{ }} interpolation inside it,
# so nothing here can be parsed as shell.
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
TITLE: CI is failing on main
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
TRIGGER: ${{ github.event_name }}
SHA: ${{ github.sha }}
WEB: ${{ needs.web.result }}
DOTNET: ${{ needs.dotnet.result }}
IMAGE: ${{ needs.image.result }}
PYTHON: ${{ needs.python.result }}
run: |
{
echo "The \`ci\` workflow failed on \`main\`."
echo
echo "**Failed jobs**"
if [ "$WEB" = failure ]; then echo "- Web — WCAG checks"; fi
if [ "$DOTNET" = failure ]; then echo "- .NET — test + audit"; fi
if [ "$IMAGE" = failure ]; then echo "- Image — agent starts Playwright as uid 1654"; fi
if [ "$PYTHON" = failure ]; then echo "- Python — lint + test + audit"; fi
echo
echo "| | |"
echo "| --- | --- |"
echo "| Run | $RUN_URL |"
echo "| Commit | \`$SHA\` |"
echo "| Trigger | \`$TRIGGER\` |"
echo
echo "If this is the weekly scheduled run and no commit landed since the last"
echo "green build, the cause is most likely a **newly published advisory against an"
echo "existing dependency** rather than a code change — check the audit steps first."
} > body.md
# Match on the exact title against the live issue list rather than the search
# index, which lags behind creation and would let a second run open a duplicate.
number=$(gh issue list --state open --limit 100 --json number,title \
--jq '[.[] | select(.title == env.TITLE)] | first | .number // empty')
if [ -n "$number" ]; then
gh issue comment "$number" --body-file body.md
echo "Commented on existing issue #$number"
else
gh issue create --title "$TITLE" --body-file body.md
fi