Repository navigation
223 lines (220 loc) · 11 KB
/
Copy pathci.yml
File metadata and controls
223 lines (220 loc) · 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
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
name: ci
on:
pull_request:
workflow_dispatch:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
# No test ever calls an Ever Platform host: the anonymous statistics (on by default) are switched off in every job
env:
TR_EVER_STATS_ENABLED: 'false'
jobs:
api-unit:
runs-on: ${{ vars.RUNNER_LINUX_X64_4 || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '26.12.1'
- run: npm install --global --ignore-scripts yarn@1.22.22
- run: yarn install --frozen-lockfile --network-timeout 600000
- name: Lint API
run: yarn --cwd api lint
- name: API unit tests
run: yarn --cwd api test
api-e2e:
runs-on: ${{ vars.RUNNER_LINUX_X64_4 || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
db: [better-sqlite3, postgres, mysql]
# Throwaway databases of this job only, reachable from the job alone: no credentials needed
services:
postgres:
image: postgres:15-alpine
env:
POSTGRES_DB: tr_e2e
POSTGRES_USER: tr
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U tr -d tr_e2e" --health-interval 5s --health-timeout 5s --health-retries 20
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: tr_e2e
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
ports:
- 3306:3306
options: >-
--health-cmd "mysqladmin ping -h 127.0.0.1" --health-interval 5s --health-timeout 5s --health-retries 30
env:
NODE_ENV: e2e
TR_DEFAULT_PROJECT_PLAN: default
TR_ACCESS_LOGS_ENABLED: 'false'
TR_DB_TYPE: ${{ matrix.db }}
TR_DB_HOST: 127.0.0.1
TR_DB_PORT: ${{ matrix.db == 'mysql' && '3306' || '5432' }}
TR_DB_USER: ${{ matrix.db == 'mysql' && 'root' || 'tr' }}
TR_DB_DATABASE: ${{ matrix.db == 'better-sqlite3' && 'data/tr_e2e.sqlite3' || 'tr_e2e' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '26.12.1'
- run: npm install --global --ignore-scripts yarn@1.22.22
- run: yarn install --frozen-lockfile --network-timeout 600000
# The whole existing suite, plus the Ever ID sign-in suite, on each database
- name: API e2e tests (${{ matrix.db }})
working-directory: api
run: yarn jest --config ./test/jest-e2e.json --runInBand --forceExit
webapp-unit:
runs-on: ${{ vars.RUNNER_LINUX_X64_4 || 'ubuntu-latest' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '26.12.1'
- run: npm install --global --ignore-scripts yarn@1.22.22
- run: yarn install --frozen-lockfile --network-timeout 600000
- uses: browser-actions/setup-chrome@48ad923757ca74d66703209fe939badbdf80f2f4 # v2.2.0
id: chrome
- name: Webapp unit tests
working-directory: webapp
env:
CHROME_BIN: ${{ steps.chrome.outputs.chrome-path }}
run: yarn test --watch=false --browsers=ChromeHeadlessCI --progress=false
# What the Ever Platform modules may send, proven at run time: nothing when they are off, nothing when they are loaded
# but switched off, and only their own calls when they are on (tools/egress-audit/README.md). Docker with NET_RAW and
# NET_ADMIN is needed for the capture. The steps after the harness install run even when one before them failed, so
# that one red step does not hide the result of the others.
egress:
runs-on: ${{ vars.RUNNER_LINUX_X64_8 || vars.RUNNER_LINUX_X64_4 || 'ubuntu-latest' }}
timeout-minutes: 150
env:
AUDIT_CONFIG: tools/egress-audit/egress-audit.config.json
AUDIT_ARTIFACTS: egress-audit-artifacts
TR_IMAGE: ever-traduora:egress-audit
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6
with:
node-version: '26.12.1'
- name: Install the egress audit harness (the version and integrity tools/egress-audit/harness.json pins)
run: |
name=$(node -p "require('./tools/egress-audit/harness.json').package")
version=$(node -p "require('./tools/egress-audit/harness.json').version")
expected=$(node -p "require('./tools/egress-audit/harness.json').integrity")
mkdir -p "$RUNNER_TEMP/harness"
cd "$RUNNER_TEMP/harness"
npm pack "${name}@${version}" --registry https://registry.npmjs.org --json > pack.json
actual=$(node -p "require('./pack.json')[0].integrity")
if [ "$actual" != "$expected" ]; then
echo "::error::${name}@${version} does not match the pinned integrity"
exit 1
fi
echo '{"name":"egress-audit-harness","private":true}' > package.json
npm install --no-audit --no-fund --ignore-scripts --registry https://registry.npmjs.org ./ever-co-connect-tools-${version}.tgz
echo "EGRESS_AUDIT=$RUNNER_TEMP/harness/node_modules/@ever-co/connect-tools/dist/egress-audit/run.mjs" >> "$GITHUB_ENV"
- name: 'Static: the Ever Platform code never guesses where it runs'
if: ${{ !cancelled() }}
run: node "$EGRESS_AUDIT" cloud-inference --dirs api/src/ever-stats,api/src/ever-instance,api/src/ever-platform,api/src/ever-connect
- name: Build the image under test
if: ${{ !cancelled() }}
# The registry cache can time out under load (ESOCKETTIMEDOUT): the build is tried up to three times, and the
# layers that finished are reused
run: |
for attempt in 1 2 3; do
if docker build -f Dockerfile --build-arg "VERDACCIO_REGISTRY=${{ vars.VERDACCIO_REGISTRY }}" -t "$TR_IMAGE" .; then
exit 0
fi
echo "::warning::the image build failed (attempt $attempt of 3)"
sleep 30
done
exit 1
- name: Secrets of this run
if: ${{ !cancelled() }}
run: |
secret=$(openssl rand -hex 32)
echo "::add-mask::$secret"
echo "TR_AUDIT_SECRET=$secret" >> "$GITHUB_ENV"
- name: 'off: both modules off (TR_EVER_STATS_ENABLED=false, connection unset)'
if: ${{ !cancelled() }}
run: node "$EGRESS_AUDIT" --config "$AUDIT_CONFIG" --mode off --legs api --artifacts "$AUDIT_ARTIFACTS" --verbose
- name: 'loaded_off: both modules loaded, statistics switched off by the operator, not connected'
if: ${{ !cancelled() }}
run: node "$EGRESS_AUDIT" --config "$AUDIT_CONFIG" --mode loaded_off --legs api --artifacts "$AUDIT_ARTIFACTS" --verbose
- name: 'positive_stats: statistics on, against the mock platform'
if: ${{ !cancelled() }}
run: node "$EGRESS_AUDIT" --config "$AUDIT_CONFIG" --mode positive_stats --legs api --artifacts "$AUDIT_ARTIFACTS" --verbose
- name: 'positive_connect: connected with a mock connect code'
if: ${{ !cancelled() }}
run: node "$EGRESS_AUDIT" --config "$AUDIT_CONFIG" --mode positive_connect --legs api --artifacts "$AUDIT_ARTIFACTS" --verbose
- name: 'Control: positive_stats without the mock platform must fail'
if: ${{ !cancelled() }}
run: |
set +e
node "$EGRESS_AUDIT" --config "$AUDIT_CONFIG" --mode positive_stats --no-mock --legs api --artifacts "$AUDIT_ARTIFACTS/control" --verbose
code=$?
set -e
if [ "$code" -ne 1 ]; then
echo "::error::without the mock platform the audit must report a violation (exit 1); it exited $code"
exit 1
fi
echo "The control failed as it must (exit 1)."
- name: 'The statistics scheduler: not loaded in off, and in loaded_off it asked after the switch-off'
if: ${{ !cancelled() }}
run: |
node -e '
const fs = require("fs"), path = require("path");
const logOf = (mode) => {
const dir = path.join(process.env.AUDIT_ARTIFACTS, mode);
const file = fs.existsSync(dir) ? fs.readdirSync(dir).find((name) => /^product-api.*\.log$/.test(name)) : null;
return file ? fs.readFileSync(path.join(dir, file), "utf8") : null;
};
let failed = false;
const fail = (message) => { console.error(`::error::${message}`); failed = true; };
const off = logOf("off");
if (off === null) fail("off: the API log is missing");
else if (/ever_(stats|connect)\./.test(off)) fail("off: an Ever Platform module ran");
else console.log("off: no Ever Platform module ran.");
const loaded = logOf("loaded_off");
if (loaded === null) fail("loaded_off: the API log is missing");
else if (!loaded.includes("ever_stats.send outcome=skipped_ui_off")) fail("loaded_off: the scheduler never ran after the switch-off: the run proves nothing");
else if (/ever_stats\.send outcome=(sent|accepted|rejected|failed)/.test(loaded)) fail("loaded_off: the scheduler tried to send");
else console.log("loaded_off: the scheduler ran after the switch-off and sent nothing.");
process.exit(failed ? 1 : 0);
'
- name: The evidence of a mode that did not pass (the API log and the driver's steps)
if: ${{ !cancelled() }}
# The in-cluster runner may keep no artifacts: what explains a failure is printed here. Nothing in these files is a
# secret (TR_SECRET is never logged, and the operator account exists only in the run's database).
run: |
for dir in "$AUDIT_ARTIFACTS"/*/ "$AUDIT_ARTIFACTS"/control/*/; do
[ -f "$dir/report.json" ] || continue
if node -e 'process.exit(JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).exit === 0 ? 0 : 1)' "$dir/report.json"; then continue; fi
echo "::group::$dir"
for file in "$dir"driver-*.log; do [ -f "$file" ] && { echo "--- $file"; tail -n 40 "$file"; }; done
for file in "$dir"product-*.log; do [ -f "$file" ] && { echo "--- $file"; tail -n 80 "$file"; }; done
echo "::endgroup::"
done
- name: Upload the evidence (pcaps, DNS logs, reports)
if: always()
# The in-cluster runner may have no artifact store: the verdict is the steps above, not this upload
continue-on-error: true
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: egress-audit
path: ${{ env.AUDIT_ARTIFACTS }}
retention-days: 14