build.yml•2.09 kB
name: Build
on:
push:
branches:
- '**' # Build on all branches
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
jobs:
pre-check:
runs-on: ubuntu-22.04
outputs:
skip-workflow: ${{ steps.check.outputs.skip-workflow }}
steps:
- name: Check if workflow should be skipped
id: check
run: |
if [[ "${{ github.event.head_commit.author.name }}" == "github-actions[bot]" ]] && [[ "${{ github.event.head_commit.message }}" == Release\ version* ]]; then
echo "skip-workflow=true" >> $GITHUB_OUTPUT
echo "Skipping this workflow..."
else
echo "skip-workflow=false" >> $GITHUB_OUTPUT
echo "Proceeding with this workflow..."
fi
build-and-push-image:
runs-on: ubuntu-22.04
needs: [pre-check]
if: ${{ needs.pre-check.outputs.skip-workflow == 'false' }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,prefix=sha-
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
VERSION=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max