Skip to content

Commit

Permalink
Add k0sctl version lookup to vars.sh
Browse files Browse the repository at this point in the history
The vars.sh script is used to obtain variables from Makefile variables
in scripts. Even if the k0sctl version is not maintained in a Makefile,
but rather in a go.mod file, we can use the same interface for scripts.
This makes the origin transparent and we can special-case anything in
the vars.sh script, instead of introducing other ad-hoc mechanisms.

Moreover, include the k0sctl version in the build-env by default. It's
fast and safe enough to be included by default, even if not required.

Signed-off-by: Tom Wieczorek <[email protected]>
  • Loading branch information
twz123 committed Jan 16, 2024
1 parent d43803b commit 3e7654d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 24 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/check-network.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ jobs:
terraform apply -auto-approve
- name: Set k0sctl version
run: |
version=$(cd hack/tool; go list -m -f '{{.Version}}' github.com/k0sproject/k0sctl)
echo "K0SCTL_VERSION=${version}" >> $GITHUB_ENV
- name: Create k0s Cluster using k0sctl
id: k0sctl
run: |
Expand Down
17 changes: 6 additions & 11 deletions .github/workflows/ostests-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,15 @@ jobs:

- name: "Workflow run :: Prepare"
working-directory: ./
env:
K0SCTL_VERSION: ${{ inputs.k0sctl-version }}
run: |
kubernetesVersion="$(./vars.sh kubernetes_version)"
k0sctlVersion="${K0SCTL_VERSION:-$(./vars.sh FROM=hack/tool k0sctl_version)}"
set -x
echo KUBERNETES_VERSION="$kubernetesVersion" >>"$GITHUB_ENV"
echo K0SCTL_VERSION="$k0sctlVersion" >>"$GITHUB_ENV"
- name: "Terraform :: Requisites :: Download k0s"
if: inputs.k0s-version == ''
Expand All @@ -92,17 +98,6 @@ jobs:
name: k0s-linux-amd64
path: ${{ github.workspace }}/.cache

- name: Set k0sctl version
run: |
if [ -z "${{ inputs.k0sctl-version }}" ]; then
version=$(grep k0sproject/k0sctl hack/tool/go.mod|cut -d" " -f2)
echo "Detected k0sctl dependency version ${version}"
else
version="${{ inputs.k0sctl-version }}"
echo "Using given k0sctl version ${version}"
fi
echo "K0SCTL_VERSION=${version}" >> $GITHUB_ENV
- name: "Terraform :: Requisites :: Prepare"
env:
K0S_VERSION: ${{ inputs.k0s-version }}
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/prepare-build-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
set -eu

goVersion="$(./vars.sh go_version)"
k0sctlVersion="$(./vars.sh FROM=hack/tool k0sctl_version)"
golangciLintVersion="$(./vars.sh FROM=hack/tools golangci-lint_version)"
pythonVersion="$(./vars.sh FROM=docs python_version)"

cat <<EOF >>"$GITHUB_ENV"
GO_VERSION=$goVersion
GOLANGCI_LINT_VERSION=$golangciLintVersion
K0SCTL_VERSION=$k0sctlVersion
PYTHON_VERSION=$pythonVersion
EOF

# shellcheck disable=SC1090
. "$GITHUB_ENV"

echo ::group::OS Environment
env | sort
echo ::endgroup::

echo ::group::Build Environment
cat -- "$GITHUB_ENV"
echo ::endgroup::
5 changes: 0 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,6 @@ jobs:
terraform apply -auto-approve
- name: Set k0sctl version
run: |
version=$(cd hack/tool; go list -m -f '{{.Version}}' github.com/k0sproject/k0sctl)
echo "K0SCTL_VERSION=${version}" >> $GITHUB_ENV
- name: Create k0s Cluster using k0sctl
id: k0sctl
run: |
Expand Down
18 changes: 18 additions & 0 deletions vars.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
#shellcheck disable=SC3043

set -eu

Expand All @@ -12,6 +13,18 @@ print_usage() {
echo " $0 FROM=docs python_version"
}

version_from_go_mod() {
local pkg version rest
while read -r pkg version rest; do
if [ "$pkg" = "$1" ]; then
printf %s "$version"
return 0
fi
done

return 1
}

fail() {
echo "$@" >&2
print_usage >&2
Expand Down Expand Up @@ -41,6 +54,11 @@ done
[ -n "$var" ] || fail Makefile variable not given
[ -n "$from" ] || from=embedded-bins

if [ "$var" = k0sctl_version ]; then
version_from_go_mod github.com/k0sproject/k0sctl <"$from"/go.mod
exit 0
fi

exec make --no-print-directory -r -s -f - <<EOF
include $from/Makefile.variables
Expand Down

0 comments on commit 3e7654d

Please sign in to comment.