Skip to content
Merged
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
69 changes: 52 additions & 17 deletions .github/actions/setup-go-kpt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
# limitations under the License.

name: "Setup Go and kpt"
description: "Sets up Go from go.mod and installs kpt version matching go.mod"
description: "Sets up Go from go.mod and installs kpt, either from the kpt-version input or the version pinned in go.mod"

inputs:
install-kpt:
description: "Whether to install kpt"
required: false
default: "true"
kpt-version:
description: "Exact kpt version to install (e.g. v1.0.2-pre.4). Takes precedence over kpt-version-file."
required: false
default: ""
go-version:
description: "Exact version for Go version setup, go-version-file is ignored if set"
required: false
Expand All @@ -28,7 +32,7 @@ inputs:
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."
description: "Path to the go.mod file used to resolve the kpt version. Defaults to go-version-file. Ignored when kpt-version is set."
required: false
default: ""
go-cache:
Expand Down Expand Up @@ -56,36 +60,67 @@ runs:
cache: ${{ inputs.go-cache == 'true' }}
cache-dependency-path: ${{ inputs.cache-dependency-path }}

- name: Get kpt version from go.mod
- name: Resolve kpt version
if: inputs.install-kpt == 'true'
id: kpt-version
shell: bash
env:
KPT_VERSION_INPUT: ${{ inputs.kpt-version }}
GO_VERSION_FILE: ${{ inputs.go-version-file }}
KPT_VERSION_FILE: ${{ inputs.kpt-version-file }}
run: |
set -euo pipefail
VERSION_FILE="${KPT_VERSION_FILE:-$GO_VERSION_FILE}"
if [ ! -f "$VERSION_FILE" ]; then
echo "::error::kpt version file '${VERSION_FILE}' not found."
exit 1
fi
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 "::error::Could not resolve github.com/kptdev/kpt from ${VERSION_FILE}."
exit 1
if [ -n "${KPT_VERSION_INPUT}" ]; then
KPT_VERSION="${KPT_VERSION_INPUT}"
echo "Using kpt version from kpt-version input"
else
VERSION_FILE="${KPT_VERSION_FILE:-$GO_VERSION_FILE}"
if [ ! -f "$VERSION_FILE" ]; then
echo "::error::kpt version file '${VERSION_FILE}' not found."
exit 1
fi
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 "::error::Could not resolve github.com/kptdev/kpt from ${VERSION_FILE}."
exit 1
fi
fi
# Normalise to the go.mod form, e.g. 1.0.2-pre.4 -> v1.0.2-pre.4
case "${KPT_VERSION}" in
v*) ;;
*) KPT_VERSION="v${KPT_VERSION}" ;;
esac
echo "Using kpt version: ${KPT_VERSION}"
echo "version=${KPT_VERSION}" >> "$GITHUB_OUTPUT"

- name: Resolve kpt release tag
if: inputs.install-kpt == 'true'
id: kpt-tag
shell: bash
env:
KPT_VERSION: ${{ steps.kpt-version.outputs.version }}
run: |
set -euo pipefail
# Newer kpt releases use the cli/<version> tag, older ones the plain <version>.
# Output is captured first so a git failure aborts instead of looking like "no cli/ tag".
if ! REFS=$(GIT_TERMINAL_PROMPT=0 git ls-remote --tags https://github.com/kptdev/kpt "refs/tags/cli/${KPT_VERSION}"); then
echo "::error::Could not query kptdev/kpt tags to resolve the release layout for ${KPT_VERSION}."
exit 1
fi
if [ -n "${REFS}" ]; then
TAG="cli/${KPT_VERSION}"
else
TAG="${KPT_VERSION}"
fi
echo "Using kpt release tag: ${TAG}"
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"

Comment thread
aravindtga marked this conversation as resolved.
Resolved
- name: Install kpt
if: inputs.install-kpt == 'true'
uses: jaxxstorm/action-install-gh-release@v2.1.0
with:
repo: kptdev/kpt
# The kpt CLI binaries are published on the cli/ module's release tag
# (e.g. cli/v1.0.2-pre.4); the root module tag carries no assets.
tag: cli/${{ steps.kpt-version.outputs.version }}
tag: ${{ steps.kpt-tag.outputs.tag }}
chmod: 0755
Loading