Skip to content

ci: lowercase GHCR repo name in image tag (Docker requires lowercase) #2

ci: lowercase GHCR repo name in image tag (Docker requires lowercase)

ci: lowercase GHCR repo name in image tag (Docker requires lowercase) #2

Workflow file for this run

name: Build and publish Docker image
on:
release:
types: [published]
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Compute image tags
id: tags
run: |
GHCR_IMAGE="ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"
DOCKERHUB_IMAGE="${{ secrets.DOCKERHUB_USERNAME }}/voscript"
TAGS="$GHCR_IMAGE:latest,$DOCKERHUB_IMAGE:latest"
# Tag-triggered builds (release or push-tag) get the version tag too.
# Strip leading "v" for Docker Hub convention (0.7.0), keep raw ref for GHCR.
if [ "${{ github.event_name }}" = "release" ] || [ "${{ github.event_name }}" = "push" ]; then
RAW_VERSION="${GITHUB_REF#refs/tags/}"
STRIPPED_VERSION="${RAW_VERSION#v}"
TAGS="$TAGS,$GHCR_IMAGE:$RAW_VERSION,$DOCKERHUB_IMAGE:$STRIPPED_VERSION"
fi
echo "tags=$TAGS" >> "$GITHUB_OUTPUT"
- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./app
platforms: linux/amd64
push: true
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max