forked from ko-build/setup-ko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
57 lines (52 loc) · 1.9 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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'
runs:
using: "composite"
steps:
- shell: bash
run: |
set -ex
# 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)
echo "Installing ko using go install"
go install github.com/google/ko@main
;;
latest-release)
tag=$(curl -L -s -u "username:${{ github.token }}" https://api.github.com/repos/ko-build/ko/releases/latest | jq -r '.tag_name')
;;
*)
tag="${{ inputs.version }}"
esac
os=${{ runner.os }}
if [[ $os == "macOS" ]]; then
os="Darwin"
fi
if [[ ! -z ${tag} ]]; then
echo "Installing ko @ ${tag} for ${os}"
curl -fsL https://github.com/ko-build/ko/releases/download/${tag}/ko_${tag:1}_${os}_x86_64.tar.gz | sudo tar xzf - -C /usr/local/bin ko
fi
if [[ ! -z ${KO_DOCKER_REPO} ]]; then
echo "KO_DOCKER_REPO is already set"
echo "Skipping login to ghcr.io and passing KO_DOCKER_REPO=${KO_DOCKER_REPO} on to future steps"
echo "KO_DOCKER_REPO=${KO_DOCKER_REPO}" >> $GITHUB_ENV
else
# NB: username doesn't seem to matter.
echo "${{ github.token }}" | ko login ghcr.io --username "dummy" --password-stdin
# Set KO_DOCKER_REPO for future steps.
# We need to get the repository name in lowercase, otherwise it could fail
repo=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
echo "KO_DOCKER_REPO=ghcr.io/${repo}"
echo "KO_DOCKER_REPO=ghcr.io/${repo}" >> $GITHUB_ENV
fi