Skip to content

Commit 2007c53

Browse files
authored
chore: CI fixes (#4160)
1 parent 0bb8c7b commit 2007c53

10 files changed

Lines changed: 297 additions & 47 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 164 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,26 @@ jobs:
101101
run: nix flake check --impure
102102

103103
- name: Build components
104-
run: nix develop --impure .#ci -c make -j 3 build
104+
run: |
105+
# On Depot runners, cgo external linking can spill large temporary linker
106+
# files into /run via the default temp dir. Keep Go and system temp files
107+
# on the workspace disk for this step to avoid "no space left on device",
108+
# while still allowing each parallel go build to get its own temp dir.
109+
mkdir -p \
110+
"$GITHUB_WORKSPACE/.tmp/go-work" \
111+
"$GITHUB_WORKSPACE/.tmp/system"
112+
env \
113+
GOTMPDIR="$GITHUB_WORKSPACE/.tmp/go-work" \
114+
TMPDIR="$GITHUB_WORKSPACE/.tmp/system" \
115+
nix develop --impure .#ci -c make -j 4 build
105116
106117
- name: Validate commit messages
107118
run: |
108119
nix develop --impure .#ci -c pre-commit run -a
109120
nix develop --impure .#ci -c pre-commit run --hook-stage manual
110121
111-
generators:
112-
name: Code Generators
122+
generators-openapi:
123+
name: Code Generators / OpenAPI
113124
runs-on: depot-ubuntu-latest-8
114125

115126
steps:
@@ -151,7 +162,130 @@ jobs:
151162
152163
- name: Ensure code generators are run
153164
run: |
154-
nix develop --impure .#ci -c make generate-all
165+
nix develop --impure .#ci -c make update-openapi
166+
167+
# does not detect new files
168+
if [ -n "$(git diff --exit-code)" ]; then
169+
git diff
170+
171+
echo "Code generators have not been run, please run 'make generate-all' and commit the changes"
172+
exit 1
173+
fi
174+
175+
# detect files not committed
176+
if [ -n "$(git status --porcelain)" ]; then
177+
git status --porcelain
178+
179+
echo "Code generators have not been run, please run 'make generate-all' and commit the changes"
180+
exit 1
181+
fi
182+
183+
generators-javascript-sdk:
184+
name: Code Generators / JavaScript SDK
185+
runs-on: depot-ubuntu-latest-8
186+
187+
steps:
188+
- name: Checkout repository
189+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
190+
with:
191+
persist-credentials: false
192+
193+
- name: Set up Nix
194+
uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34
195+
with:
196+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
197+
nix_conf: |
198+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
199+
keep-env-derivations = true
200+
keep-outputs = true
201+
202+
- name: Restore Nix store
203+
uses: nix-community/cache-nix-action/restore@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
204+
with:
205+
primary-key: ${{ runner.os }}-openmeter-nix-build-${{ github.ref_name }}-${{ hashFiles('flake.*') }}
206+
restore-prefixes-first-match: |
207+
${{ runner.os }}-openmeter-nix-build-${{ github.ref_name }}-
208+
${{ runner.os }}-openmeter-nix-build-main-${{ hashFiles('flake.*') }}
209+
${{ runner.os }}-openmeter-nix-build-main-
210+
${{ runner.os }}-openmeter-nix-build-
211+
212+
- name: Restore go.mod cache if exists
213+
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
214+
with:
215+
path: .devenv/state/go
216+
key: ${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
217+
# Prefer to restore the branch cache over the main cache
218+
restore-keys: |
219+
${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
220+
${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-
221+
${{ runner.os }}-openmeter-go-modules-main-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
222+
${{ runner.os }}-openmeter-go-modules-main
223+
224+
- name: Ensure code generators are run
225+
run: |
226+
nix develop --impure .#ci -c make generate-javascript-sdk
227+
228+
# does not detect new files
229+
if [ -n "$(git diff --exit-code)" ]; then
230+
git diff
231+
232+
echo "Code generators have not been run, please run 'make generate-all' and commit the changes"
233+
exit 1
234+
fi
235+
236+
# detect files not committed
237+
if [ -n "$(git status --porcelain)" ]; then
238+
git status --porcelain
239+
240+
echo "Code generators have not been run, please run 'make generate-all' and commit the changes"
241+
exit 1
242+
fi
243+
244+
generators-go:
245+
name: Code Generators / Go
246+
runs-on: depot-ubuntu-latest-8
247+
248+
steps:
249+
- name: Checkout repository
250+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
251+
with:
252+
persist-credentials: false
253+
254+
- name: Set up Nix
255+
uses: nixbuild/nix-quick-install-action@2c9db80fb984ceb1bcaa77cdda3fdf8cfba92035 # v34
256+
with:
257+
github_access_token: ${{ secrets.GITHUB_TOKEN }}
258+
nix_conf: |
259+
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
260+
keep-env-derivations = true
261+
keep-outputs = true
262+
263+
- name: Restore Nix store
264+
uses: nix-community/cache-nix-action/restore@7df957e333c1e5da7721f60227dbba6d06080569 # v7.0.2
265+
with:
266+
primary-key: ${{ runner.os }}-openmeter-nix-build-${{ github.ref_name }}-${{ hashFiles('flake.*') }}
267+
restore-prefixes-first-match: |
268+
${{ runner.os }}-openmeter-nix-build-${{ github.ref_name }}-
269+
${{ runner.os }}-openmeter-nix-build-main-${{ hashFiles('flake.*') }}
270+
${{ runner.os }}-openmeter-nix-build-main-
271+
${{ runner.os }}-openmeter-nix-build-
272+
273+
- name: Restore go.mod cache if exists
274+
uses: actions/cache/restore@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
275+
with:
276+
path: .devenv/state/go
277+
key: ${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
278+
# Prefer to restore the branch cache over the main cache
279+
restore-keys: |
280+
${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
281+
${{ runner.os }}-openmeter-go-modules-${{ github.ref_name }}-
282+
${{ runner.os }}-openmeter-go-modules-main-${{ hashFiles('flake.*', 'go.*', '.github/workflows/*.yaml') }}
283+
${{ runner.os }}-openmeter-go-modules-main
284+
285+
- name: Ensure code generators are run
286+
run: |
287+
nix develop --impure .#ci -c make patch-oapi-templates
288+
nix develop --impure .#ci -c go generate ./...
155289
156290
# does not detect new files
157291
if [ -n "$(git diff --exit-code)" ]; then
@@ -232,7 +366,16 @@ jobs:
232366
SVIX_JWT_SECRET: DUMMY_JWT_SECRET
233367
# count=1 is needed to force retest
234368
run: |
235-
nix develop --impure .#ci -c make test-nocache
369+
# On Depot runners, cgo builds during tests can spill temporary files
370+
# into /run via the default temp dir. Keep Go and system temp files on
371+
# the workspace disk for this step to avoid "no space left on device".
372+
mkdir -p \
373+
"$GITHUB_WORKSPACE/.tmp/go-work" \
374+
"$GITHUB_WORKSPACE/.tmp/system"
375+
env \
376+
GOTMPDIR="$GITHUB_WORKSPACE/.tmp/go-work" \
377+
TMPDIR="$GITHUB_WORKSPACE/.tmp/system" \
378+
nix develop --impure .#ci -c make test-nocache
236379
237380
- name: Stop docker-compose dependencies
238381
if: always()
@@ -441,6 +584,14 @@ jobs:
441584
442585
cat quickstart/docker-compose.override.yaml
443586
587+
- name: Debug quickstart runner state
588+
run: |
589+
echo "### DEBUG"
590+
ss -ltnp | grep ':49000 ' || true
591+
docker ps -a
592+
docker network ls
593+
echo "### DEBUG"
594+
444595
- name: Launch Docker Compose
445596
run: docker compose -f docker-compose.yaml -f docker-compose.override.yaml up -d
446597
working-directory: quickstart
@@ -523,6 +674,14 @@ jobs:
523674
524675
cat e2e/docker-compose.override.yaml
525676
677+
- name: Debug E2E runner state
678+
run: |
679+
echo "### DEBUG"
680+
ss -ltnp | grep ':39000 ' || true
681+
docker ps -a
682+
docker network ls
683+
echo "### DEBUG"
684+
526685
- name: Launch Docker Compose infra
527686
run: docker compose -f docker-compose.infra.yaml -f docker-compose.openmeter.yaml -f docker-compose.override.yaml up -d
528687
working-directory: e2e

e2e/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ env-local-down:
1818
$(call print-target)
1919
docker compose \
2020
-f docker-compose.infra.yaml \
21+
-f docker-compose.debug-ports.yaml \
2122
-f docker-compose.openmeter.yaml \
2223
-f docker-compose.openmeter-local.yaml \
2324
down
@@ -27,6 +28,7 @@ env-local-up:
2728
$(call print-target)
2829
docker compose \
2930
-f docker-compose.infra.yaml \
31+
-f docker-compose.debug-ports.yaml \
3032
-f docker-compose.openmeter.yaml \
3133
-f docker-compose.openmeter-local.yaml \
3234
up -d --build --force-recreate
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Optional host port exposure for local debugging.
2+
# CI does not need these infra services reachable from the host.
3+
services:
4+
kafka:
5+
ports:
6+
- "127.0.0.1:39092:29092"
7+
8+
clickhouse:
9+
ports:
10+
- "127.0.0.1:38123:8123"
11+
- "127.0.0.1:39000:9000"
12+
- "127.0.0.1:39009:9009"
13+
14+
redis:
15+
ports:
16+
- "127.0.0.1:36379:6379"
17+
18+
postgres:
19+
ports:
20+
- "127.0.0.1:35432:5432"

e2e/docker-compose.infra.yaml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,21 @@ services:
44
extends:
55
file: ../docker-compose.base.yaml
66
service: kafka
7-
ports:
8-
- "127.0.0.1:39092:29092"
97

108
clickhouse:
119
extends:
1210
file: ../docker-compose.base.yaml
1311
service: clickhouse
14-
ports:
15-
- "127.0.0.1:38123:8123"
16-
- "127.0.0.1:39000:9000"
17-
- "127.0.0.1:39009:9009"
1812

1913
redis:
2014
extends:
2115
file: ../docker-compose.base.yaml
2216
service: redis
23-
ports:
24-
- "127.0.0.1:36379:6379"
25-
2617

2718
postgres:
2819
extends:
2920
file: ../docker-compose.base.yaml
3021
service: postgres
31-
ports:
32-
- "127.0.0.1:35432:35432"
3322

3423
configs:
3524
svix_sql:

openmeter/subscription/addon/diff/apply_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ func TestApply(t *testing.T) {
3333

3434
// TODO: we could write purer tests here (without depending on the services) but this is simply more convenient for now
3535
runWithDeps := func(t *testing.T, fn func(t *testing.T, deps *tcDeps)) {
36-
clock.SetTime(now)
37-
defer clock.ResetTime()
36+
clock.FreezeTime(now.Add(time.Millisecond))
37+
defer func() {
38+
clock.UnFreeze()
39+
clock.ResetTime()
40+
}()
3841

3942
dbDeps := subscriptiontestutils.SetupDBDeps(t)
4043
defer dbDeps.Cleanup(t)
@@ -811,8 +814,11 @@ func TestApplyWithMultiInstance(t *testing.T) {
811814
}
812815

813816
runWithDeps := func(t *testing.T, fn func(t *testing.T, deps *tcDeps)) {
814-
clock.SetTime(now)
815-
defer clock.ResetTime()
817+
clock.FreezeTime(now.Add(time.Millisecond))
818+
defer func() {
819+
clock.UnFreeze()
820+
clock.ResetTime()
821+
}()
816822

817823
dbDeps := subscriptiontestutils.SetupDBDeps(t)
818824
defer dbDeps.Cleanup(t)

openmeter/subscription/addon/diff/restore_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ func TestRestore(t *testing.T) {
3030

3131
withDeps := func(fn func(t *testing.T, deps *tcDeps)) func(t *testing.T) {
3232
return func(t *testing.T) {
33-
clock.SetTime(now)
34-
defer clock.ResetTime()
33+
clock.FreezeTime(now.Add(time.Millisecond))
34+
defer func() {
35+
clock.UnFreeze()
36+
clock.ResetTime()
37+
}()
3538

3639
dbDeps := subscriptiontestutils.SetupDBDeps(t)
3740
defer dbDeps.Cleanup(t)
@@ -371,7 +374,7 @@ func TestRestore(t *testing.T) {
371374
}))
372375

373376
// Let's advance some time
374-
clock.SetTime(clock.Now().AddDate(0, 0, 1))
377+
clock.FreezeTime(clock.Now().AddDate(0, 0, 1))
375378

376379
// Let's make an edit to the sub effective at 1 month
377380
sView, err := deps.deps.WorkflowService.EditRunning(
@@ -647,7 +650,7 @@ func TestRestore(t *testing.T) {
647650

648651
for idx := range 8 {
649652
// Lets pass time
650-
clock.SetTime(clock.Now().Add(time.Minute))
653+
clock.FreezeTime(clock.Now().Add(time.Minute))
651654
diff, err := addondiff.GetDiffableFromAddon(subView, subsAdd)
652655
require.NoError(t, err, "failed to get diffable for iteration %d", idx)
653656

@@ -657,7 +660,7 @@ func TestRestore(t *testing.T) {
657660
err = spec.Apply(diff.GetRestores(), subscription.ApplyContext{CurrentTime: now})
658661
require.NoError(t, err, "failed to restore for iteration %d", idx)
659662

660-
clock.SetTime(clock.Now().Add(time.Minute))
663+
clock.FreezeTime(clock.Now().Add(time.Minute))
661664

662665
// Finally lets toggle the quantity
663666
sAdd, err := deps.deps.SubscriptionAddonService.ChangeQuantity(context.Background(), subsAdd.NamespacedID, subscriptionaddon.CreateSubscriptionAddonQuantityInput{

0 commit comments

Comments
 (0)