diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b6e102c8ebf4..d8a23e65228f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -271,10 +271,19 @@ jobs: with: go-version: ${{ env.GO_VERSION }} - - id: set-matrix + - name: Generate Autopilot test matrix + id: set-matrix run: | - matrix=$(./hack/tools/gen-matrix.sh 1.24.3 1.24.4) - echo matrix="$matrix" >> $GITHUB_OUTPUT + set -x + k8sVersion="$(./vars.sh kubernetes_version)" + majorVersion="${k8sVersion%%.*}" + minorVersion=${k8sVersion#$majorVersion.} + minorVersion="${minorVersion%%.*}" + + { + printf matrix= + hack/tools/gen-matrix.sh "$majorVersion.$(($minorVersion - 1))" "$majorVersion.$minorVersion" + } >> "$GITHUB_OUTPUT" autopilot-smoketest: name: Autopilot smoke test diff --git a/hack/tools/gen-matrix.sh b/hack/tools/gen-matrix.sh index c87d671ef5bb..fed9903b3e76 100755 --- a/hack/tools/gen-matrix.sh +++ b/hack/tools/gen-matrix.sh @@ -1,20 +1,38 @@ -#!/bin/bash +#!/usr/bin/env sh -# Founds the last k0s releases of the given versions and generates json MATRIX_OUTPUT for github actions. +# Finds the last k0s releases of the given versions and generates json MATRIX_OUTPUT for github actions. # Usage: # ./gen-matrix.sh 1.24.2 1.24.3 -# Output: ["v1.24.2+k0s.0","v1.24.3+k0s.0"] +# Output: ["v1.24.2+k0s.0", "v1.24.3+k0s.0"] -go install github.com/k0sproject/version/cmd/k0s_sort@v0.2.2 -GOBIN="$(go env GOPATH)/bin" -MATRIX_OUTPUT="[" -COMMA="" -for i in "$@"; do \ - RELEASE=$(gh release list -L 100 -R k0sproject/k0s | grep "+k0s." | grep -v Draft | cut -f 1 | $GOBIN/k0s_sort | grep $i | tail -1) - MATRIX_OUTPUT+="$COMMA\"$RELEASE\"" - COMMA="," -done +list_k0s_releases() { + gh api -X GET /repos/k0sproject/k0s/releases \ + -F per_page=100 --paginate \ + --jq '.[] | select(.prerelease == false and .draft == false) | .name' +} -MATRIX_OUTPUT+="]" +k0s_sort() { + go run github.com/k0sproject/version/cmd/k0s_sort@v0.2.2 +} -echo $MATRIX_OUTPUT +latest_release() { + list_k0s_releases | grep -F "v$1" | k0s_sort | tail -1 +} + +json_print_latest_releases() { + printf '[' + + pattern='"%s"' + for i in "$@"; do + latestRelease="$(latest_release "$i")" + [ -z "$latestRelease" ] || { + # shellcheck disable=SC2059 + printf "$pattern" "$latestRelease" + pattern=', "%s"' + } + done + + echo ']' +} + +json_print_latest_releases "$@"