Skip to content

.

. #1

Workflow file for this run

name: Build and push Docker image
on:
push:
tags:
- "v*"
workflow_dispatch:
inputs:
tag:
description: "Git tag to build (e.g. v0.0.5). Leave empty to build current ref."
required: false
default: ""
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag }}
- name: Compute Docker tags
id: tags
shell: bash
run: |
set -euo pipefail
IMAGE="daanjansen94/virasign"
REF_NAME="${GITHUB_REF_NAME}"
VERSION="${REF_NAME#v}"
# If manually dispatched with an explicit tag, use that for naming.
if [[ -n "${{ inputs.tag }}" ]]; then
REF_NAME="${{ inputs.tag }}"
VERSION="${REF_NAME#v}"
fi
# Read version from pyproject.toml and only publish :latest when the pushed tag
# matches that version (prevents older tags from overwriting :latest).
PROJECT_VERSION="$(python3 - <<'PY'
import tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
print(data["project"]["version"])
PY
)"
TAGS="${IMAGE}:${VERSION}"
if [[ "${VERSION}" == "${PROJECT_VERSION}" ]]; then
TAGS+=$'\n'"${IMAGE}:latest"
fi
{
echo "tags<<EOF"
echo "${TAGS}"
echo "EOF"
} >> "${GITHUB_OUTPUT}"
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
file: docs/docker/Dockerfile
push: true
tags: ${{ steps.tags.outputs.tags }}