Skip to content

Commit

Permalink
Merge pull request k0sproject#3729 from k0sproject/backport-2847-to-r…
Browse files Browse the repository at this point in the history
…elease-1.26

[Backport release-1.26] Test Autopilot updates for current and previous k0s minor versions
  • Loading branch information
twz123 authored Nov 17, 2023
2 parents fb7514a + 446b691 commit 2f6526b
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 2f6526b

Please sign in to comment.