-
Notifications
You must be signed in to change notification settings - Fork 0
369 lines (355 loc) · 15.2 KB
/
Copy pathci.yml
File metadata and controls
369 lines (355 loc) · 15.2 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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
# A push that supersedes an in-flight run makes that run's verdict
# irrelevant, so cancel it rather than paying for both. Keyed by ref, so
# concurrent PRs never cancel each other.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
# No SQL lane here on purpose: any target that builds or tests SQL must
# delegate to cmd/rgit-install, so -tags rgit_sql and parser generation stay
# in exactly one place (AGENTS.md § Delegation boundary). Plain `go build`/
# `go test` never touch it.
#
# cgo is mandatory -- rgit links tree-sitter through cgo, so CGO_ENABLED=0
# is not an option. ubuntu-latest ships gcc (verified against
# actions/runner-images' own software manifest), so no toolchain step is
# needed here.
jobs:
test:
name: test (unit lane)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: Rethunk-Tech/gh-actions/setup-go@e04e0afa3e00c59e33030fdbc7df29c15000357b # v1.7
# cmd/rgit-install's own tests (TestRunPrereqChecks, TestFindSQLAdapter)
# assert this in a real dev/CI environment -- not a build-time SQL
# lane (this file's own top comment), just PATH presence for the
# prereq check itself. Same step release.yml's darwin/linux/windows
# jobs already carry, kept in sync on purpose.
- run: npm install -g tree-sitter-cli
# -short: the unit lane CONTRIBUTING.md calls where the guarantee
# lives. It also skips every live-language-server test cleanly (each
# checks testing.Short() and/or exec.LookPath before dialling), which
# matters here since this runner has no language servers installed.
- run: go test -short ./...
lint:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: Rethunk-Tech/gh-actions/setup-go@e04e0afa3e00c59e33030fdbc7df29c15000357b # v1.7
with:
run-lint: "true"
run-govulncheck: "true"
e2e:
name: test (full suite)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: Rethunk-Tech/gh-actions/setup-go@e04e0afa3e00c59e33030fdbc7df29c15000357b # v1.7
# Same reason the unit lane above installs this: cmd/rgit-install's
# own tests run here too, unshortened by -short.
- run: npm install -g tree-sitter-cli
# The unit lane above is where a regression must fail; this lane
# proves the assembled program behaves -- it builds the binary and
# execs it, which -short skips entirely. Without it, CONTRIBUTING's
# claim that these gates run on every push was true of two lanes out
# of three. The completion cases guard on exec.LookPath and skip
# cleanly when a shell (zsh here) is absent from the runner.
- run: go test ./...
race:
name: race (internal/lsp)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: Rethunk-Tech/gh-actions/setup-go@e04e0afa3e00c59e33030fdbc7df29c15000357b # v1.7
# Scoped to internal/lsp, not ./...: CONTRIBUTING.md names jsonrpc2
# and the spawn lock -- both there -- as the concurrency that
# matters. Every live-server case in this package skips cleanly via
# its own exec.LookPath guard when nothing is installed.
- run: go test -race ./internal/lsp/...
install-script:
name: install script
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# shellcheck ships preinstalled on ubuntu-latest (actions/runner-images'
# own software manifest) -- no extra Action or install step needed, the
# same reasoning this file's own top comment gives for skipping a gcc
# setup step.
- run: shellcheck scripts/install.sh
# --dry-run never touches the network (docs/INSTALL.md § Install
# script): this is a lint of the script's own control flow -- flag
# parsing, OS/arch detection, the printed plan -- not a real download,
# so it needs nothing from the release it would otherwise fetch.
- run: VERSION=v1.2.0 sh scripts/install.sh --dry-run
- name: Show cosign plan in dry-run
run: |
mock_bin="$(mktemp -d)"
trap 'rm -rf "$mock_bin"' EXIT
printf '%s\n' \
'#!/bin/sh' \
'exit 0' >"$mock_bin/cosign"
chmod +x "$mock_bin/cosign"
output="$(
PATH="$mock_bin:/usr/bin:/bin" VERSION=v1.2.0 \
sh scripts/install.sh --dry-run
)"
printf '%s\n' "$output"
printf '%s\n' "$output" | grep -Fq 'cosign/Sigstore bundle' || {
printf '%s\n' 'missing cosign/Sigstore dry-run plan' >&2
exit 1
}
# Exercise Darwin's asset and checksum selection without needing a Mac
# runner or touching the network.
- run: |
mock_bin="$(mktemp -d)"
trap 'rm -rf "$mock_bin"' EXIT
printf '%s\n' \
'#!/bin/sh' \
"case \"\$1\" in" \
' -s) printf "%s\n" Darwin ;;' \
' -m) printf "%s\n" arm64 ;;' \
'esac' >"$mock_bin/uname"
chmod +x "$mock_bin/uname"
output="$(
PATH="$mock_bin:$PATH" VERSION=v1.2.0 sh scripts/install.sh --dry-run
)"
printf '%s\n' "$output"
for expected in \
rgit-v1.2.0-darwin-arm64 \
SHA256SUMS
do
printf '%s\n' "$output" | grep -Fq "$expected" || {
printf 'missing expected output: %s\n' "$expected" >&2
exit 1
}
done
- run: |
mock_bin="$(mktemp -d)"
trap 'rm -rf "$mock_bin"' EXIT
printf '%s\n' \
'#!/bin/sh' \
"case \"\$1\" in" \
' -s) printf "%s\n" Darwin ;;' \
' -m) printf "%s\n" x86_64 ;;' \
'esac' >"$mock_bin/uname"
chmod +x "$mock_bin/uname"
output="$(
PATH="$mock_bin:$PATH" VERSION=v1.2.0 sh scripts/install.sh --dry-run
)"
printf '%s\n' "$output"
for expected in \
rgit-v1.2.0-darwin-amd64 \
SHA256SUMS
do
printf '%s\n' "$output" | grep -Fq "$expected" || {
printf 'missing expected output: %s\n' "$expected" >&2
exit 1
}
done
- name: Verify optional cosign branch without network
run: |
fixture="$(mktemp -d)"
mock_bin="$(mktemp -d)"
no_cosign_prefix="$(mktemp -d)"
cosign_prefix="$(mktemp -d)"
cosign_marker="$(mktemp)"
trap 'rm -rf "$fixture" "$mock_bin" "$no_cosign_prefix" "$cosign_prefix" "$cosign_marker"' EXIT
asset="rgit-v1.2.0-linux-amd64"
printf '%s\n' \
'#!/bin/sh' \
'printf "%s\n" "rgit v1.2.0"' >"$fixture/$asset"
chmod +x "$fixture/$asset"
asset_digest="$(sha256sum "$fixture/$asset" | cut -d' ' -f1)"
printf '%s %s\n' "$asset_digest" "$asset" >"$fixture/SHA256SUMS"
printf '%s\n' '{"mock":true}' >"$fixture/SHA256SUMS.sigstore.json"
export COSIGN_FIXTURE="$fixture"
export COSIGN_MARKER="$cosign_marker"
printf '%s\n' \
'#!/bin/sh' \
'set -eu' \
'out=' \
'url=' \
"while [ \"\$#\" -gt 0 ]; do" \
" case \"\$1\" in" \
" -o) out=\$2; shift 2 ;;" \
' -*) shift ;;' \
" *) url=\$1; shift ;;" \
' esac' \
'done' \
"case \"\$url\" in" \
" */SHA256SUMS.sigstore.json) cp \"\$COSIGN_FIXTURE/SHA256SUMS.sigstore.json\" \"\$out\" ;;" \
" */SHA256SUMS) cp \"\$COSIGN_FIXTURE/SHA256SUMS\" \"\$out\" ;;" \
" */rgit-v1.2.0-linux-amd64) cp \"\$COSIGN_FIXTURE/rgit-v1.2.0-linux-amd64\" \"\$out\" ;;" \
' *) exit 1 ;;' \
'esac' >"$mock_bin/curl"
chmod +x "$mock_bin/curl"
PATH="$mock_bin:/usr/bin:/bin" \
PREFIX="$no_cosign_prefix" VERSION=v1.2.0 \
sh scripts/install.sh
test ! -s "$cosign_marker"
printf '%s\n' \
'#!/bin/sh' \
'set -eu' \
"[ \"\${1:-}\" = verify-blob ]" \
'shift' \
'bundle=' \
'identity=' \
'issuer=' \
'checksum=' \
"while [ \"\$#\" -gt 0 ]; do" \
" case \"\$1\" in" \
" --bundle) bundle=\$2; shift 2 ;;" \
" --certificate-identity-regexp) identity=\$2; shift 2 ;;" \
" --certificate-oidc-issuer) issuer=\$2; shift 2 ;;" \
" *) checksum=\$1; shift ;;" \
' esac' \
'done' \
"[ \"\$bundle\" = SHA256SUMS.sigstore.json ]" \
"[ \"\$checksum\" = SHA256SUMS ]" \
"[ \"\$identity\" = \"https://github.com/Rethunk-Tech/rethunk-git-cli/.github/workflows/release.yml@.*\" ]" \
"[ \"\$issuer\" = \"https://token.actions.githubusercontent.com\" ]" \
"test -s \"\$bundle\"" \
"test -s \"\$checksum\"" \
"printf \"%s\n\" verified >\"\$COSIGN_MARKER\"" >"$mock_bin/cosign"
chmod +x "$mock_bin/cosign"
PATH="$mock_bin:/usr/bin:/bin" \
PREFIX="$cosign_prefix" VERSION=v1.2.0 \
sh scripts/install.sh
grep -Fqx verified "$cosign_marker"
install-script-windows:
name: install script (windows)
runs-on: windows-latest
timeout-minutes: 5
env:
VERSION: v1.2.0
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Verify Windows dry-run output
shell: pwsh
run: |
$mockBin = Join-Path $env:RUNNER_TEMP "rgit-cosign-dry-run-$([guid]::NewGuid().ToString('N'))"
New-Item -ItemType Directory -Path $mockBin | Out-Null
try {
Set-Content -LiteralPath (Join-Path $mockBin 'cosign.cmd') `
-Value @('@echo off', 'exit /b 0') -Encoding ascii
$oldPath = $env:PATH
$env:PATH = "$mockBin;$oldPath"
$outputLines = @(& .\scripts\install.ps1 -DryRun)
} finally {
$env:PATH = $oldPath
Remove-Item -LiteralPath $mockBin -Recurse -Force -ErrorAction SilentlyContinue
}
if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}
$output = $outputLines -join [Environment]::NewLine
$output
foreach ($expected in @(
'rgit-v1.2.0-windows-amd64.exe',
'SHA256SUMS',
'cosign/Sigstore bundle'
)) {
if (-not $output.Contains($expected)) {
throw "missing expected output: $expected"
}
}
- name: Verify optional cosign branch without network
shell: pwsh
run: |
$fixture = Join-Path $env:RUNNER_TEMP "rgit-install-fixture-$([guid]::NewGuid().ToString('N'))"
$mockBin = Join-Path $env:RUNNER_TEMP "rgit-cosign-$([guid]::NewGuid().ToString('N'))"
$noCosignBin = Join-Path $env:RUNNER_TEMP "rgit-no-cosign-$([guid]::NewGuid().ToString('N'))"
$noCosignPrefix = Join-Path $env:RUNNER_TEMP "rgit-no-cosign-prefix-$([guid]::NewGuid().ToString('N'))"
$cosignPrefix = Join-Path $env:RUNNER_TEMP "rgit-cosign-prefix-$([guid]::NewGuid().ToString('N'))"
$marker = Join-Path $env:RUNNER_TEMP "rgit-cosign-marker-$([guid]::NewGuid().ToString('N'))"
$asset = 'rgit-v1.2.0-windows-amd64.exe'
foreach ($directory in @(
$fixture,
$mockBin,
$noCosignBin,
$noCosignPrefix,
$cosignPrefix
)) {
New-Item -ItemType Directory -Path $directory | Out-Null
}
[IO.File]::WriteAllText($marker, '')
Copy-Item -LiteralPath (Join-Path $env:SystemRoot 'System32\where.exe') `
-Destination (Join-Path $fixture $asset)
$digest = (Get-FileHash -LiteralPath (Join-Path $fixture $asset) -Algorithm SHA256).Hash
Set-Content -LiteralPath (Join-Path $fixture 'SHA256SUMS') `
-Value "$digest $asset" -Encoding ascii
Set-Content -LiteralPath (Join-Path $fixture 'SHA256SUMS.sigstore.json') `
-Value '{"mock":true}' -Encoding ascii
function Invoke-WebRequest {
param(
[string]$Uri,
[string]$OutFile
)
$name = [IO.Path]::GetFileName(([Uri]$Uri).AbsolutePath)
Copy-Item -LiteralPath (Join-Path $env:COSIGN_FIXTURE $name) `
-Destination $OutFile -Force
}
$cosignScript = @(
'@echo off'
'if /i not "%~1"=="verify-blob" exit /b 1'
'if /i not "%~2"=="--bundle" exit /b 1'
'if /i not "%~nx3"=="SHA256SUMS.sigstore.json" exit /b 1'
'if not exist "%~3" exit /b 1'
'if /i not "%~4"=="--certificate-identity-regexp" exit /b 1'
'if not "%~5"=="https://github.com/Rethunk-Tech/rethunk-git-cli/.github/workflows/release.yml@.*" exit /b 1'
'if /i not "%~6"=="--certificate-oidc-issuer" exit /b 1'
'if not "%~7"=="https://token.actions.githubusercontent.com" exit /b 1'
'if /i not "%~nx8"=="SHA256SUMS" exit /b 1'
'if not exist "%~8" exit /b 1'
'> "%COSIGN_MARKER%" echo verified'
'exit /b 0'
)
Set-Content -LiteralPath (Join-Path $mockBin 'cosign.cmd') `
-Value $cosignScript -Encoding ascii
$oldPath = $env:PATH
try {
$env:COSIGN_FIXTURE = $fixture
$env:COSIGN_MARKER = $marker
$env:PATH = $noCosignBin
$env:PREFIX = $noCosignPrefix
& .\scripts\install.ps1
if (-not (Test-Path -LiteralPath (Join-Path $noCosignPrefix 'rgit.exe'))) {
throw 'Windows install without cosign did not produce rgit.exe'
}
if ((Get-Item -LiteralPath $marker).Length -ne 0) {
throw 'cosign marker was written on the no-cosign path'
}
$env:PATH = "$mockBin;$env:SystemRoot\System32"
$env:PREFIX = $cosignPrefix
& .\scripts\install.ps1
if (-not (Test-Path -LiteralPath (Join-Path $cosignPrefix 'rgit.exe'))) {
throw 'Windows install with cosign did not produce rgit.exe'
}
if ((Get-Content -LiteralPath $marker -Raw).Trim() -ne 'verified') {
throw 'cosign marker was not written by the cosign path'
}
} finally {
$env:PATH = $oldPath
$env:PREFIX = $null
Remove-Item -LiteralPath @(
$fixture,
$mockBin,
$noCosignBin,
$noCosignPrefix,
$cosignPrefix,
$marker
) -Recurse -Force -ErrorAction SilentlyContinue
}