Skip to content

Commit 18f4fee

Browse files
committed
chore: refactor presubmits so they are easier to run locally
1 parent cf8082c commit 18f4fee

File tree

4 files changed

+77
-20
lines changed

4 files changed

+77
-20
lines changed

.github/workflows/main.yml

+5-20
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,9 @@ jobs:
1919

2020
- uses: actions/checkout@v2
2121

22-
- name: verify goimports
23-
run: |
24-
files=$(go run golang.org/x/tools/cmd/goimports -format-only -l .)
25-
# Sadly goimports doesn't use exit codes
26-
if [[ -n "${files}" ]]; then
27-
echo "::error ::goimports should be run on these files:"
28-
echo "${files}"
29-
exit 1
30-
fi
22+
- name: verify-goimports
23+
run: dev/ci/verify-goimports
24+
3125

3226
verify-gomod:
3327
runs-on: ubuntu-latest
@@ -40,17 +34,8 @@ jobs:
4034

4135
- uses: actions/checkout@v2
4236

43-
- run: dev/format-gomod
44-
45-
- run: |
46-
changes=$(git status --porcelain)
47-
if [[ -n "${changes}" ]]; then
48-
echo "::error Changes detected from dev/format-gomod:"
49-
echo "::error (You may need to run go clean -cache -modcache)"
50-
git diff | head -n60
51-
echo "${changes}"
52-
exit 1
53-
fi
37+
- name: verify-gomod
38+
run: dev/ci/presubmits/verify-gomod
5439

5540
kind-e2e:
5641
name: Test with a Kind cluster

dev/ci/presubmits/verify-goimports

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# CI script to keep all files formatted with goimporrts
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
# cd to the repo root
25+
REPO_ROOT=$(git rev-parse --show-toplevel)
26+
cd "${REPO_ROOT}"
27+
28+
files=$(go run golang.org/x/tools/cmd/goimports -format-only -l .)
29+
# Sadly goimports doesn't use exit codes
30+
if [[ -n "${files}" ]]; then
31+
echo "::error ::goimports should be run on these files:"
32+
echo "${files}"
33+
exit 1
34+
fi

dev/ci/presubmits/verify-gomod

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
# Copyright 2025 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
# CI script to keep all our go.mod/go.sum updated
19+
20+
set -o errexit
21+
set -o nounset
22+
set -o pipefail
23+
24+
# cd to the repo root
25+
REPO_ROOT=$(git rev-parse --show-toplevel)
26+
cd "${REPO_ROOT}"
27+
28+
dev/format-gomod
29+
30+
changes=$(git status --porcelain)
31+
if [[ -n "${changes}" ]]; then
32+
echo "::error Changes detected from dev/format-gomod:"
33+
echo "::error (You may need to run go clean -cache -modcache)"
34+
git diff | head -n60
35+
echo "${changes}"
36+
exit 1
37+
fi

dev/format-gomod

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ go version
3333
go work sync
3434

3535
# Pin mockkubeapiserver an older version of kube, so mockkubeapiserver can be used from repos that aren't on the latest kube
36+
echo "Forcing mockkubeapiserver client-go / apimachinery version to kube 0.26"
3637
cd ${REPO_ROOT}/mockkubeapiserver
3738
go get k8s.io/[email protected]
3839
go get k8s.io/[email protected]

0 commit comments

Comments
 (0)