Add GHA release workflow #10
Workflow file for this run
This file contains hidden or 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
name: Release | |
on: | |
push: | |
tags: | |
- 'v*' # Trigger on all tag pushes with "v" prefix | |
release: | |
types: | |
- created | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write # Needed for GH releases | |
packages: write # Needed for pushing to GHCR | |
steps: | |
- name: Check GITHUB_TOKEN permissions | |
run: | | |
GITHUB_TOKEN="${{ secrets.GITHUB_TOKEN }}" gh auth status | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: go.mod | |
- name: Install ko | |
run: | | |
go install github.com/google/ko@latest | |
- name: Authenticate with GHCR | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | skopeo login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: Determine version info | |
id: version | |
run: | | |
TAG_NAME=${GITHUB_REF#refs/tags/} | |
echo "tag=$TAG_NAME" >> $GITHUB_ENV | |
LATEST_TAG=$(git tag -l --sort=-v:refname | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1) | |
if [[ "$TAG_NAME" == "$LATEST_TAG" ]]; then | |
echo "latest=true" >> $GITHUB_ENV | |
else | |
echo "latest=false" >> $GITHUB_ENV | |
fi | |
- name: Build and push image | |
run: | | |
ko build --oci-layout-path kpm.oci --push=false --platform all . | |
skopeo copy --all oci:./kpm.oci docker://ghcr.io/${{ github.repository_owner }}/kpm:$tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: If latest version, push latest tag | |
if: env.latest == 'true' | |
run: | | |
skopeo copy --all oci:./kpm.oci docker://ghcr.io/${{ github.repository_owner }}/kpm:latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create/Update Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
generate_release_notes: true | |
make_latest: "${{ env.latest }}" |