Skip to content

Commit 596d322

Browse files
committed
Fix golangci-lint action step for large diff
1 parent a58f03d commit 596d322

File tree

8 files changed

+116
-25
lines changed

8 files changed

+116
-25
lines changed

.github/workflows/ci.yaml

Lines changed: 80 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,102 @@ permissions:
1919
checks: write # Used to annotate code in the PR
2020

2121
jobs:
22+
changes:
23+
name: categorize changes
24+
runs-on: ubuntu-latest
25+
outputs:
26+
non-docs: ${{ steps.detect.outputs.non-docs }}
27+
yaml: ${{ steps.detect.outputs.yaml }}
28+
steps:
29+
- name: Get base depth
30+
id: base-depth
31+
run: echo "base-depth=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_OUTPUT
32+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
33+
with:
34+
ref: ${{ github.event.pull_request.head.sha }}
35+
fetch-depth: ${{ steps.base-depth.outputs.base-depth }}
36+
- name: detect
37+
id: detect
38+
run: |
39+
git fetch origin ${{ github.base_ref }}
40+
41+
# Store git diff command for reuse
42+
GIT_DIFF_CMD="git diff --name-only ${{ github.event.pull_request.base.sha }}...${{ github.event.pull_request.head.sha }}"
43+
44+
# Disable pipefail to avoid SIGPIPE (exit 141) when commands like head/grep exit early
45+
# SIGPIPE occurs when git diff tries to write but the reading end of the pipe has closed
46+
set +o pipefail
47+
48+
# Show changed files for debugging (limit to first 50 for readability)
49+
echo "Changed files (first 50):"
50+
$GIT_DIFF_CMD | head -50
51+
FILE_COUNT=$($GIT_DIFF_CMD | wc -l)
52+
echo "Total files changed: $FILE_COUNT"
53+
54+
# If no files are changed at all, skip detection
55+
# Use git diff output directly to avoid bash variable size limits with large PRs
56+
if [[ $FILE_COUNT -gt 0 ]]; then
57+
# We only care about grep's exit status (did it find matches?), not the pipe status
58+
NON_DOCS=$($GIT_DIFF_CMD | grep -Ev '\.md$' > /dev/null && echo 'true' || echo 'false')
59+
YAML=$($GIT_DIFF_CMD | grep -E '\.ya?ml$' > /dev/null && echo 'true' || echo 'false')
60+
echo "non-docs=${NON_DOCS}" | tee -a $GITHUB_OUTPUT
61+
echo "yaml=${YAML}" | tee -a $GITHUB_OUTPUT
62+
fi
63+
64+
# Re-enable pipefail for subsequent commands
65+
set -o pipefail
66+
2267
build:
2368
name: build
69+
needs: [changes]
2470
runs-on: ubuntu-latest
71+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
2572
steps:
26-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
73+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
2774
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
2875
with:
2976
go-version-file: "go.mod"
77+
check-latest: true
78+
env:
79+
GOTOOLCHAIN: auto
3080
- name: build
3181
run: |
3282
go build -v ./...
3383
linting:
34-
needs: [build]
84+
needs: [changes]
3585
name: lint
3686
runs-on: ubuntu-latest
3787
steps:
38-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
88+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
89+
with:
90+
fetch-depth: 0
3991
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
4092
with:
4193
go-version-file: "go.mod"
94+
check-latest: true
95+
env:
96+
GOTOOLCHAIN: auto
4297
- name: gofmt
98+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
4399
run: |
44100
gofmt_out=$(gofmt -d $(find * -name '*.go' ! -path 'vendor/*' ! -path 'third_party/*'))
45101
if [[ -n "$gofmt_out" ]]; then
46102
failed=1
47103
fi
48104
echo "$gofmt_out"
49105
- name: golangci-lint
50-
uses: golangci/golangci-lint-action@e7fa5ac41e1cf5b7d48e45e42232ce7ada589601 # v9.1.0
106+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
107+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
51108
with:
52-
version: v2.1.0
53-
only-new-issues: true
54-
args: --timeout=10m
109+
version: v2.7.2
110+
args: --new-from-merge-base=origin/${{ github.base_ref }} --timeout=10m
55111
- name: yamllint
112+
if: ${{ needs.changes.outputs.yaml == 'true' }}
56113
run: |
57114
apt update && apt install -y yamllint
58115
yamllint -c .yamllint $(find . -path ./vendor -prune -o -type f -regex ".*y[a]ml" -print | tr '\n' ' ')
59116
- name: check-license
117+
if: ${{ needs.changes.outputs.non-docs == 'true' }}
60118
run: |
61119
go install github.com/google/go-licenses@v1.0.0
62120
go-licenses check ./...
@@ -65,10 +123,13 @@ jobs:
65123
name: test
66124
runs-on: ubuntu-latest
67125
steps:
68-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
126+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
69127
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
70128
with:
71129
go-version-file: "go.mod"
130+
check-latest: true
131+
env:
132+
GOTOOLCHAIN: auto
72133
- name: build
73134
run: |
74135
make test-unit-verbose-and-race
@@ -77,10 +138,13 @@ jobs:
77138
name: Check generated code
78139
runs-on: ubuntu-latest
79140
steps:
80-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
141+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
81142
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
82143
with:
83144
go-version-file: "go.mod"
145+
check-latest: true
146+
env:
147+
GOTOOLCHAIN: auto
84148
- name: generated
85149
run: |
86150
./hack/verify-codegen.sh
@@ -89,10 +153,13 @@ jobs:
89153
name: Multi-arch build
90154
runs-on: ubuntu-latest
91155
steps:
92-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
156+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
93157
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
94158
with:
95159
go-version-file: "go.mod"
160+
check-latest: true
161+
env:
162+
GOTOOLCHAIN: auto
96163
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
97164
- name: ko-resolve
98165
run: |
@@ -104,8 +171,9 @@ jobs:
104171
github.com/tektoncd/operator/cmd/openshift/proxy-webhook: registry.access.redhat.com/ubi9/ubi-minimal
105172
EOF
106173
107-
KO_DOCKER_REPO=example.com make TARGET=kubernetes resolve
108-
KO_DOCKER_REPO=example.com make TARGET=openshift resolve
174+
# Use ko from setup-ko action to avoid Go version mismatch
175+
KO_BIN=$(which ko) KO_DOCKER_REPO=example.com make TARGET=kubernetes resolve
176+
KO_BIN=$(which ko) KO_DOCKER_REPO=example.com make TARGET=openshift resolve
109177
e2e-tests:
110178
needs: [build]
111179
uses: ./.github/workflows/e2e-matrix.yml

