Skip to content

Commit

Permalink
Test Autopilot updates for current and previous k0s minor versions
Browse files Browse the repository at this point in the history
Currently, Autopilot update tests are hard-coded to use some 1.24 k0s
versions. Use the current Kubernetes version to determine the latest
k0s releases for that minor version and the previous minor version. Use
these k0s versions as a base for the Autopilot update tests.

Signed-off-by: Tom Wieczorek <[email protected]>
(cherry picked from commit 8b365f1)
  • Loading branch information
twz123 authored and github-actions[bot] committed Nov 17, 2023
1 parent fb7514a commit 446b691
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 32 additions & 14 deletions hack/tools/gen-matrix.sh
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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/[email protected]
}

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 "$@"

0 comments on commit 446b691

Please sign in to comment.