ci: derive registry host, owner and user for Docker publish
CI / Go (test / vet / build) (push) Successful in 27s
CI / Rust (fmt / clippy / test / build) (push) Successful in 53s
CI / Go ↔ Rust differential + SQLite takeover (push) Successful in 1m53s
Docker publish / Build and push image (push) Failing after 1m2s

Login failed with "Username required" because REGISTRY_OWNER was not set.
Default the registry host to this Gitea instance, the owner to the
repository owner and the user to the tag pusher, lowercase the image
name, and keep a failed GHA cache export from failing the build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
wtandClaude Opus 5.5 committed 2026-10-30 13:42:19 +07:00
1 parent 9e0235c31f
commit d4619ec5ba
1 file changed
+21 -12
+21 -12
View File
@@ -5,11 +5,11 @@ name: Docker publish
# Configure the repository by adding these secrets / variables: # Configure the repository by adding these secrets / variables:
# Secrets: # Secrets:
# REGISTRY_TOKEN - Gitea PAT with `write:package` (and `read:repository`) scope. # REGISTRY_TOKEN - Gitea PAT with `write:package` (and `read:repository`) scope.
# Variables (Settings -> Actions): # Optional variables (Settings -> Actions); defaults come from the repository:
# REGISTRY_HOST - the Gitea registry host, e.g. gitea.com (default below) # REGISTRY_HOST - the Gitea registry host (default: host of this Gitea instance)
# REGISTRY_OWNER - owner/namespace of the repo, e.g. your-username or your-org # REGISTRY_OWNER - owner/namespace of the image (default: repository owner)
# REGISTRY_REPO - repository name, e.g. balance-server # REGISTRY_REPO - image name (default: repository name)
# REGISTRY_USER - the username owning the token if it differs from REGISTRY_OWNER. # REGISTRY_USER - the username owning the token (default: user who pushed the tag)
# #
# NOTE: variable/secret names must NOT start with GITEA_ or GITHUB_. # NOTE: variable/secret names must NOT start with GITEA_ or GITHUB_.
@@ -20,10 +20,10 @@ on:
- "v*" - "v*"
env: env:
REGISTRY_HOST: ${{ vars.REGISTRY_HOST || 'gitea.com' }} REGISTRY_HOST: ${{ vars.REGISTRY_HOST }}
REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER }} REGISTRY_OWNER: ${{ vars.REGISTRY_OWNER || github.repository_owner }}
REGISTRY_REPO: ${{ vars.REGISTRY_REPO || github.event.repository.name }} REGISTRY_REPO: ${{ vars.REGISTRY_REPO || github.event.repository.name }}
REGISTRY_USER: ${{ vars.REGISTRY_USER || vars.REGISTRY_OWNER }} REGISTRY_USER: ${{ vars.REGISTRY_USER || github.actor }}
jobs: jobs:
publish: publish:
@@ -40,10 +40,19 @@ jobs:
id: meta id: meta
env: env:
VERSION: ${{ github.ref_name }} VERSION: ${{ github.ref_name }}
SERVER_URL: ${{ github.server_url }}
run: | run: |
# Keep only semver body so "v1.2.3" -> "1.2.3". # Keep only semver body so "v1.2.3" -> "1.2.3".
tag="${VERSION#v}" tag="${VERSION#v}"
echo "version_tagname=$tag" >> "$GITHUB_OUTPUT" echo "version_tagname=$tag" >> "$GITHUB_OUTPUT"
# The Gitea registry lives on the same host as the instance itself.
host="${REGISTRY_HOST:-${SERVER_URL#*://}}"
host="${host%%/*}"
echo "host=$host" >> "$GITHUB_OUTPUT"
# Image references must be lowercase ("BalanceServer" -> "balanceserver").
image="$host/${REGISTRY_OWNER,,}/${REGISTRY_REPO,,}"
echo "image=$image" >> "$GITHUB_OUTPUT"
echo "Publishing $image:$tag as $REGISTRY_USER"
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
@@ -51,7 +60,7 @@ jobs:
- name: Log in to Gitea Container Registry - name: Log in to Gitea Container Registry
uses: docker/login-action@v3 uses: docker/login-action@v3
with: with:
registry: ${{ env.REGISTRY_HOST }} registry: ${{ steps.meta.outputs.host }}
username: ${{ env.REGISTRY_USER }} username: ${{ env.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }} password: ${{ secrets.REGISTRY_TOKEN }}
@@ -61,7 +70,7 @@ jobs:
context: . context: .
push: true push: true
tags: | tags: |
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.REGISTRY_REPO }}:${{ steps.meta.outputs.version_tagname }} ${{ steps.meta.outputs.image }}:${{ steps.meta.outputs.version_tagname }}
${{ env.REGISTRY_HOST }}/${{ env.REGISTRY_OWNER }}/${{ env.REGISTRY_REPO }}:latest ${{ steps.meta.outputs.image }}:latest
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max,ignore-error=true