Skip to content

Commit 679e8ac

Browse files
patch adding version specifying + older binary handling for kpt&go install … (#4871)
* adding version specifying + older binary handling for kpt&go install github action Signed-off-by: Catalin-Stratulat-Ericsson <catalin.stratulat@ericsson.com> * addressing aravindan comment regarding auth and cutover Signed-off-by: Catalin-Stratulat-Ericsson <catalin.stratulat@ericsson.com> --------- Signed-off-by: Catalin-Stratulat-Ericsson <catalin.stratulat@ericsson.com>
1 parent 5b3bb72 commit 679e8ac

1 file changed

Lines changed: 52 additions & 17 deletions

File tree

‎.github/actions/setup-go-kpt/action.yml‎

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@
1313
# limitations under the License.
1414

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

1818
inputs:
1919
install-kpt:
2020
description: "Whether to install kpt"
2121
required: false
2222
default: "true"
23+
kpt-version:
24+
description: "Exact kpt version to install (e.g. v1.0.2-pre.4). Takes precedence over kpt-version-file."
25+
required: false
26+
default: ""
2327
go-version:
2428
description: "Exact version for Go version setup, go-version-file is ignored if set"
2529
required: false
@@ -28,7 +32,7 @@ inputs:
2832
required: false
2933
default: "go.mod"
3034
kpt-version-file:
31-
description: "Path to the go.mod file used to resolve the kpt version. Defaults to go-version-file."
35+
description: "Path to the go.mod file used to resolve the kpt version. Defaults to go-version-file. Ignored when kpt-version is set."
3236
required: false
3337
default: ""
3438
go-cache:
@@ -56,36 +60,67 @@ runs:
5660
cache: ${{ inputs.go-cache == 'true' }}
5761
cache-dependency-path: ${{ inputs.cache-dependency-path }}
5862

59-
- name: Get kpt version from go.mod
63+
- name: Resolve kpt version
6064
if: inputs.install-kpt == 'true'
6165
id: kpt-version
6266
shell: bash
6367
env:
68+
KPT_VERSION_INPUT: ${{ inputs.kpt-version }}
6469
GO_VERSION_FILE: ${{ inputs.go-version-file }}
6570
KPT_VERSION_FILE: ${{ inputs.kpt-version-file }}
6671
run: |
6772
set -euo pipefail
68-
VERSION_FILE="${KPT_VERSION_FILE:-$GO_VERSION_FILE}"
69-
if [ ! -f "$VERSION_FILE" ]; then
70-
echo "::error::kpt version file '${VERSION_FILE}' not found."
71-
exit 1
72-
fi
73-
GO_MOD_DIR=$(dirname -- "$VERSION_FILE")
74-
KPT_VERSION=$(cd "$GO_MOD_DIR" && go mod edit -json \
75-
| jq -r '(.Require[]? | select(.Path=="github.com/kptdev/kpt") | .Version) // ""')
76-
if [ -z "$KPT_VERSION" ]; then
77-
echo "::error::Could not resolve github.com/kptdev/kpt from ${VERSION_FILE}."
78-
exit 1
73+
if [ -n "${KPT_VERSION_INPUT}" ]; then
74+
KPT_VERSION="${KPT_VERSION_INPUT}"
75+
echo "Using kpt version from kpt-version input"
76+
else
77+
VERSION_FILE="${KPT_VERSION_FILE:-$GO_VERSION_FILE}"
78+
if [ ! -f "$VERSION_FILE" ]; then
79+
echo "::error::kpt version file '${VERSION_FILE}' not found."
80+
exit 1
81+
fi
82+
GO_MOD_DIR=$(dirname -- "$VERSION_FILE")
83+
KPT_VERSION=$(cd "$GO_MOD_DIR" && go mod edit -json \
84+
| jq -r '(.Require[]? | select(.Path=="github.com/kptdev/kpt") | .Version) // ""')
85+
if [ -z "$KPT_VERSION" ]; then
86+
echo "::error::Could not resolve github.com/kptdev/kpt from ${VERSION_FILE}."
87+
exit 1
88+
fi
7989
fi
90+
# Normalise to the go.mod form, e.g. 1.0.2-pre.4 -> v1.0.2-pre.4
91+
case "${KPT_VERSION}" in
92+
v*) ;;
93+
*) KPT_VERSION="v${KPT_VERSION}" ;;
94+
esac
8095
echo "Using kpt version: ${KPT_VERSION}"
8196
echo "version=${KPT_VERSION}" >> "$GITHUB_OUTPUT"
8297

98+
- name: Resolve kpt release tag
99+
if: inputs.install-kpt == 'true'
100+
id: kpt-tag
101+
shell: bash
102+
env:
103+
KPT_VERSION: ${{ steps.kpt-version.outputs.version }}
104+
run: |
105+
set -euo pipefail
106+
# Newer kpt releases use the cli/<version> tag, older ones the plain <version>.
107+
# Output is captured first so a git failure aborts instead of looking like "no cli/ tag".
108+
if ! REFS=$(GIT_TERMINAL_PROMPT=0 git ls-remote --tags https://github.com/kptdev/kpt "refs/tags/cli/${KPT_VERSION}"); then
109+
echo "::error::Could not query kptdev/kpt tags to resolve the release layout for ${KPT_VERSION}."
110+
exit 1
111+
fi
112+
if [ -n "${REFS}" ]; then
113+
TAG="cli/${KPT_VERSION}"
114+
else
115+
TAG="${KPT_VERSION}"
116+
fi
117+
echo "Using kpt release tag: ${TAG}"
118+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
119+
83120
- name: Install kpt
84121
if: inputs.install-kpt == 'true'
85122
uses: jaxxstorm/action-install-gh-release@v2.1.0
86123
with:
87124
repo: kptdev/kpt
88-
# The kpt CLI binaries are published on the cli/ module's release tag
89-
# (e.g. cli/v1.0.2-pre.4); the root module tag carries no assets.
90-
tag: cli/${{ steps.kpt-version.outputs.version }}
125+
tag: ${{ steps.kpt-tag.outputs.tag }}
91126
chmod: 0755

0 commit comments

Comments
 (0)