Skip to content

Commit 8be8970

Browse files
committed
CI: parallelizing tests
1 parent 77b3446 commit 8be8970

File tree

3 files changed

+74
-47
lines changed

3 files changed

+74
-47
lines changed

.github/workflows/go.yml

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ name: Go
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
permissions:
1010
contents: read
1111

1212
jobs:
13+
## TODO: conditional-changes checker is not working
1314
conditional-changes:
1415
runs-on: ubuntu-latest
1516
permissions:
@@ -27,7 +28,7 @@ jobs:
2728
2829
check-modules:
2930
name: check-synced-go-modules
30-
needs: conditional-changes
31+
# needs: conditional-changes
3132
# if: needs.conditional-changes.outputs.doc == 'false'
3233
runs-on: [ubuntu-latest]
3334
steps:
@@ -39,6 +40,9 @@ jobs:
3940
uses: actions/setup-go@v6
4041
with:
4142
go-version-file: go.work
43+
cache: true
44+
cache-dependency-path: |
45+
**/go.sum
4246
id: go
4347
- name: sync go modules
4448
run: make workspace-sync
@@ -47,7 +51,7 @@ jobs:
4751

4852
lint:
4953
name: Lint
50-
needs: conditional-changes
54+
# needs: conditional-changes
5155
# if: needs.conditional-changes.outputs.doc == 'false'
5256
runs-on: [ubuntu-latest]
5357
steps:
@@ -59,15 +63,19 @@ jobs:
5963
uses: actions/setup-go@v6
6064
with:
6165
go-version-file: go.work
66+
cache: true
67+
cache-dependency-path: |
68+
**/go.sum
6269
id: go
6370
- name: Lint
6471
run: make lint
6572
- name: Verify boilerplate
6673
run: make check-license
6774

68-
test-linux:
75+
## Test all modules without plugins and released modules
76+
test-non-released-modules:
6977
name: Test Linux
70-
needs: conditional-changes
78+
# needs: conditional-changes
7179
# if: needs.conditional-changes.outputs.doc == 'false'
7280
runs-on: [ubuntu-latest]
7381
steps:
@@ -77,54 +85,59 @@ jobs:
7785
uses: actions/setup-go@v6
7886
with:
7987
go-version-file: go.work
88+
cache: true
89+
cache-dependency-path: |
90+
**/go.sum
8091
id: go
81-
- name: Test all modules
82-
run: make test-unit-non-plugin
92+
- name: Test all modules without plugins and released modules
93+
run: make test-unit-non-plugin-and-non-released
8394
env:
8495
KUSTOMIZE_DOCKER_E2E: true
8596