.github/workflows/e2e-matrix.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Tekton Integration
22
# Adapted from https://github.com/mattmoor/mink/blob/master/.github/workflows/minkind.yaml
33

4-
on: [workflow_call] # yamllint disable-line rule:truthy
4+
on:
5+
- workflow_call
56

67
defaults:
78
run:
@@ -19,23 +20,26 @@ jobs:
1920
matrix:
2021
k8s-name:
2122
- k8s-oldest
22-
- k8s-plus-one
23+
- k8s-latest
2324

2425
include:
2526
- k8s-name: k8s-oldest
2627
k8s-version: v1.28.x
27-
- k8s-name: k8s-plus-one
28-
k8s-version: v1.29.x
28+
- k8s-name: k8s-latest
29+
k8s-version: v1.34.x
2930
env:
3031
KO_DOCKER_REPO: registry.local:5000/tekton
3132
CLUSTER_DOMAIN: c${{ github.run_id }}.local
3233
ARTIFACTS: ${{ github.workspace }}/artifacts
3334

3435
steps:
35-
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
36+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
3637
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
3738
with:
3839
go-version-file: "go.mod"
40+
check-latest: true
41+
env:
42+
GOTOOLCHAIN: auto
3943
- uses: ko-build/setup-ko@d006021bd0c28d1ce33a07e7943d48b079944c8d # v0.9
4044

