Skip to content

fix: restore README images on docs and PyPI (#293) #168

fix: restore README images on docs and PyPI (#293)

fix: restore README images on docs and PyPI (#293) #168

Workflow file for this run

name: Build and publish a Docker image
on:
push:
branches:
- 'main'
workflow_run:
workflows: [Release]
types:
- completed
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
PYTHON_VERSION: '3.14'
# See https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Install python
uses: actions/setup-python@v5
with:
python-version: ${{env.PYTHON_VERSION}}
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Set package version
run: |
VERSION=$(uvx dunamai from git --style semver)
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
- name: Export requirements.txt file
run: uv export --all-packages --all-extras --format requirements-txt --no-hashes --no-editable --no-default-groups --no-emit-workspace > requirements.txt
- 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: Get git branch and short sha for tag
env:
EVENT_BRANCH: ${{ github.event.workflow_run.head_branch || github.ref_name }}
EVENT_SHA: ${{ github.event.workflow_run.head_sha || github.sha }}
run: |
git_hash_short=$(git rev-parse --short "$EVENT_SHA")
printf 'GIT_HASH_SHORT=%s\n' "${git_hash_short}" >> "$GITHUB_ENV"
git_branch="$EVENT_BRANCH"
if [[ -z "${git_branch}" ]]; then
git_branch=$(git rev-parse --abbrev-ref HEAD)
fi
printf 'GIT_BRANCH=%s\n' "${git_branch}" >> "$GITHUB_ENV"
git_branch_docker_safe=$(echo "${git_branch}" | tr / -)
printf 'GIT_BRANCH_DOCKER_SAFE=%s\n' "${git_branch_docker_safe}" >> "$GITHUB_ENV"
# Tagging documented at: https://github.com/docker/metadata-action?tab=readme-ov-file#basic
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# Match SHA tags and revision labels to the commit checked out above.
context: git
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,pattern={{version}},value=${{ env.PACKAGE_VERSION }},enable=${{ (github.event_name == 'workflow_run') && (github.event.workflow_run.conclusion == 'success') }}
type=sha,format=short
type=raw,value=latest,enable=${{ env.GIT_BRANCH == 'main' }}
- name: Build and push Docker image
id: push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.GIT_BRANCH_DOCKER_SAFE }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
build-args: |
semver=${{ env.PACKAGE_VERSION }}
git_hash_short=${{ env.GIT_HASH_SHORT }}
git_branch=${{ env.GIT_BRANCH }}
build_date=$(date -u -Iseconds)
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Delete untagged images
uses: dataaxiom/ghcr-cleanup-action@v1
with:
delete-untagged: true
older-than: 30 days