86-
test-macos:
87-
name: Test MacOS
88-
needs: conditional-changes
97+
test-modules:
98+
name: Test ${{ matrix.os }} - ${{ matrix.module }}
99+
# needs: conditional-changes
89100
# if: needs.conditional-changes.outputs.doc == 'false'
90-
runs-on: [macos-latest]
101+
runs-on: ${{ matrix.os }}
102+
strategy:
103+
fail-fast: false
104+
matrix:
105+
os: [ubuntu-latest, macos-latest, windows-latest]
106+
module:
107+
- kyaml
108+
- cmd/config
109+
- api
110+
- kustomize
111+
include:
112+
- module: kyaml
113+
test-cmd: go test -race -v -cover ./...
114+
- module: cmd/config
115+
test-cmd: go test -v -cover ./...
116+
- module: api
117+
test-cmd: go test -v -cover ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-01-31T23:38:41Z -X sigs.k8s.io/kustomize/api/provenance.version=(test)"
118+
- module: kustomize
119+
test-cmd: go test -v -cover ./...
120+
- os: ubuntu-latest
121+
docker-e2e: true
122+
- os: macos-latest
123+
docker-e2e: false
124+
- os: windows-latest
125+
docker-e2e: false
126+
env:
127+
KUSTOMIZE_DOCKER_E2E: ${{ matrix.docker-e2e }}
91128
steps:
92129
- name: Check out code into the Go module directory
93130
uses: actions/checkout@v5
94131
- name: Set up Go 1.x
95132
uses: actions/setup-go@v6
96133
with:
97134
go-version-file: go.work
135+
cache: true
136+
cache-dependency-path: |
137+
**/go.sum
98138
id: go
99-
- name: Test all modules
100-
run: make test-unit-non-plugin
101-
env:
102-
KUSTOMIZE_DOCKER_E2E: false # docker not installed on mac
103-
104-
test-windows:
105-
name: Test Windows
106-
needs: conditional-changes
107-
# if: needs.conditional-changes.outputs.doc == 'false'
108-
runs-on: [windows-latest]
109-
steps:
110-
- name: Check out code into the Go module directory
111-
uses: actions/checkout@v5
112-
- name: Set up Go 1.x
113-
uses: actions/setup-go@v6
114-
with:
115-
go-version-file: go.work
116-
id: go
117-
- name: Test kyaml
118-
run: go test -cover ./...
119-
working-directory: ./kyaml
120-
- name: Test cmd/config
121-
run: go test -cover ./...
122-
working-directory: ./cmd/config
123-
env:
124-
KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
125-
126-
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
127-
#- name: Test all modules
128-
# run: make test-unit-non-plugin
129-
# env:
130-
# KUSTOMIZE_DOCKER_E2E: false # docker on windows not working well yet
139+
- name: Test ${{ matrix.module }}
140+
run: ${{ matrix.test-cmd }}
141+
# TODO (#4001): replace specific modules above with this once Windows tests are passing.
142+
if: ${{ !(matrix.os == 'windows-latest' && (matrix.module == 'api' || matrix.module == 'kustomize')) }}
143+
working-directory: ./${{ matrix.module }}

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,15 @@ test-unit-all: \
136136
test-unit-non-plugin \
137137
test-unit-kustomize-plugins
138138

139-
# This target is used by our Github Actions CI to run unit tests for all non-plugin modules in multiple GOOS environments.
140139
.PHONY: test-unit-non-plugin
141140
test-unit-non-plugin:
142141
./hack/for-each-module.sh "make test" "./plugin/*" 20
143142

143+
# This target is used by our Github Actions CI to run unit tests for all non-plugin and non-released modules in multiple GOOS environments.
144+
.PHONY: test-unit-non-plugin-and-non-released
145+
test-unit-non-plugin-and-non-released:
146+
./hack/for-each-module.sh "make test" "./plugin/*|./kyaml/go.mod|./cmd/config/go.mod|./api/go.mod|./kustomize/go.mod" 16
147+
144148
.PHONY: build-non-plugin-all
145149
build-non-plugin-all:
146150
./hack/for-each-module.sh "make build" "./plugin/*" 20
@@ -183,7 +187,7 @@ test-examples-kustomize-against-latest-release: $(MYGOBIN)/mdrip
183187
workspace-sync:
184188
go work sync
185189
./hack/doGoMod.sh tidy
186-
190+
187191
# --- Cleanup targets ---
188192
.PHONY: clean
189193
clean: clean-kustomize-external-go-plugin uninstall-tools

hack/for-each-module.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,18 @@ seen=()
2222
KUSTOMIZE_ROOT=$(pwd)
2323
export KUSTOMIZE_ROOT
2424

25+
# Build find command with multiple -not -path options
26+
find_cmd="find . -name go.mod -not -path \"./site/*\""
27+
if [[ -n "$skip_pattern" ]]; then
28+
# Split skip_pattern by | and add -not -path for each
29+
IFS='|' read -ra PATTERNS <<< "$skip_pattern"
30+
for pattern in "${PATTERNS[@]}"; do
31+
find_cmd+=" -not -path \"$pattern\""
32+
done
33+
fi
34+
2535
# verify all modules pass validation
26-
for i in $(find . -name go.mod -not -path "./site/*" -not -path "$skip_pattern"); do
36+
for i in $(eval "$find_cmd"); do
2737
pushd .
2838
cd $(dirname "$i");
2939

0 commit comments

Comments
 (0)