Skip to content

Building and Publishing to GitHub #18

Building and Publishing to GitHub

Building and Publishing to GitHub #18

Workflow file for this run

# This Github Action will build and publish images to github registry automatically.
# The image version can be either `latest` from the main branch or a tag whenever a tag is created.
name: Building and Publishing to GitHub
on:
push:
branches:
- main
create:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_VERSION: latest
GO_VERSION: '1.22.7'
jobs:
export-registry:
runs-on: ubuntu-20.04
outputs:
registry: ${{ steps.export.outputs.registry }}
steps:
- id: export
run: |
# registry must be in lowercase
echo "::set-output name=registry::$(echo "${{ env.REGISTRY }}/${{ github.repository }}" | tr [:upper:] [:lower:])"
publish-images:
needs: export-registry
env:
REGISTRY: ${{ needs.export-registry.outputs.registry }}
runs-on: ubuntu-20.04
steps:
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v4
- name: Set image version for a new release
if: startsWith(github.ref, 'refs/tags/')
run: |
echo "IMAGE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Login to ${{ env.REGISTRY }}
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push controller manager images to registry
run: |
make push
env:
REGISTRY: ${{ env.REGISTRY}}
TAG: ${{ env.IMAGE_VERSION }}