From f6b70e2e2a8b232a10502097e07a356d84b03558 Mon Sep 17 00:00:00 2001 From: Aravindhan Ayyanathan Date: Wed, 2 Sep 2026 11:54:31 +0100 Subject: [PATCH] Improve kpt version resolution in setup-go-kpt composite action Signed-off-by: Aravindhan Ayyanathan --- .github/actions/setup-go-kpt/action.yml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/actions/setup-go-kpt/action.yml b/.github/actions/setup-go-kpt/action.yml index ff428d8a93..6fb4ffc732 100644 --- a/.github/actions/setup-go-kpt/action.yml +++ b/.github/actions/setup-go-kpt/action.yml @@ -23,7 +23,7 @@ inputs: kpt-fallback-version: description: "Fallback kpt version if extraction from go.mod fails" required: false - default: "v1.0.0-beta.65" + default: "v1.0.0" go-version: description: "Exact version for Go version setup, go-version-file is ignored if set" required: false @@ -31,6 +31,10 @@ inputs: description: "Path to go.mod file for Go version setup" required: false default: "go.mod" + kpt-version-file: + description: "Path to the go.mod file used to resolve the kpt version. Defaults to go-version-file." + required: false + default: "" go-cache: description: "Enable Go module caching" required: false @@ -62,14 +66,26 @@ runs: shell: bash env: GO_VERSION_FILE: ${{ inputs.go-version-file }} + KPT_VERSION_FILE: ${{ inputs.kpt-version-file }} KPT_FALLBACK: ${{ inputs.kpt-fallback-version }} run: | - GO_MOD_DIR=$(dirname -- "$GO_VERSION_FILE") - KPT_VERSION=$(cd "$GO_MOD_DIR" && go list -m -f '{{.Version}}' github.com/kptdev/kpt 2>/dev/null) + set -euo pipefail + VERSION_FILE="${KPT_VERSION_FILE:-$GO_VERSION_FILE}" + KPT_VERSION="" + if [ ! -f "$VERSION_FILE" ]; then + echo "::warning::kpt version file '${VERSION_FILE}' not found; using fallback ${KPT_FALLBACK}." + else + GO_MOD_DIR=$(dirname -- "$VERSION_FILE") + KPT_VERSION=$(cd "$GO_MOD_DIR" && go mod edit -json \ + | jq -r '(.Require[]? | select(.Path=="github.com/kptdev/kpt") | .Version) // ""') + if [ -z "$KPT_VERSION" ]; then + echo "::warning::Could not resolve github.com/kptdev/kpt from ${VERSION_FILE}; using fallback ${KPT_FALLBACK}." + fi + fi if [ -z "$KPT_VERSION" ]; then - echo "Warning: Could not resolve kpt version from ${GO_VERSION_FILE}, using fallback." KPT_VERSION="$KPT_FALLBACK" fi + echo "Using kpt version: ${KPT_VERSION}" echo "version=${KPT_VERSION}" >> "$GITHUB_OUTPUT" - name: Install kpt