Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/update-go-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 9 additions & 12 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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/[email protected]
with:
go-version: ${{ matrix.go_version }}
go-version: ${{ matrix.version }}
check-latest: true
cache-dependency-path: go.sum

Expand All @@ -67,5 +65,4 @@ jobs:
CI: true

- name: Run style and unused
if: ${{ matrix.go_version == '1.22' }}
run: make style unused
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
12 changes: 12 additions & 0 deletions supported_go_versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"versions": [
{
"label": "stable",
"version": "1.25"
},
{
"label": "oldstable",
"version": "1.24"
}
]
}
2 changes: 0 additions & 2 deletions supported_go_versions.txt

This file was deleted.

32 changes: 25 additions & 7 deletions update-go-version.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
{
"versions": [
{
"label": "stable",
"version": "$latest_version",
"name": "Tests (stable)"
},
{
"label": "oldstable",
"version": "$current_stable_version",
"name": "Tests (oldstable)"
}
]
}
EOF
else
echo "No new Go version detected. Current Go version is: $current_version"
fi

Loading