4145
- name: Install Dependencies
@@ -62,12 +66,12 @@ jobs:
6266
--e2e-env ./test/e2e-tests-kind.env
6367
6468
- name: Upload test results
65-
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
69+
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
6670
with:
6771
name: ${{ matrix.k8s-version }}-${{ matrix.feature-flags }}
6872
path: ${{ env.ARTIFACTS }}
6973

70-
- uses: chainguard-dev/actions/kind-diag@3e8a2a226fad9e1ecbf2d359b8a7697554a4ac6d # v1.5.10
74+
- uses: chainguard-dev/actions/kind-diag@7d647f470c4d3692286221bd17ca78206976a61c # v1.5.11
7175
if: ${{ failure() }}
7276
with:
7377
artifact-name: ${{ matrix.k8s-version }}-${{ matrix.feature-flags }}-logs

.github/workflows/golangci-lint.yaml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,23 @@ permissions:
99
contents: read
1010
checks: write # Used to annotate code in the PR
1111

12+
env:
13+
GOTOOLCHAIN: auto
14+
1215
jobs:
1316
golangci:
1417
name: lint
1518
runs-on: ubuntu-latest
1619
steps:
17-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
18-
- uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
20+
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
21+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
1922
with:
20-
go-version: "1.23.x"
23+
go-version-file: "go.mod"
24+
check-latest: true
25+
env:
26+
GOTOOLCHAIN: auto
2127
- name: golangci-lint
22-
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
28+
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v6.2.0
2329
with:
24-
version: v2.0.1
25-
args: --timeout=10m
30+
version: v2.7.2
31+
args: --timeout=10m --new-from-merge-base=origin/${{ github.base_ref }}

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Q = $(if $(filter 1,$V),,@)
2121
M = $(shell printf "\033[34;1m🐱\033[0m")
2222

2323
export GO111MODULE=on
24+
# Force GOTOOLCHAIN to auto to allow downloading Go 1.25+
25+
export GOTOOLCHAIN = auto
2426

2527
$(BIN):
2628
@mkdir -p $@

hack/fetch-releases.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
set -u -e
44

5+
# Ensure GOTOOLCHAIN is set to auto to allow Go 1.25+ to be downloaded
6+
export GOTOOLCHAIN="${GOTOOLCHAIN:-auto}"
7+
58
declare -r SCRIPT_DIR=$(cd $(dirname "$0")/.. && pwd)
69
TARGET=""
710
FORCE_FETCH_RELEASE=""

hack/setup-kind.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ set -o nounset
2222
set -o pipefail
2323
set -x
2424

25+
# Ensure GOTOOLCHAIN is set to auto to allow Go 1.25+ to be downloaded
26+
export GOTOOLCHAIN=auto
27+
2528
# Print error message and exit 1
2629
# Parameters: $1..$n - error message to be displayed
2730
function abort() {

test/e2e-common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ function install_operator_resources() {
4141

4242
echo ">> Deploying Tekton Operator Resources"
4343

44+
# Ensure GOTOOLCHAIN is set to auto before running make
45+
export GOTOOLCHAIN=auto
4446
make KO_BIN=$(which ko) KUSTOMIZE_BIN=$(which kustomize) TARGET=${TARGET:-kubernetes} apply || fail_test "Tekton Operator installation failed"
4547

4648
# Wait for pods to be running in the namespaces we are deploying to

test/e2e-tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
# and deploy Tekton Pipelines to it for running integration tests.
1919
set -e
2020

21+
# Ensure GOTOOLCHAIN is set to auto to allow Go 1.25+ to be downloaded
22+
export GOTOOLCHAIN="${GOTOOLCHAIN:-auto}"
23+
2124
source $(dirname $0)/e2e-common.sh
2225

2326
# Script entry point.

0 commit comments

Comments
 (0)