Skip to content

[pre-commit.ci] pre-commit autoupdate #255

[pre-commit.ci] pre-commit autoupdate

[pre-commit.ci] pre-commit autoupdate #255

name: Create and publish a Docker image to ghcr.io
on:
push:
branches:
- "**"
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract image version prefix
id: image_prefix
run: |
echo "prefix=$(echo ${{ github.ref_name }} | sed 's:/.*::')" >> "$GITHUB_OUTPUT"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,enable=true,priority=100,prefix=,suffix=,format=short
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
provenance: false
push: true
tags: ${{ steps.meta.outputs.tags }}${{ !startsWith(steps.image_prefix.outputs.prefix, 'main') && format('-{0}', steps.image_prefix.outputs.prefix) || '' }}-${{ github.run_number }}
cache-from: type=gha
cache-to: type=gha,mode=max
- uses: benjlevesque/[email protected]
id: short-sha
- name: Create tag
uses: actions/github-script@v7
with:
script: |
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/${{ steps.short-sha.outputs.sha }}${{ !startsWith(steps.image_prefix.outputs.prefix, 'main') && format('-{0}', steps.image_prefix.outputs.prefix) || '' }}-${{ github.run_number }}',
sha: context.sha
})