-
Notifications
You must be signed in to change notification settings - Fork 15
214 lines (188 loc) · 6.43 KB
/
test.yml
File metadata and controls
214 lines (188 loc) · 6.43 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
name: Test
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
repository_dispatch:
types: [contract-updated]
workflow_dispatch:
jobs:
lint:
name: lint
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.11.4
unit:
name: unit (L1)
runs-on: macos-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Vet
run: go vet ./...
- name: Run unit + contract tests
run: make test-coverage
- name: Upload coverage to Codecov
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
uses: codecov/codecov-action@v4
with:
use_oidc: true
files: ./coverage.out
flags: unittests
name: openboot-coverage
fail_ci_if_error: false
- name: Upload coverage artifacts (on failure)
if: failure()
uses: actions/upload-artifact@v4
with:
name: debug-coverage
path: |
coverage.out
coverage.html
retention-days: 7
contract:
name: contract schema (L2)
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Contract schema validation
run: |
git clone --depth 1 https://github.com/openbootdotdev/openboot-contract.git /tmp/contract
pip3 install --break-system-packages jsonschema
python3 -c "
import json, jsonschema, sys
checks = [
('/tmp/contract/schemas/remote-config.json', '/tmp/contract/fixtures/config-v1.json'),
('/tmp/contract/schemas/snapshot.json', '/tmp/contract/fixtures/snapshot-v1.json'),
]
failed = 0
for schema_path, fixture_path in checks:
schema = json.load(open(schema_path))
data = json.load(open(fixture_path))
try:
jsonschema.validate(data, schema)
print(f' ✓ {fixture_path.split(\"/\")[-1]} matches {schema_path.split(\"/\")[-1]}')
except jsonschema.ValidationError as e:
print(f' ✗ {fixture_path.split(\"/\")[-1]}: {e.message}')
failed += 1
sys.exit(1 if failed else 0)
"
curl-bash-smoke:
name: curl|bash smoke
if: github.event_name != 'pull_request'
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
- name: Build
run: make build
- name: Start mock server
run: |
python3 scripts/mock-server.py 18888 ./openboot &
echo $! > /tmp/mock-pid
for i in $(seq 1 20); do
curl -sf http://localhost:18888/api/packages >/dev/null 2>&1 && break
sleep 0.3
done
- name: Run curl|bash install (dry-run)
run: curl -fsSL http://localhost:18888/testuser/test-config/install | bash
- name: Stop mock server
if: always()
run: kill $(cat /tmp/mock-pid) 2>/dev/null || true
cli-compat:
name: old-cli compat
if: github.event_name != 'pull_request'
runs-on: macos-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get previous release version
id: prev
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
ASSET="openboot-darwin-arm64"
else
ASSET="openboot-darwin-amd64"
fi
PREV=$(curl -sf https://api.github.com/repos/openbootdotdev/openboot/releases \
-H "Authorization: Bearer $GITHUB_TOKEN" | \
ASSET="$ASSET" python3 -c "
import json, os, sys
asset = os.environ['ASSET']
releases = json.load(sys.stdin)
# Keep stable releases that still have the binary asset for this arch.
# Some older releases have had their binaries deleted (e.g. v0.55.1),
# so fall back to the most recent release that is still downloadable.
stable = [r for r in releases
if not r.get('prerelease') and not r.get('draft')
and any(a.get('name') == asset for a in r.get('assets', []))]
if stable:
print(stable[0]['tag_name'])
else:
sys.exit(1)
" 2>/dev/null) || true
echo "version=$PREV" >> $GITHUB_OUTPUT
- name: Download previous release binary
if: steps.prev.outputs.version != ''
run: |
VER="${{ steps.prev.outputs.version }}"
ARCH=$(uname -m)
if [ "$ARCH" = "arm64" ]; then
SUFFIX="darwin-arm64"
else
SUFFIX="darwin-amd64"
fi
curl -fsSL \
"https://github.com/openbootdotdev/openboot/releases/download/${VER}/openboot-${SUFFIX}" \
-o /tmp/openboot-prev
chmod +x /tmp/openboot-prev
- name: Start mock server for compat test
if: steps.prev.outputs.version != ''
run: |
python3 scripts/mock-server.py 18889 /tmp/openboot-prev &
echo $! > /tmp/compat-mock-pid
for i in $(seq 1 20); do
curl -sf http://localhost:18889/api/packages >/dev/null 2>&1 && break
sleep 0.3
done
- name: Run previous binary against current mock
if: steps.prev.outputs.version != ''
run: |
if /tmp/openboot-prev install --help >/dev/null 2>&1; then
OPENBOOT_DRY_RUN=true OPENBOOT_API_URL=http://localhost:18889 \
/tmp/openboot-prev install -s testuser/test-config
else
OPENBOOT_DRY_RUN=true OPENBOOT_API_URL=http://localhost:18889 \
/tmp/openboot-prev -s -u testuser/test-config
fi
- name: Stop compat mock server
if: always()
run: kill $(cat /tmp/compat-mock-pid) 2>/dev/null || true