Skip to content
Merged
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
52 changes: 52 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,58 @@ jobs:
kubectl cluster-info
kubectl get nodes

test-with-version-file:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Create version file
run: echo "kind v0.23.0" > .tool-versions

- name: Create kind cluster from version file
uses: ./
with:
version_file: ".tool-versions"

- name: Test
run: |
kind version | grep "v0.23.0"
kubectl cluster-info
kubectl get nodes

test-with-plain-version-file:
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Create version file
run: echo "v0.23.0" > .kind_version

- name: Create kind cluster from a plain version file
uses: ./
with:
version_file: ".kind_version"

- name: Test
run: |
kind version | grep "v0.23.0"
kubectl cluster-info
kubectl get nodes

test-with-custom-kubeconfig:
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ For more information, reference the GitHub Help Documentation for [Creating a wo
For more information on inputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#input)

- `version`: The kind version to use (default: `v0.33.0`)
- `version_file`: The path to a file containing the kind version to use. Supports the asdf [`.tool-versions`](https://asdf-vm.com/manage/configuration.html#tool-versions) layout (the `kind` entry) and plain version files. The version is used as-is, so include the leading `v` (for example `kind v0.33.0`). Takes precedence over `version` when set.
- `config`: The path to the kind config file
- `node_image`: The Docker image for the cluster nodes
- `cluster_name`: The name of the cluster to create (default: `chart-testing`)
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
description: "The kind version to use (default: v0.33.0)"
required: false
default: "v0.33.0"
version_file:
description: "The path to a file containing the kind version to use (asdf '.tool-versions' or a plain version file; the version is used as-is, e.g. v0.33.0). Takes precedence over 'version' when set."
required: false
config:
description: "The path to the kind config file"
required: false
Expand Down
35 changes: 35 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,45 @@ set -o pipefail

SCRIPT_DIR=$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}" || realpath "${BASH_SOURCE[0]}")")

# Resolve the kind version from a version file. Supports the asdf
# '.tool-versions' format (a line such as "kind v0.33.0") as well as a plain
# file that contains only the version string.
resolve_version_from_file() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we also parse if i have a file that have only the version?

like
.kind_version
then in the file

v0.23.0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then add a test for that as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plain files already work: when there's no kind line, the first non-comment line is used as the version, so a .kind_version containing v0.23.0 resolves to v0.23.0. Added a test-with-plain-version-file job for exactly that, and bumped the checkout pin in the version-file job to v7.0.1 to match the other jobs.

local file="$1"
local version=""

if [[ ! -f "${file}" ]]; then
echo "ERROR: version_file '${file}' does not exist." >&2
exit 1
fi

# asdf '.tool-versions' format: a line such as "kind v0.33.0".
version=$(grep -E '^[[:space:]]*kind[[:space:]]+' "${file}" | head -n 1 | tr -d '\r' | awk '{print $2}') || true

# Otherwise treat the file as a plain version file (first token of the
# first non-empty, non-comment line).
if [[ -z "${version}" ]]; then
version=$(grep -vE '^[[:space:]]*(#|$)' "${file}" | head -n 1 | tr -d '\r' | awk '{print $1}') || true
fi

if [[ -z "${version}" ]]; then
echo "ERROR: no kind version found in version_file '${file}'." >&2
exit 1
fi

echo "${version}"
}

main() {
local args=()
local registry_args=()

# A version file takes precedence over the 'version' input when set.
if [[ -n "${INPUT_VERSION_FILE:-}" ]]; then
INPUT_VERSION="$(resolve_version_from_file "${INPUT_VERSION_FILE}")"
echo "Using kind version '${INPUT_VERSION}' from version_file '${INPUT_VERSION_FILE}'." >&2
fi

if [[ -n "${INPUT_VERSION:-}" ]]; then
args+=(--version "${INPUT_VERSION}")
fi
Expand Down