Skip to content

CI

CI #333

Workflow file for this run

name: CI
on:
workflow_dispatch:
push:
tags:
- "v*.*.*"
branches:
- main
pull_request:
types:
- opened
- reopened
schedule:
- cron: "0 0 * * 6"
env:
REGISTRY_IMAGE: ghcr.io/${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci-skip]')"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare
id: prep
run: |
VERSION=dev
if [[ $GITHUB_REF == refs/tags/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
fi
# v1.0.0
TAGS="${REGISTRY_IMAGE}:${VERSION}"
# v1.0.0,v1
TAGS="${TAGS},${REGISTRY_IMAGE}:${VERSION%%.*}"
if [[ $VERSION =~ ^v[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
# :v1.0.0,:v1,:latest
TAGS="${TAGS},${REGISTRY_IMAGE}:latest"
fi
echo ::set-output name=tags::${TAGS}
if [ "${{github.event_name}}" == "pull_request" ]; then
echo ::set-output name=push::false
echo ::set-output name=cache_from::"type=registry,ref=${REGISTRY_IMAGE}:buildcache"
echo ::set-output name=cache_to::""
else
echo ::set-output name=push::true
echo ::set-output name=cache_from::"type=registry,ref=${REGISTRY_IMAGE}:buildcache"
echo ::set-output name=cache_to::"type=registry,ref=${REGISTRY_IMAGE}:buildcache,mode=max"
fi
echo ::set-output name=github_server_url::"${GITHUB_SERVER_URL}"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
with:
install: true
version: latest
driver-opts: image=moby/buildkit:master
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ steps.prep.outputs.push }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
IMAGE_SOURCE=${{ steps.prep.outputs.github_server_url }}/${{ github.repository }}
cache-from: ${{ steps.prep.outputs.cache_from }}
cache-to: ${{ steps.prep.outputs.cache_to }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}