Skip to content

CI improvements

CI improvements #376

Workflow file for this run

name: Build and publish container image
on:
# run when tagging or pushing to master
push:
branches: [master]
tags: ["*"]
# run on PRs against master
pull_request:
branches: [master]
# manual trigger
workflow_dispatch:
inputs:
tag:
description: Build a container image for this git tag
required: true
env:
# GitHub Container Registry hostname
GHCR_HOSTNAME: ghcr.io
jobs:
build_and_push:
runs-on: ubuntu-latest
steps:
- name: Checkout the latest SHA for this branch
uses: actions/checkout@v4
if: github.event_name != 'workflow_dispatch'
- name: Checkout the specified tag
uses: actions/checkout@v4
if: github.event_name == 'workflow_dispatch'
with:
ref: ${{ github.event.inputs.tag }}
- name: Get the latest Dockerfile if needed
if: github.event_name == 'workflow_dispatch'
run: |
if [[ ! -f Dockerfile ]]; then
git fetch --depth=1 origin master
git checkout origin/master -- Dockerfile
fi
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the container image
uses: docker/build-push-action@v5
with:
# this will add the proper tag if we're in workflow_dispatch
tags: ${{ github.event.inputs.tag }}
cache-from: type=gha
cache-to: type=gha,mode=max