diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6b823b9..4dccabd6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,15 +19,18 @@ 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 + - 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 - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download @@ -74,13 +77,16 @@ jobs: - name: Checkout uses: actions/checkout@v5 + - 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: - 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 8b27f78d..14c4ec60 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,15 +19,18 @@ 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 + - 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 - uses: actions/checkout@v5 - - name: Get dependencies run: | go mod download @@ -92,10 +95,16 @@ 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: - go-version: "1.22" + go-version: "1.24.2" id: go - uses: hashicorp/setup-terraform@v3 @@ -103,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 @@ -122,10 +128,16 @@ 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 + - 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 @@ -133,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 new file mode 100755 index 00000000..2b56ceae --- /dev/null +++ b/scripts/check_go_version.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -euo pipefail + +MOD_VERSION=$(go mod edit -json | jq -r .Go) +echo "go.mod version: $MOD_VERSION" +STATUS=0 + +if [[ " $* " == *" --fix "* ]]; then + for wf in .github/workflows/*.{yml,yaml}; do + sed -i "s/go-version:.*/go-version: \"${MOD_VERSION}\"/g" "${wf}" + done + exit 0 +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 + fi + + UNIQUE_WF_VERSIONS=$(sort -u <<<"$WF_VERSIONS") + 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 + +if [[ $STATUS -eq 1 ]]; then + echo "Re-run this script with --fix to automatically update workflows to match go.mod" +fi + +exit $STATUS