-
Notifications
You must be signed in to change notification settings - Fork 1
241 lines (236 loc) · 10.1 KB
/
Copy pathci.yml
File metadata and controls
241 lines (236 loc) · 10.1 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
# Boatstack-owned control plane.
name: Verify Boatstack distribution
on:
pull_request:
push:
branches: [main]
permissions:
contents: read
jobs:
# Unix runs the full suite serially (~1-2 min) and is the unsharded correctness
# reference. Windows is sharded in `test-windows` (see below).
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Verify upstream sync contract
shell: bash
run: |
workflow=".github/workflows/sync-upstream.yml"
current="labs/12-product-engineering-loop"
retired="examples/12-product-engineering-loop"
count="$(grep -cF "$current" "$workflow")"
if [[ "$count" != "2" ]]; then
echo "Expected exactly two sync references to $current; found $count." >&2
exit 1
fi
if grep -Fq "$retired" "$workflow"; then
echo "Sync workflow still references retired path $retired." >&2
exit 1
fi
title='Sync Boatstack from Intelligence Flow Labs @ $short'
title_count="$(grep -cF "$title" "$workflow")"
if [[ "$title_count" != "2" ]]; then
echo "Expected commit and PR titles to use $title; found $title_count." >&2
exit 1
fi
- name: Detect projected runtime
id: runtime
shell: bash
run: |
if [[ -f boatstack/go.mod ]]; then
echo "go=true" >> "$GITHUB_OUTPUT"
else
echo "go=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-go@v5
if: steps.runtime.outputs.go == 'true'
with:
go-version-file: boatstack/go.mod
cache-dependency-path: boatstack/go.mod
- run: go test ./...
if: steps.runtime.outputs.go == 'true'
working-directory: boatstack
- run: go build ./cmd/boatstack-helper
if: steps.runtime.outputs.go == 'true'
working-directory: boatstack
- uses: actions/setup-python@v5
if: steps.runtime.outputs.go != 'true'
with:
python-version: "3.11"
- name: Verify legacy projection during migration
if: steps.runtime.outputs.go != 'true'
env:
PYTHONUTF8: "1"
run: python3 -m unittest discover -s tests -v
- name: Compile legacy projection during migration
if: steps.runtime.outputs.go != 'true'
env:
PYTHONUTF8: "1"
run: python3 -m compileall -q boatstack
- name: Validate Bash installer
if: steps.runtime.outputs.go == 'true'
shell: bash
run: bash -n install.sh
# Windows `go test` is dominated by per-process spawn latency (each test spawns
# several `git` processes; the suite is ~330 tests run serially), so the full
# suite takes ~15 min on Windows vs ~1 min on Unix. In-process t.Parallel() is
# unsafe (the package swaps ~14 global function-seams), so we shard across
# processes: N runners, each running a disjoint, balanced subset. Shard
# assignment is an LPT makespan-minimization controller — see
# .github/scripts/ci_shard.py. Target: slowest shard < 5 min.
test-windows:
strategy:
fail-fast: false
matrix:
shard: [0, 1, 2, 3, 4, 5]
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Detect projected runtime
id: runtime
shell: bash
run: |
if [[ -f boatstack/go.mod ]]; then
echo "go=true" >> "$GITHUB_OUTPUT"
else
echo "go=false" >> "$GITHUB_OUTPUT"
fi
# Windows `go test`/`go build` is dominated by Microsoft Defender scanning
# the many small files the Go toolchain emits during compile/link. Excluding
# the Go caches, the workspace, and go.exe is a major wall-clock lever;
# sharding on top of this is what gets the suite under 5 min.
- name: Exclude Go caches from Microsoft Defender (Windows)
if: steps.runtime.outputs.go == 'true'
shell: pwsh
run: |
$targets = @(
"$env:LOCALAPPDATA\go-build", # GOCACHE (build cache)
"$env:USERPROFILE\go", # GOPATH incl. pkg\mod (GOMODCACHE)
$env:GITHUB_WORKSPACE, # sources + compiled test binaries
$env:RUNNER_TEMP
) | Where-Object { $_ -and $_.Trim() -ne '' } | Select-Object -Unique
foreach ($t in $targets) {
try {
Add-MpPreference -ExclusionPath $t -ErrorAction Stop
Write-Host "Defender exclusion added: $t"
} catch {
Write-Host "::warning::Defender exclusion failed for $t : $($_.Exception.Message)"
}
}
try { Add-MpPreference -ExclusionProcess 'go.exe' -ErrorAction Stop } catch {}
- uses: actions/setup-go@v5
if: steps.runtime.outputs.go == 'true'
with:
go-version-file: boatstack/go.mod
cache-dependency-path: boatstack/go.mod
# Enumerate tests, pick this shard's balanced subset, and run only those.
# `go test -list` and `go test -run` share the warm GOCACHE, so the second
# compile is a cache hit. An empty shard is a clean skip — never
# `go test -run ''`, which would run the whole suite.
- name: Test shard ${{ matrix.shard }}
if: steps.runtime.outputs.go == 'true'
shell: bash
working-directory: boatstack
run: |
regex=$(go test -list '^Test' ./... | python "${{ github.workspace }}/.github/scripts/ci_shard.py" --total 6 --index ${{ matrix.shard }})
if [ -z "$regex" ]; then
echo "Shard ${{ matrix.shard }} is empty; nothing to run."
exit 0
fi
echo "Shard ${{ matrix.shard }} selects $(( $(grep -o '|' <<<"$regex" | wc -l) + 1 )) tests"
go test -run "$regex" ./...
# Windows-only, non-test validation runs once (on shard 0), not per shard.
- name: Build helper
if: steps.runtime.outputs.go == 'true' && matrix.shard == '0'
working-directory: boatstack
run: go build ./cmd/boatstack-helper
- name: Validate PowerShell installer
if: steps.runtime.outputs.go == 'true' && matrix.shard == '0'
shell: pwsh
run: |
$tokens = $null
$errors = $null
[System.Management.Automation.Language.Parser]::ParseFile((Resolve-Path install.ps1), [ref]$tokens, [ref]$errors) > $null
if ($errors.Count -gt 0) {
$errors | ForEach-Object { Write-Error $_ }
exit 1
}
auto-merge-sync:
if: >-
github.event_name == 'pull_request' &&
github.event.pull_request.head.repo.full_name == github.repository &&
startsWith(github.head_ref, 'sync/intelligence-flow-')
needs: [test, test-windows]
runs-on: ubuntu-latest
steps:
- name: Create repository automation token
id: app-token
uses: actions/create-github-app-token@v3
with:
client-id: ${{ vars.BOATSTACK_APP_CLIENT_ID }}
private-key: ${{ secrets.BOATSTACK_APP_PRIVATE_KEY }}
owner: operatorstack
repositories: boatstack
permission-contents: write
permission-pull-requests: write
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Verify generated projection provenance
env:
APP_SLUG: ${{ steps.app-token.outputs.app-slug }}
HEAD_BRANCH: ${{ github.head_ref }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
shell: bash
run: |
source_repo="$(jq -r '.source.repository' UPSTREAM.json)"
source_commit="$(jq -r '.source.commit' UPSTREAM.json)"
short="${source_commit:0:12}"
[[ "$PR_AUTHOR" == "${APP_SLUG}[bot]" ]]
[[ "$source_repo" == "operatorstack/intelligence-flow" ]]
[[ "$HEAD_BRANCH" == "sync/intelligence-flow-$short" ]]
- name: Merge verified generated PR
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_URL: ${{ github.event.pull_request.html_url }}
run: gh pr merge "$PR_URL" --squash
# After a sync lands, close any older sync PR it supersedes. A sync PR that
# failed CI is never merged by this job, so without this it lingers as an
# orphan once a newer sync overtakes it (see the pile-up that motivated this).
# intelligence-flow is public, so the default token can read its history for
# the ancestry check; closing uses the app token (pull-requests: write).
- name: Check out Intelligence Flow for ancestry
uses: actions/checkout@v4
with:
repository: operatorstack/intelligence-flow
fetch-depth: 0
path: intelligence-flow
- name: Close superseded sync PRs
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
shell: bash
run: |
merged="$(jq -r '.source.commit' UPSTREAM.json)"
if [[ -z "$merged" || "$merged" == "null" ]]; then
echo "No recorded source commit; skipping supersession cleanup."
exit 0
fi
gh pr list --state open --json number,headRefName \
--jq '.[] | select(.headRefName | startswith("sync/intelligence-flow-")) | [.number, .headRefName] | @tsv' \
| while IFS=$'\t' read -r number branch; do
short="${branch#sync/intelligence-flow-}"
# Skip the sync that just merged (its own branch), not a supersession.
[[ "${merged:0:12}" == "$short" ]] && continue
# Close only PRs whose source is an ancestor of the merged source —
# i.e. already included. A newer, not-yet-merged sync (descendant) is
# left untouched.
if git -C intelligence-flow merge-base --is-ancestor "$short" "$merged" 2>/dev/null; then
echo "Closing superseded sync PR #$number ($short)."
gh pr close "$number" --comment "Superseded by the sync at ${merged:0:12}, which already includes this PR's source ($short). Closing the stale sync PR automatically."
fi
done