Compare commits
No commits in common. "main" and "v0.2" have entirely different histories.
23
.github/dependabot.yml
vendored
23
.github/dependabot.yml
vendored
@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: gomod
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
groups:
|
|
||||||
all:
|
|
||||||
update-types:
|
|
||||||
- "patch"
|
|
||||||
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "daily"
|
|
||||||
open-pull-requests-limit: 10
|
|
||||||
groups:
|
|
||||||
all:
|
|
||||||
update-types:
|
|
||||||
- "minor"
|
|
||||||
- "patch"
|
|
55
.github/workflows/ci.yaml
vendored
55
.github/workflows/ci.yaml
vendored
@ -1,55 +0,0 @@
|
|||||||
name: ci
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test-ko-action:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
|
|
||||||
with:
|
|
||||||
go-version: '1.22'
|
|
||||||
check-latest: 'true'
|
|
||||||
|
|
||||||
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
|
||||||
|
|
||||||
# Minimal publish
|
|
||||||
- uses: ./
|
|
||||||
|
|
||||||
- run: ko publish --bare ./
|
|
||||||
if: ${{ github.event_name == 'pull_request' }}
|
|
||||||
env:
|
|
||||||
KO_DOCKER_REPO: ko.local
|
|
||||||
|
|
||||||
- name: Install old release
|
|
||||||
uses: ./
|
|
||||||
with:
|
|
||||||
version: v0.8.0
|
|
||||||
|
|
||||||
- name: Check installed version
|
|
||||||
run: ko version | grep 0.8.0
|
|
||||||
|
|
||||||
- name: Install from tip
|
|
||||||
uses: ./
|
|
||||||
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: ./
|
|
||||||
env:
|
|
||||||
KO_DOCKER_REPO: already-set
|
|
||||||
|
|
||||||
- name: Check pre-set KO_DOCKER_REPO
|
|
||||||
run: |
|
|
||||||
if [[ "${KO_DOCKER_REPO}" != "already-set" ]]; then
|
|
||||||
echo "${KO_DOCKER_REPO} != already-set"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
43
.github/workflows/use-action.yaml
vendored
43
.github/workflows/use-action.yaml
vendored
@ -2,61 +2,38 @@ name: Use Action
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: ['main']
|
||||||
- 'main'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
use-action:
|
use-action:
|
||||||
name: Use Action
|
name: Use Action
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
platform:
|
platform: [ubuntu-latest, macos-latest]
|
||||||
- ubuntu-latest
|
|
||||||
- macos-latest
|
|
||||||
|
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.22'
|
go-version: 1.16
|
||||||
check-latest: 'true'
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
|
|
||||||
|
|
||||||
# Minimal publish
|
# Minimal publish
|
||||||
- uses: ko-build/setup-ko@main
|
- uses: imjasonh/setup-ko@main
|
||||||
|
|
||||||
- run: ko publish --bare ./
|
- run: ko publish --bare ./
|
||||||
|
|
||||||
- name: Install old release
|
# Install an old release.
|
||||||
uses: ko-build/setup-ko@main
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
with:
|
with:
|
||||||
version: v0.8.0
|
version: v0.8.0
|
||||||
|
|
||||||
- name: Check installed version
|
- name: Check installed version
|
||||||
run: ko version | grep 0.8.0
|
run: ko version | grep 0.8.0
|
||||||
|
|
||||||
- name: Install from tip
|
# Install from tip
|
||||||
uses: ko-build/setup-ko@main
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
with:
|
with:
|
||||||
version: tip
|
version: tip
|
||||||
|
|
||||||
- name: Check installed version (tip)
|
- name: Check installed version (tip)
|
||||||
run: |
|
run: |
|
||||||
sudo rm /usr/local/bin/ko # Uninstall previous versions.
|
sudo rm /usr/local/bin/ko # Uninstall previous versions.
|
||||||
ko version
|
ko version
|
||||||
|
|
||||||
# If KO_DOCKER_REPO is set during setup, it's set for future steps.
|
|
||||||
- name: Pre-set KO_DOCKER_REPO
|
|
||||||
uses: ko-build/setup-ko@main
|
|
||||||
env:
|
|
||||||
KO_DOCKER_REPO: already-set
|
|
||||||
|
|
||||||
- name: Check pre-set KO_DOCKER_REPO
|
|
||||||
run: |
|
|
||||||
if [[ "${KO_DOCKER_REPO}" != "already-set" ]]; then
|
|
||||||
echo "${KO_DOCKER_REPO} != already-set"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
101
README.md
101
README.md
@ -1,10 +1,6 @@
|
|||||||
# GitHub Action to install and setup [`ko`](https://github.com/ko-build/ko)
|
# GitHub Action to install and setup [`ko`](https://github.com/google/ko)
|
||||||
|
|
||||||
[](https://github.com/ko-build/setup-ko/actions/workflows/use-action.yaml)
|
[](https://github.com/imjasonh/setup-ko/actions/workflows/use-action.yaml)
|
||||||
|
|
||||||
> :warning: Note: `ko` recently [moved to its own GitHub org](https://github.com/ko-build/ko/issues/791), which broke `setup-ko@v0.5` if the `ko` version wasn't specified.
|
|
||||||
>
|
|
||||||
> To fix this, either upgrade to [`setup-ko@v0.6`](https://github.com/ko-build/setup-ko/releases/tag/v0.6) or specify `version`
|
|
||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
|
|
||||||
@ -20,97 +16,100 @@ jobs:
|
|||||||
name: Publish
|
name: Publish
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.20.x'
|
go-version: 1.15
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- uses: ko-build/setup-ko@v0.6
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
- run: ko build
|
- run: ko publish ./
|
||||||
```
|
```
|
||||||
|
|
||||||
_That's it!_ This workflow will build and publish your code to [GitHub Container Regsitry](https://ghcr.io).
|
_That's it!_ This workflow will build and publish your code to [GitHub Container Regsitry](https://ghcr.io).
|
||||||
|
|
||||||
By default, the action sets `KO_DOCKER_REPO=ghcr.io/[owner]/[repo]` for all subsequent steps, and uses the `${{ github.token }}` to authorize pushes to GHCR.
|
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`.
|
||||||
See [documentation for `ko`](https://ko.build/configuration/) to learn more about configuring `ko`.
|
|
||||||
|
|
||||||
The action works on Linux and macOS [runners](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners).
|
|
||||||
If you'd like support for Windows runners, [let us know](https://github.com/ko-build/setup-ko/issues/new)!
|
|
||||||
|
|
||||||
### Select `ko` version to install
|
### Select `ko` version to install
|
||||||
|
|
||||||
By default, `ko-build/setup-ko` installs the [latest released version of `ko`](https://github.com/ko-build/ko/releases).
|
By default, `imjasonh/setup-ko` installs the latest released version of `ko`.
|
||||||
|
|
||||||
You can select a version with the `version` parameter:
|
You can select a version with the `version` parameter:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
- uses: ko-build/setup-ko@v0.6
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
with:
|
with:
|
||||||
version: v0.14.1
|
version: v0.8.0
|
||||||
```
|
```
|
||||||
|
|
||||||
To build and install `ko` from source using `go install`, specify `version: tip`.
|
To build and install `ko` from source using `go get`, specify `version: tip`.
|
||||||
|
|
||||||
### Pushing to other registries
|
### Pushing to other registries
|
||||||
|
|
||||||
By default, `ko-build/setup-ko` configures `ko` to push images to [GitHub Container Registry](https://ghcr.io), but you can configure it to push to other registries as well.
|
By default, `imjasonh/setup-ko` configures `ko` to push images to [GitHub Container Registry](https://ghcr.io), but you can configure it to push to other registries.
|
||||||
|
|
||||||
If `KO_DOCKER_REPO` is already set when `setup-ko` runs, it will skip logging in to ghcr.io and will propagate `KO_DOCKER_REPO` for subsequent steps.
|
To do this, you need to provide credentials to authorize the push.
|
||||||
|
|
||||||
To do this, you should provide credentials to authorize the push.
|
|
||||||
You can use [encrypted secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store the authorization token, and pass it to `ko login` before pushing:
|
You can use [encrypted secrets](https://docs.github.com/en/actions/reference/encrypted-secrets) to store the authorization token, and pass it to `ko login` before pushing:
|
||||||
|
|
||||||
```yaml
|
```
|
||||||
steps:
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
...
|
|
||||||
- uses: ko-build/setup-ko@v0.6
|
|
||||||
env:
|
|
||||||
KO_DOCKER_REPO: my.registry/my-repo
|
|
||||||
- env:
|
- env:
|
||||||
auth_token: ${{ secrets.auth_token }}
|
auth_token: ${{ secrets.auth_token }}
|
||||||
run: |
|
run: |
|
||||||
echo "${auth_token}" | ko login https://my.registry --username my-username --password-stdin
|
echo "${auth_token}" | ko login https://my.registry --username my-username --password-stdin
|
||||||
ko build
|
export KO_DOCKER_REPO=my.registry/my-repo
|
||||||
|
ko publish ./
|
||||||
```
|
```
|
||||||
|
|
||||||
### Release Integration
|
### Release Integration
|
||||||
|
|
||||||
In addition to publishing images, `ko` can produce YAML files containing references to built images, using [`ko resolve`](https://ko.build/features/k8s)
|
In addition to publishing images, `ko` can produce YAML files containing references to built images, using [`ko resolve`](https://github.com/google/ko#kubernetes-integration)
|
||||||
|
|
||||||
With this action, you can use `ko resolve` to produce output YAML that you then attach to a GitHub Release using the [GitHub CLI](https://cli.github.com).
|
With this action, you can use `ko resolve` to produce output YAML that you then attach to a GitHub Release using [actions/create-release](https://github.com/actions/create-release) and [actions/upload-release-asset](https://github.com/actions/upload-release-asset).
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: Publish Release YAML
|
name: Publish Release
|
||||||
|
|
||||||
on:
|
on:
|
||||||
release:
|
push:
|
||||||
types:
|
tags: ['v*']
|
||||||
- 'created'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
publish-release-yaml:
|
publish-release:
|
||||||
name: Publish Release YAML
|
name: Publish Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/setup-go@v4
|
- uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: '1.20'
|
go-version: 1.15
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- uses: ko-build/setup-ko@v0.6
|
|
||||||
|
|
||||||
- name: Generate and upload release.yaml
|
- uses: imjasonh/setup-ko@v0.1
|
||||||
|
- run: ko resolve -f config/ > release-${{ github.sha }}.yaml
|
||||||
|
|
||||||
|
- name: Create Release
|
||||||
|
id: create_release
|
||||||
|
uses: actions/create-release@v1
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
with:
|
||||||
tag=$(echo ${{ github.ref }} | cut -c11-) # get tag name without tags/refs/ prefix.
|
tag_name: ${{ github.ref }}
|
||||||
ko resolve -t ${tag} -f config/ > release.yaml
|
release_name: Release ${{ github.ref }}
|
||||||
gh release upload ${tag} release.yaml
|
|
||||||
|
- name: Upload Release Asset
|
||||||
|
uses: actions/upload-release-asset@v1
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
with:
|
||||||
|
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||||
|
asset_path: ./release-${{ github.sha }}.yaml
|
||||||
|
asset_name: release-${{ github.sha }}.yaml
|
||||||
|
asset_content_type: application/x-yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### A note on versioning
|
### A note on versioning
|
||||||
|
|
||||||
The `@v0.X` in the `uses` statement refers to the version _of the action definition in this repo._
|
The `@v0.1` in the `uses` statement refers to the version _of the action definition in this repo._
|
||||||
|
|
||||||
Regardless of what version of the action definition you use, `ko-build/setup-ko` will install the latest released version of `ko` unless otherwise specified with `version:`.
|
Regardless of what version of the action definition you use, `imjasonh/setup-ko` will install the latest released version of `ko` unless otherwise specified with `version:`.
|
||||||
|
30
action.yml
30
action.yml
@ -5,7 +5,7 @@ branding:
|
|||||||
color: green
|
color: green
|
||||||
inputs:
|
inputs:
|
||||||
version:
|
version:
|
||||||
description: 'Version of ko to install (tip, latest-release, v0.14.1, etc.)'
|
description: 'Version of ko to install (tip, latest-release, v0.8.2, etc.)'
|
||||||
required: true
|
required: true
|
||||||
default: 'latest-release'
|
default: 'latest-release'
|
||||||
runs:
|
runs:
|
||||||
@ -13,19 +13,17 @@ runs:
|
|||||||
steps:
|
steps:
|
||||||
- shell: bash
|
- shell: bash
|
||||||
run: |
|
run: |
|
||||||
set -ex
|
|
||||||
|
|
||||||
# Install ko:
|
# Install ko:
|
||||||
# - if version is "tip", install from tip of main.
|
# - if version is "tip", install from tip of main.
|
||||||
# - if version is "latest-release", look up latest release.
|
# - if version is "latest-release", look up latest release.
|
||||||
# - otherwise, install the specified version.
|
# - otherwise, install the specified version.
|
||||||
case ${{ inputs.version }} in
|
case ${{ inputs.version }} in
|
||||||
tip)
|
tip)
|
||||||
echo "Installing ko using go install"
|
echo "Installing ko using go get"
|
||||||
go install github.com/google/ko@main
|
go get github.com/google/ko@main
|
||||||
;;
|
;;
|
||||||
latest-release)
|
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=$(curl -s https://api.github.com/repos/google/ko/releases | jq -r '.[].tag_name' | head -n 1)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
tag="${{ inputs.version }}"
|
tag="${{ inputs.version }}"
|
||||||
@ -38,20 +36,12 @@ runs:
|
|||||||
|
|
||||||
if [[ ! -z ${tag} ]]; then
|
if [[ ! -z ${tag} ]]; then
|
||||||
echo "Installing ko @ ${tag} for ${os}"
|
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
|
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
|
fi
|
||||||
|
|
||||||
if [[ ! -z ${KO_DOCKER_REPO} ]]; then
|
# NB: username doesn't seem to matter.
|
||||||
echo "KO_DOCKER_REPO is already set"
|
echo "${{ github.token }}" | ko login ghcr.io --username "dummy" --password-stdin
|
||||||
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.
|
# Set KO_DOCKER_REPO for future steps.
|
||||||
# We need to get the repository name in lowercase, otherwise it could fail
|
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}"
|
||||||
repo=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
echo "KO_DOCKER_REPO=ghcr.io/${{ github.repository }}" >> $GITHUB_ENV
|
||||||
echo "KO_DOCKER_REPO=ghcr.io/${repo}"
|
|
||||||
echo "KO_DOCKER_REPO=ghcr.io/${repo}" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user