-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitHub Action to install and setup ko
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: 'Setup ko' | ||
description: 'Install and authorize ko' | ||
branding: | ||
icon: box | ||
color: green | ||
inputs: | ||
version: | ||
description: 'Version of ko to install (tip, latest-release, v0.8.2, etc.)' | ||
required: true | ||
default: 'latest-release' | ||
GITHUB_TOKEN: | ||
description: "GitHub token to use to login to ghcr.io; if unset, skip ko login" | ||
required: false | ||
runs: | ||
using: "composite" | ||
steps: | ||
- shell: bash | ||
run: | | ||
# Install ko: | ||
# - if version is "tip", install from tip of main. | ||
# - if version is "latest-release", look up latest release. | ||
# - otherwise, install the specified version. | ||
case ${{ inputs.version }} in | ||
tip) | ||
go get github.com/google/ko@main | ||
exit 0 | ||
;; | ||
latest-release) | ||
tag=$(curl -s https://api.github.com/repos/google/ko/releases | jq -r '.[].tag_name' | head -n 1) | ||
;; | ||
*) | ||
tag="${{ inputs.version }}" | ||
esac | ||
echo "Installing ko @ ${tag}" | ||
curl -fsL https://github.com/google/ko/releases/download/${tag}/ko_${tag:1}_Linux_x86_64.tar.gz | sudo tar xzf - -C /usr/local/bin ko | ||
# If GITHUB_TOKEN is set, ko login to ghcr.io. | ||
if [[ -z "${{ inputs.GITHUB_TOKEN }}" ]]; then | ||
echo "GITHUB_TOKEN unset, not logging in" | ||
else | ||
echo "GITHUB_TOKEN is set, logging in" | ||
echo "${{ inputs.GITHUB_TOKEN }}" | ko login ghcr.io --username ${{ github.repository }} --password-stdin | ||
fi | ||
# Set KO_DOCKER_REPO for future steps. | ||
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}" | ||
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}" >> $GITHUB_ENV |