if KO_DOCKER_REPO is set, skip login and propagate it
This commit is contained in:
parent
6ab7b626d1
commit
47862890e7
20
.github/workflows/use-action.yaml
vendored
20
.github/workflows/use-action.yaml
vendored
@ -22,18 +22,30 @@ jobs:
|
||||
- uses: imjasonh/setup-ko@main
|
||||
- run: ko publish --bare ./
|
||||
|
||||
# Install an old release.
|
||||
- uses: imjasonh/setup-ko@main
|
||||
- name: Install old release
|
||||
uses: imjasonh/setup-ko@main
|
||||
with:
|
||||
version: v0.8.0
|
||||
- name: Check installed version
|
||||
run: ko version | grep 0.8.0
|
||||
|
||||
# Install from tip
|
||||
- uses: imjasonh/setup-ko@main
|
||||
- name: Install from tip
|
||||
uses: imjasonh/setup-ko@main
|
||||
with:
|
||||
version: tip
|
||||
- name: Check installed version (tip)
|
||||
run: |
|
||||
sudo rm /usr/local/bin/ko # Uninstall previous versions.
|
||||
ko version
|
||||
|
||||
# If KO_DOCKER_REPO is set during setup, it's set for future steps.
|
||||
- name: Pre-set KO_DOCKER_REPO
|
||||
uses: imjasonh/setup-ko@main
|
||||
env:
|
||||
KO_DOCKER_REPO: already-set
|
||||
- name: Check pre-set KO_DOCKER_REPO
|
||||
run: |
|
||||
if [[ ${KO_DOCKER_REPO} -ne "already-set"]]; then
|
||||
echo "${KO_DOCKER_REPO} != already-set"
|
||||
exit 1
|
||||
fi
|
||||
|
@ -30,8 +30,8 @@ _That's it!_ This workflow will build and publish your code to [GitHub Container
|
||||
By default, the action sets `KO_DOCKER_REPO=ghcr.io/[owner]/[repo]`.
|
||||
See [documentation for `ko`](https://github.com/google/ko#configuration) to learn more about configuring `ko`.
|
||||
|
||||
:warning: **Note:** The action _sets_ `KO_DOCKER_REPO` for all subsequent steps.
|
||||
If you define `KO_DOCKER_REPO` as a workflow-wide environment variable, its value will be modified after the action runs.
|
||||
By default the action sets `KO_DOCKER_REPO` for all subsequent steps.
|
||||
Instead, if the `env` is already set when the action runs, it will skip logging in to ghcr.io and propagate `KO_DOCKER_REPO` for subsequent steps.
|
||||
|
||||
The action works on Linux and macOS [runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and _should_ work for Windows runners when `ko` releases include Windows binaries (next `ko` release🤞! see [google/ko#339](https://github.com/google/ko/pull/339))
|
||||
|
||||
|
16
action.yml
16
action.yml
@ -41,9 +41,15 @@ runs:
|
||||
curl -fsL https://github.com/google/ko/releases/download/${tag}/ko_${tag:1}_${os}_x86_64.tar.gz | sudo tar xzf - -C /usr/local/bin ko
|
||||
fi
|
||||
|
||||
# NB: username doesn't seem to matter.
|
||||
echo "${{ github.token }}" | ko login ghcr.io --username "dummy" --password-stdin
|
||||
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.
|
||||
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}"
|
||||
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
|
||||
# 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
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user