diff --git a/.github/workflows/update-go-versions.yml b/.github/workflows/update-go-versions.yml index 3e2a05139..b77f301b1 100644 --- a/.github/workflows/update-go-versions.yml +++ b/.github/workflows/update-go-versions.yml @@ -15,8 +15,8 @@ jobs: - name: Checkout repository uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Execute bash script - run: bash update-go-version.bash + - name: Update Go version + run: make update-go-version # If there are no changes (i.e. no diff exists with the checked-out base branch), # no pull request will be created and the action exits silently. diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 99072ff19..bf41c6853 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -22,29 +22,27 @@ jobs: name: Fetch supported Go versions runs-on: ubuntu-latest outputs: - supported_versions: ${{ steps.matrix.outputs.supported_versions }} + matrix: ${{ steps.versions.outputs.matrix }} steps: - name: Checkout code uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - name: Read supported_go_versions.txt - id: matrix + - name: Get supported Go versions JSON + id: versions run: | - versions=$(cat supported_go_versions.txt) - matrix="[$(echo "$versions" | sed 's/\(.*\)/"\1"/' | paste -s -d,)]" - echo "supported_versions=$matrix" >> $GITHUB_OUTPUT + echo "matrix=$(cat supported_go_versions.json | jq -c .)" >> "$GITHUB_OUTPUT" test: - name: Tests (${{ matrix.go_version }}) + name: Tests (${{ matrix.label }}) runs-on: ubuntu-latest needs: supported_versions # Set fail-fast to false to ensure all Go versions are tested regardless of failures strategy: fail-fast: false matrix: - go_version: ${{ fromJSON(needs.supported_versions.outputs.supported_versions) }} + include: ${{ fromJSON(needs.supported_versions.outputs.matrix).versions }} # Define concurrency at the job level for matrix jobs concurrency: - group: ${{ github.workflow }}-test-${{ matrix.go_version }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} + group: ${{ github.workflow }}-test-${{ matrix.label }}-${{ (github.event.pull_request && github.event.pull_request.number) || github.ref || github.run_id }} cancel-in-progress: true steps: @@ -54,10 +52,10 @@ jobs: - name: Check for CRLF line endings run: make check-crlf - - name: Set up Go ${{ matrix.go_version }} + - name: Set up Go ${{ matrix.version }} uses: actions/setup-go@v6.0.0 with: - go-version: ${{ matrix.go_version }} + go-version: ${{ matrix.version }} check-latest: true cache-dependency-path: go.sum @@ -67,5 +65,4 @@ jobs: CI: true - name: Run style and unused - if: ${{ matrix.go_version == '1.22' }} run: make style unused diff --git a/Makefile b/Makefile index ff01ce882..826cded62 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,14 @@ test: deps common-test test-exp .PHONY: test-short test-short: deps common-test-short test-exp-short +.PHONY: update-go-version +update-go-version: + @bash update-go-version.bash + $(MAKE) generate-go-collector-test-files + .PHONY: generate-go-collector-test-files -file := supported_go_versions.txt -VERSIONS := $(shell cat ${file}) +file := supported_go_versions.json +VERSIONS := $(shell grep -o '"version": "[^"]*"' $(file) | sed 's/"version": "\(.*\)"/\1/') generate-go-collector-test-files: for GO_VERSION in $(VERSIONS); do \ docker run \ diff --git a/supported_go_versions.json b/supported_go_versions.json new file mode 100644 index 000000000..cc5a985f1 --- /dev/null +++ b/supported_go_versions.json @@ -0,0 +1,12 @@ +{ + "versions": [ + { + "label": "stable", + "version": "1.25" + }, + { + "label": "oldstable", + "version": "1.24" + } + ] +} diff --git a/supported_go_versions.txt b/supported_go_versions.txt deleted file mode 100644 index 250eb476c..000000000 --- a/supported_go_versions.txt +++ /dev/null @@ -1,2 +0,0 @@ -1.25 -1.24 diff --git a/update-go-version.bash b/update-go-version.bash index 02e6aa6c4..f1a40338a 100644 --- a/update-go-version.bash +++ b/update-go-version.bash @@ -6,18 +6,36 @@ get_latest_versions() { curl -s https://go.dev/VERSION?m=text | sed -E -n 's/go([0-9]+\.[0-9]+|\.[0-9]+).*/\1/p' } -current_version=$(cat supported_go_versions.txt | head -n 1) +# Extract the current stable version from JSON +current_version=$(grep -A 1 '"label": "stable"' supported_go_versions.json | grep '"version"' | sed 's/.*"version": "\([^"]*\)".*/\1/') latest_version=$(get_latest_versions) # Check for new version of Go, and generate go collector test files -# Add new Go version to supported_go_versions.txt, and remove the oldest version +# Update supported_go_versions.json: shift stable to oldstable, add new version as stable if [[ ! $current_version =~ $latest_version ]]; then echo "New Go version available: $latest_version" - echo "Updating supported_go_versions.txt and generating Go Collector test files" - sed -i "1i $latest_version" supported_go_versions.txt - sed -i '$d' supported_go_versions.txt - make generate-go-collector-test-files + echo "Updating supported_go_versions.json and generating Go Collector test files" + + # Get the current stable version (which will become oldstable) + current_stable_version=$(grep -A 1 '"label": "stable"' supported_go_versions.json | grep '"version"' | sed 's/.*"version": "\([^"]*\)".*/\1/') + + # Create new JSON structure with new version as stable, current stable as oldstable + cat > supported_go_versions.json <