From aeb1c57298db85048b169bb476112ac114ef067f Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 10:12:27 +0100 Subject: [PATCH 1/6] ci: fix go version to that defined in go.mod --- .github/workflows/release.yml | 4 ++-- .github/workflows/test.yml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6b823b..5b01c40 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.24.2" id: go - name: Check out code into the Go module directory @@ -80,7 +80,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: '1.22' + go-version: "1.24.2" - name: Import GPG key id: import_gpg diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8b27f78..4c36c63 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.24.2" id: go - name: Check out code into the Go module directory @@ -95,7 +95,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.24.2" id: go - uses: hashicorp/setup-terraform@v3 @@ -125,7 +125,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: - go-version: "1.22" + go-version: "1.24.2" id: go - uses: hashicorp/setup-terraform@v3 From 7de5dd6c31b3324e5d5314498ae29a960cf5ce16 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 10:30:42 +0100 Subject: [PATCH 2/6] ci: add check for Go version consistency --- .github/workflows/release.yml | 6 ++++++ .github/workflows/test.yml | 6 ++++++ scripts/check_go_version.sh | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100755 scripts/check_go_version.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5b01c40..5c4a213 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,9 @@ jobs: name: Run Integration Tests runs-on: ubuntu-latest steps: + - name: Check Go Versions + run: ./scripts/check_go_version.sh + - name: Set up Go uses: actions/setup-go@v5 with: @@ -77,6 +80,9 @@ jobs: - name: Unshallow run: git fetch --prune --unshallow + - name: Check Go Versions + run: ./scripts/check_go_version.sh + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c36c63..b2eaae8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: + - name: Check Go Versions + run: ./scripts/check_go_version.sh + - name: Set up Go uses: actions/setup-go@v5 with: @@ -122,6 +125,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: + - name: Check Go Versions + run: ./scripts/check_go_version.sh + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/scripts/check_go_version.sh b/scripts/check_go_version.sh new file mode 100755 index 0000000..ed617e6 --- /dev/null +++ b/scripts/check_go_version.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -euo pipefail + +MOD_VERSION=$(go mod edit -json | jq -r .Go) +echo "go.mod version: $MOD_VERSION" + +for wf in .github/workflows/*.yml; do + echo "Checking $wf ..." + + WF_VERSIONS=$(yq -r '.jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv "$wf" | grep -v '^---$' || true) + if [ -z "$WF_VERSIONS" ]; then + echo "ℹ️ No go-version found in $wf (skipped)" + continue + fi + + UNIQUE_WF_VERSIONS=$(echo "$WF_VERSIONS" | sort -u) + if [ "$(echo "$UNIQUE_WF_VERSIONS" | wc -l)" -ne 1 ]; then + echo "❌ Multiple Go versions found in $wf:" + echo "$UNIQUE_WF_VERSIONS" + exit 1 + fi + + # At this point there's only one unique Go version + if [ "$UNIQUE_WF_VERSIONS" != "$MOD_VERSION" ]; then + echo "❌ Mismatch in $wf: go.mod=$MOD_VERSION but workflow uses $UNIQUE_WF_VERSIONS" + exit 1 + fi + + echo "✅ $wf matches go.mod ($MOD_VERSION)" +done + +echo "✅ All workflows consistent with go.mod ($MOD_VERSION)" \ No newline at end of file From 6f452cdf4e849b54850584dd68ea8f460931bdc4 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 10:38:10 +0100 Subject: [PATCH 3/6] fixup! ci: add check for Go version consistency --- .github/workflows/release.yml | 12 ++++++------ .github/workflows/test.yml | 21 ++++++++++++--------- scripts/check_go_version.sh | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5c4a213..4dccabd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,6 +19,9 @@ jobs: name: Run Integration Tests runs-on: ubuntu-latest steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v5 + - name: Check Go Versions run: ./scripts/check_go_version.sh @@ -28,9 +31,6 @@ jobs: go-version: "1.24.2" id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download @@ -77,12 +77,12 @@ jobs: - name: Checkout uses: actions/checkout@v5 - - name: Unshallow - run: git fetch --prune --unshallow - - name: Check Go Versions run: ./scripts/check_go_version.sh + - name: Unshallow + run: git fetch --prune --unshallow + - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b2eaae8..14c4ec6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v5 + - name: Check Go Versions run: ./scripts/check_go_version.sh @@ -28,9 +31,6 @@ jobs: go-version: "1.24.2" id: go - - name: Check out code into the Go module directory - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download @@ -95,6 +95,12 @@ jobs: - "1.10.*" - "1.11.*" steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v5 + + - name: Check Go Versions + run: ./scripts/check_go_version.sh + - name: Set up Go uses: actions/setup-go@v5 with: @@ -106,9 +112,6 @@ jobs: terraform_version: ${{ matrix.terraform }} terraform_wrapper: false - - name: Check out code into the Go module directory - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download @@ -125,6 +128,9 @@ jobs: runs-on: ubuntu-latest timeout-minutes: 5 steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v5 + - name: Check Go Versions run: ./scripts/check_go_version.sh @@ -139,9 +145,6 @@ jobs: terraform_version: "latest" terraform_wrapper: false - - name: Check out code into the Go module directory - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download diff --git a/scripts/check_go_version.sh b/scripts/check_go_version.sh index ed617e6..bea7377 100755 --- a/scripts/check_go_version.sh +++ b/scripts/check_go_version.sh @@ -29,4 +29,4 @@ for wf in .github/workflows/*.yml; do echo "✅ $wf matches go.mod ($MOD_VERSION)" done -echo "✅ All workflows consistent with go.mod ($MOD_VERSION)" \ No newline at end of file +echo "✅ All workflows consistent with go.mod ($MOD_VERSION)" From 759a03e53cf42c4d61721c8d6ea671a989edb261 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 11:16:07 +0100 Subject: [PATCH 4/6] PR comments --- scripts/check_go_version.sh | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/scripts/check_go_version.sh b/scripts/check_go_version.sh index bea7377..31e789e 100755 --- a/scripts/check_go_version.sh +++ b/scripts/check_go_version.sh @@ -3,30 +3,22 @@ set -euo pipefail MOD_VERSION=$(go mod edit -json | jq -r .Go) echo "go.mod version: $MOD_VERSION" +STATUS=0 for wf in .github/workflows/*.yml; do - echo "Checking $wf ..." - WF_VERSIONS=$(yq -r '.jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv "$wf" | grep -v '^---$' || true) - if [ -z "$WF_VERSIONS" ]; then - echo "ℹ️ No go-version found in $wf (skipped)" + if [[ -z "$WF_VERSIONS" ]]; then continue fi UNIQUE_WF_VERSIONS=$(echo "$WF_VERSIONS" | sort -u) - if [ "$(echo "$UNIQUE_WF_VERSIONS" | wc -l)" -ne 1 ]; then - echo "❌ Multiple Go versions found in $wf:" - echo "$UNIQUE_WF_VERSIONS" - exit 1 - fi - - # At this point there's only one unique Go version - if [ "$UNIQUE_WF_VERSIONS" != "$MOD_VERSION" ]; then - echo "❌ Mismatch in $wf: go.mod=$MOD_VERSION but workflow uses $UNIQUE_WF_VERSIONS" - exit 1 - fi - - echo "✅ $wf matches go.mod ($MOD_VERSION)" + for ver in $UNIQUE_WF_VERSIONS; do + if [[ "${ver}" != "$MOD_VERSION" ]]; then + STATUS=1 + echo "❌ $wf: go.mod=$MOD_VERSION but workflow uses $(tr '\n' ' ' <<<"$UNIQUE_WF_VERSIONS")" + continue + fi + done done -echo "✅ All workflows consistent with go.mod ($MOD_VERSION)" +exit $STATUS From bfceb4cf7de3e805a06d3485d20cf119f3b9fbbc Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 11:50:36 +0100 Subject: [PATCH 5/6] add --fix --- scripts/check_go_version.sh | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/scripts/check_go_version.sh b/scripts/check_go_version.sh index 31e789e..358e061 100755 --- a/scripts/check_go_version.sh +++ b/scripts/check_go_version.sh @@ -1,11 +1,37 @@ #!/usr/bin/env bash set -euo pipefail +fix=0 +args="$(getopt -o "" -l fix -- "$@")" +eval set -- "$args" +while true; do + case "$1" in + --fix) + fix=1 + shift + ;; + --) + shift + break + ;; + *) + error "Unrecognized option: $1" + ;; + esac +done + MOD_VERSION=$(go mod edit -json | jq -r .Go) echo "go.mod version: $MOD_VERSION" STATUS=0 -for wf in .github/workflows/*.yml; do +if [[ $fix -eq 1 ]]; then + for wf in .github/workflows/*.{yml,yaml}; do + sed -i "s/go-version:.*/go-version: \"${MOD_VERSION}\"/g" "${wf}" + done + exit $STATUS +fi + +for wf in .github/workflows/*.{yml,yaml}; do WF_VERSIONS=$(yq -r '.jobs[].steps[] | select(.with["go-version"]) | .with["go-version"]' -o=tsv "$wf" | grep -v '^---$' || true) if [[ -z "$WF_VERSIONS" ]]; then continue @@ -21,4 +47,8 @@ for wf in .github/workflows/*.yml; do done done +if [[ $STATUS -eq 1 ]]; then + echo "Re-run this script with --fix to automatically update workflows to match go.mod" +fi + exit $STATUS From 154792908aec67861bc4c9e0e824d21745e38b39 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 5 Sep 2025 14:29:59 +0100 Subject: [PATCH 6/6] more pr suggestions --- scripts/check_go_version.sh | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/scripts/check_go_version.sh b/scripts/check_go_version.sh index 358e061..2b56cea 100755 --- a/scripts/check_go_version.sh +++ b/scripts/check_go_version.sh @@ -1,34 +1,15 @@ #!/usr/bin/env bash set -euo pipefail -fix=0 -args="$(getopt -o "" -l fix -- "$@")" -eval set -- "$args" -while true; do - case "$1" in - --fix) - fix=1 - shift - ;; - --) - shift - break - ;; - *) - error "Unrecognized option: $1" - ;; - esac -done - MOD_VERSION=$(go mod edit -json | jq -r .Go) echo "go.mod version: $MOD_VERSION" STATUS=0 -if [[ $fix -eq 1 ]]; then +if [[ " $* " == *" --fix "* ]]; then for wf in .github/workflows/*.{yml,yaml}; do sed -i "s/go-version:.*/go-version: \"${MOD_VERSION}\"/g" "${wf}" done - exit $STATUS + exit 0 fi for wf in .github/workflows/*.{yml,yaml}; do @@ -37,9 +18,9 @@ for wf in .github/workflows/*.{yml,yaml}; do continue fi - UNIQUE_WF_VERSIONS=$(echo "$WF_VERSIONS" | sort -u) + UNIQUE_WF_VERSIONS=$(sort -u <<<"$WF_VERSIONS") for ver in $UNIQUE_WF_VERSIONS; do - if [[ "${ver}" != "$MOD_VERSION" ]]; then + if [[ $ver != "$MOD_VERSION" ]]; then STATUS=1 echo "❌ $wf: go.mod=$MOD_VERSION but workflow uses $(tr '\n' ' ' <<<"$UNIQUE_WF_VERSIONS")" continue