Skip to content

Commit 7e015cf

Browse files
authored
Parallelize make targets for faster builds (#1257)
* Parallelize make targets for faster builds Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> * Add support for Mac Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> * Address copilot review comments Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> * Add go cache path to composite action Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> * Add golangci-lint cache Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech> --------- Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
1 parent b07a11b commit 7e015cf

5 files changed

Lines changed: 41 additions & 13 deletions

File tree

.github/workflows/after-push-to-branch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2022-2026 The kpt Authors
22
#
3-
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
54
# you may not use this file except in compliance with the License.
65
# You may obtain a copy of the License at
@@ -32,6 +31,7 @@ jobs:
3231
with:
3332
go-version-file: documentation/go.mod
3433
install-kpt: 'false'
34+
cache-dependency-path: functions/go/*/go.sum
3535
- uses: docker/setup-qemu-action@v4
3636
- uses: docker/setup-buildx-action@v4
3737
- name: Log in to GHCR

.github/workflows/after-tag-with-version.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
with:
3535
go-version-file: documentation/go.mod
3636
install-kpt: 'false'
37+
cache-dependency-path: functions/go/*/go.sum
3738

3839
- name: Setup QEMU
3940
uses: docker/setup-qemu-action@v4

.github/workflows/ci.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2026 The kpt Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
name: CI
216

317
on:
@@ -58,6 +72,7 @@ jobs:
5872
with:
5973
go-version-file: documentation/go.mod
6074
install-kpt: 'false'
75+
cache-dependency-path: functions/go/*/go.sum
6176
- name: Run unit tests
6277
run: |
6378
make unit-test
@@ -74,6 +89,13 @@ jobs:
7489
uses: kptdev/porch/.github/actions/setup-go-kpt@main
7590
with:
7691
go-version-file: functions/go/list-setters/go.mod
92+
cache-dependency-path: functions/go/*/go.sum
93+
- name: Cache golangci-lint
94+
uses: actions/cache@v5
95+
with:
96+
path: ~/.cache/golangci-lint
97+
key: golangci-lint-${{ hashFiles('functions/go/*/go.sum') }}
98+
restore-keys: golangci-lint-
7799
- name: Install kustomize
78100
uses: syntaqx/setup-kustomize@v1
79101
with:

Makefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
SHELL=/bin/bash
1515
export TAG ?= latest
1616
export DEFAULT_CR ?= ghcr.io/kptdev/krm-functions-catalog
17+
NPROC := $(shell nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1)
1718

1819

1920
.DEFAULT_GOAL := help
@@ -24,7 +25,7 @@ help: ## Print this help
2425
.PHONY: test unit-test e2e-test push
2526

2627
unit-test: ## Run unit tests for Go functions
27-
cd functions/go && $(MAKE) test
28+
cd functions/go && $(MAKE) test -j$(NPROC)
2829

2930
e2e-test: ## Run all e2e tests
3031
cd tests/e2etest && go test -v -run TestE2E ./...
@@ -42,14 +43,14 @@ tidy:
4243

4344
.PHONY: build
4445
build: ## Build all function images.
45-
cd functions/go && $(MAKE) build
46+
cd functions/go && $(MAKE) build -j$(NPROC)
4647

4748
.PHONY: format
4849
format: ## Run go fix, vet, fmt, lint and generate docs for all functions
49-
cd functions/go && $(MAKE) format
50+
cd functions/go && $(MAKE) format -j$(NPROC)
5051

5152
push: ## Push images to registry. WARN: This operation should only be done in CI environment.
52-
cd functions/go && $(MAKE) push
53+
cd functions/go && $(MAKE) push -j$(NPROC)
5354

5455
validate-metadata: ## Validate all metadata.yaml files against the schema
5556
cd scripts/generate_docs && go run . validate

functions/go/Makefile

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ $(FUNCTIONS):
7373
test: generate $(FUNCTION_TESTS) ## Run unit tests for all functions
7474

7575
.PHONY: $(FUNCTION_TESTS)
76-
$(FUNCTION_TESTS):
76+
$(FUNCTION_TESTS): | generate
7777
$(MAKE) CURRENT_FUNCTION=$(subst -TEST,,$@) func-test
7878

7979
generate: install-mdtogo generate-docs
@@ -82,21 +82,21 @@ generate: install-mdtogo generate-docs
8282
generate-docs: $(FUNCTION_GENERATE_DOCS) ## Generate docs for all functions
8383

8484
.PHONY: $(FUNCTION_GENERATE_DOCS)
85-
$(FUNCTION_GENERATE_DOCS):
85+
$(FUNCTION_GENERATE_DOCS): | install-mdtogo
8686
$(MAKE) CURRENT_FUNCTION=$(subst -GENERATE,,$@) docs-generate
8787

8888
.PHONY: build
8989
build: generate $(FUNCTION_BUILDS) ## Build all function images. 'TAG' env is used to specify tag. 'dev' will be used if not set.
9090

9191
.PHONY: $(FUNCTION_BUILDS)
92-
$(FUNCTION_BUILDS):
92+
$(FUNCTION_BUILDS): | generate install-golangci-lint
9393
$(MAKE) CURRENT_FUNCTION=$(subst -BUILD,,$@) TAG=$(TAG) DEFAULT_CR=$(DEFAULT_CR) func-build
9494

9595
.PHONY: format
9696
format: generate $(FUNCTION_FORMATS)
9797

9898
.PHONY: $(FUNCTION_FORMATS)
99-
$(FUNCTION_FORMATS):
99+
$(FUNCTION_FORMATS): | generate install-golangci-lint
100100
$(MAKE) CURRENT_FUNCTION=$(subst -FORMAT,,$@) TAG=$(TAG) DEFAULT_CR=$(DEFAULT_CR) func-format
101101

102102
.PHONY: push
@@ -106,6 +106,7 @@ push: $(FUNCTION_PUSH) ## Push images to registry. WARN: This operation should o
106106
$(FUNCTION_PUSH):
107107
$(MAKE) CURRENT_FUNCTION=$(subst -PUSH,,$@) TAG=$(TAG) DEFAULT_CR=$(DEFAULT_CR) func-push
108108

109+
.PHONY: install-mdtogo
109110
install-mdtogo:
110111
go install github.com/kptdev/kpt/mdtogo@main
111112

@@ -114,16 +115,19 @@ install-mdtogo:
114115
func-verify: func-format func-test
115116
func-format: docs-generate func-fix func-vet func-fmt func-lint
116117

118+
.PHONY: install-golangci-lint
119+
install-golangci-lint:
120+
(which $(GOPATH)/bin/golangci-lint || \
121+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(GOPATH)/bin latest)
122+
117123
func-fix:
118124
cd $(CURRENT_FUNCTION) && go fix -omitzero=false ./...
119125

120126
func-fmt:
121127
cd $(CURRENT_FUNCTION) && go fmt ./...
122128

123-
func-lint:
124-
(which $(GOPATH)/bin/golangci-lint || \
125-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/v2.11.4/install.sh | sh -s -- -b $(GOPATH)/bin v2.11.4)
126-
cd $(CURRENT_FUNCTION) && time $(GOPATH)/bin/golangci-lint run --fix --timeout=10m ./...
129+
func-lint: install-golangci-lint
130+
cd $(CURRENT_FUNCTION) && time $(GOPATH)/bin/golangci-lint run --allow-parallel-runners --fix --timeout=10m ./...
127131

128132
func-test:
129133
cd $(CURRENT_FUNCTION) && go test -cover ./...

0 commit comments

Comments
 (0)