Skip to content

Commit 0c1ad9b

Browse files
authored
Parallelize the tests a bit more (slackhq#1730)
1 parent 074a123 commit 0c1ad9b

3 files changed

Lines changed: 127 additions & 102 deletions

File tree

.github/workflows/gofmt.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ on:
1313
- 'go.sum'
1414
jobs:
1515

16-
test-linux:
17-
name: Build all and test on ubuntu-linux
16+
static:
17+
name: Static checks
1818
runs-on: ubuntu-latest
1919
steps:
2020

@@ -25,8 +25,16 @@ jobs:
2525
go-version: '1.25'
2626
check-latest: true
2727

28-
- name: Build
29-
run: make all
28+
- name: Install goimports
29+
run: go install golang.org/x/tools/cmd/goimports@latest
30+
31+
- name: gofmt
32+
run: |
33+
if [ "$(find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -l)" ]
34+
then
35+
find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -d
36+
exit 1
37+
fi
3038
3139
- name: Vet
3240
run: make vet
@@ -36,24 +44,38 @@ jobs:
3644
with:
3745
version: v2.5
3846

39-
- name: Test
40-
run: make test
41-
42-
- name: End 2 end
43-
run: make e2evv
44-
45-
- name: Build test mobile
46-
run: make build-test-mobile
47-
48-
- uses: actions/upload-artifact@v7
49-
with:
50-
name: e2e packet flow linux-latest
51-
path: e2e/mermaid/linux-latest
52-
if-no-files-found: warn
53-
54-
test-linux-boringcrypto:
55-
name: Build and test on linux with boringcrypto
56-
runs-on: ubuntu-latest
47+
test:
48+
name: Test ${{ matrix.name }}
49+
runs-on: ${{ matrix.os }}
50+
strategy:
51+
fail-fast: false
52+
matrix:
53+
include:
54+
- name: linux
55+
os: ubuntu-latest
56+
build-cmd: go build ./cmd/nebula ./cmd/nebula-cert
57+
test-cmd: make test
58+
e2e-cmd: make e2evv
59+
- name: linux-boringcrypto
60+
os: ubuntu-latest
61+
build-cmd: make bin-boringcrypto
62+
test-cmd: make test-boringcrypto
63+
e2e-cmd: make e2e GOEXPERIMENT=boringcrypto CGO_ENABLED=1 TEST_ENV="TEST_LOGS=1" TEST_FLAGS="-v -ldflags -checklinkname=0"
64+
- name: linux-pkcs11
65+
os: ubuntu-latest
66+
build-cmd: make bin-pkcs11
67+
test-cmd: make test-pkcs11
68+
e2e-cmd: ''
69+
- name: macos
70+
os: macos-latest
71+
build-cmd: go build ./cmd/nebula ./cmd/nebula-cert
72+
test-cmd: make test
73+
e2e-cmd: make e2evv
74+
- name: windows
75+
os: windows-latest
76+
build-cmd: go build ./cmd/nebula ./cmd/nebula-cert
77+
test-cmd: make test
78+
e2e-cmd: make e2evv
5779
steps:
5880

5981
- uses: actions/checkout@v6
@@ -64,38 +86,41 @@ jobs:
6486
check-latest: true
6587

6688
- name: Build
67-
run: make bin-boringcrypto
89+
run: ${{ matrix.build-cmd }}
90+
91+
- name: Cross-build darwin-amd64
92+
if: matrix.name == 'macos'
93+
run: GOARCH=amd64 go build -o /tmp/nebula-amd64 ./cmd/nebula && GOARCH=amd64 go build -o /tmp/nebula-cert-amd64 ./cmd/nebula-cert
6894

6995
- name: Test
70-
run: make test-boringcrypto
96+
run: ${{ matrix.test-cmd }}
7197

7298
- name: End 2 end
73-
run: make e2e GOEXPERIMENT=boringcrypto CGO_ENABLED=1 TEST_ENV="TEST_LOGS=1" TEST_FLAGS="-v -ldflags -checklinkname=0"
74-
75-
test-linux-pkcs11:
76-
name: Build and test on linux with pkcs11
77-
runs-on: ubuntu-latest
78-
steps:
79-
80-
- uses: actions/checkout@v6
99+
if: matrix.e2e-cmd != ''
100+
run: ${{ matrix.e2e-cmd }}
81101

82-
- uses: actions/setup-go@v6
102+
- uses: actions/upload-artifact@v7
103+
if: matrix.e2e-cmd != '' && always()
83104
with:
84-
go-version: '1.25'
85-
check-latest: true
86-
87-
- name: Build
88-
run: make bin-pkcs11
89-
90-
- name: Test
91-
run: make test-pkcs11
105+
name: e2e packet flow ${{ matrix.name }}
106+
path: e2e/mermaid/
107+
if-no-files-found: warn
92108

93-
test:
94-
name: Build and test on ${{ matrix.os }}
95-
runs-on: ${{ matrix.os }}
109+
cross-build:
110+
name: Cross-build ${{ matrix.name }}
111+
runs-on: ubuntu-latest
96112
strategy:
113+
fail-fast: false
97114
matrix:
98-
os: [windows-latest, macos-latest]
115+
include:
116+
- {name: linux-arm, make-target: all-cross-linux-arm}
117+
- {name: linux-mips, make-target: all-cross-linux-mips}
118+
- {name: linux-other, make-target: all-cross-linux-other}
119+
- {name: freebsd, make-target: all-freebsd}
120+
- {name: openbsd, make-target: all-openbsd}
121+
- {name: netbsd, make-target: all-netbsd}
122+
- {name: windows, make-target: all-cross-windows}
123+
- {name: mobile, make-target: build-test-mobile}
99124
steps:
100125

101126
- uses: actions/checkout@v6
@@ -105,28 +130,21 @@ jobs:
105130
go-version: '1.25'
106131
check-latest: true
107132

108-
- name: Build nebula
109-
run: go build ./cmd/nebula
110-
111-
- name: Build nebula-cert
112-
run: go build ./cmd/nebula-cert
113-
114-
- name: Vet
115-
run: make vet
133+
- name: Build ${{ matrix.name }}
134+
run: make -j"$(nproc)" ${{ matrix.make-target }}
116135

117-
- name: golangci-lint
118-
uses: golangci/golangci-lint-action@v9
119-
with:
120-
version: v2.5
121-
122-
- name: Test
123-
run: make test
136+
finish:
137+
name: CI status
138+
if: always()
139+
needs: [static, test, cross-build]
140+
runs-on: ubuntu-latest
141+
steps:
124142

125-
- name: End 2 end
126-
run: make e2evv
143+
- name: Fail if any upstream job failed
144+
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
145+
run: |
146+
echo "upstream results: ${{ toJSON(needs) }}"
147+
exit 1
127148
128-
- uses: actions/upload-artifact@v7
129-
with:
130-
name: e2e packet flow ${{ matrix.os }}
131-
path: e2e/mermaid/${{ matrix.os }}
132-
if-no-files-found: warn
149+
- name: All upstream jobs passed
150+
run: echo "ok"

Makefile

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ ALL = $(ALL_LINUX) \
6060
windows-amd64 \
6161
windows-arm64
6262

63+
# Cross-build shards used by .github/workflows/test.yml — same as ALL_*
64+
# but with the arch that has a native CI runner removed, so the cross-build
65+
# job is not duplicating coverage the native test jobs already give.
66+
ALL_CROSS_LINUX = $(filter-out linux-amd64,$(ALL_LINUX))
67+
68+
# ALL_CROSS_LINUX further split into family sub-shards so each can run on
69+
# its own CI runner in parallel. Union of the three must equal
70+
# ALL_CROSS_LINUX; adding a new linux arch goes into the matching family.
71+
ALL_CROSS_LINUX_ARM = linux-arm-5 linux-arm-6 linux-arm-7 linux-arm64
72+
ALL_CROSS_LINUX_MIPS = linux-mips linux-mipsle linux-mips64 linux-mips64le linux-mips-softfloat
73+
ALL_CROSS_LINUX_OTHER = linux-386 linux-ppc64le linux-riscv64 linux-loong64
74+
6375
e2e:
6476
$(TEST_ENV) go test -tags=e2e_testing -count=1 $(TEST_FLAGS) ./e2e
6577

@@ -82,6 +94,35 @@ DOCKER_BIN = build/linux-amd64/nebula build/linux-amd64/nebula-cert
8294

8395
all: $(ALL:%=build/%/nebula) $(ALL:%=build/%/nebula-cert)
8496

97+
all-linux: $(ALL_LINUX:%=build/%/nebula) $(ALL_LINUX:%=build/%/nebula-cert)
98+
99+
all-freebsd: $(ALL_FREEBSD:%=build/%/nebula) $(ALL_FREEBSD:%=build/%/nebula-cert)
100+
101+
all-openbsd: $(ALL_OPENBSD:%=build/%/nebula) $(ALL_OPENBSD:%=build/%/nebula-cert)
102+
103+
all-netbsd: $(ALL_NETBSD:%=build/%/nebula) $(ALL_NETBSD:%=build/%/nebula-cert)
104+
105+
all-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert build/darwin-arm64/nebula build/darwin-arm64/nebula-cert
106+
107+
all-windows: build/windows-amd64/nebula.exe build/windows-amd64/nebula-cert.exe build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
108+
109+
# CI cross-build shards. darwin-arm64 is covered by the native macos-latest
110+
# job; windows-amd64 is covered by the native windows-latest job; both are
111+
# omitted here to avoid building them a second time. darwin-amd64 stays in
112+
# all-cross-darwin because intel mac is only a labeled/master-time native
113+
# job, so PRs still need cross-build coverage for it.
114+
all-cross-linux: $(ALL_CROSS_LINUX:%=build/%/nebula) $(ALL_CROSS_LINUX:%=build/%/nebula-cert)
115+
116+
all-cross-linux-arm: $(ALL_CROSS_LINUX_ARM:%=build/%/nebula) $(ALL_CROSS_LINUX_ARM:%=build/%/nebula-cert)
117+
118+
all-cross-linux-mips: $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula) $(ALL_CROSS_LINUX_MIPS:%=build/%/nebula-cert)
119+
120+
all-cross-linux-other: $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula) $(ALL_CROSS_LINUX_OTHER:%=build/%/nebula-cert)
121+
122+
all-cross-darwin: build/darwin-amd64/nebula build/darwin-amd64/nebula-cert
123+
124+
all-cross-windows: build/windows-arm64/nebula.exe build/windows-arm64/nebula-cert.exe
125+
85126
docker: docker/linux-$(shell go env GOARCH)
86127

87128
release: $(ALL:%=build/nebula-%.tar.gz)
@@ -236,5 +277,5 @@ smoke-vagrant/%: bin-docker build/%/nebula
236277
cd .github/workflows/smoke/ && ./smoke-vagrant.sh $*
237278

238279
.FORCE:
239-
.PHONY: bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html smoke-vagrant/%
280+
.PHONY: all all-linux all-freebsd all-openbsd all-netbsd all-darwin all-windows all-cross-linux all-cross-linux-arm all-cross-linux-mips all-cross-linux-other all-cross-darwin all-cross-windows bench bench-cpu bench-cpu-long bin build-test-mobile e2e e2ev e2evv e2evvv e2evvvv proto release service smoke-docker smoke-docker-race test test-cov-html smoke-vagrant/%
240281
.DEFAULT_GOAL := bin

0 commit comments

Comments
 (0)