Files
workflows/.gitea/workflows/build.yml
T
axelandClaude Opus 5.5 a299c55e3a fix: normalize branch names into valid image tags
A branch such as feature/foo produced an invalid Docker tag, so the build
aborted before it started. Replace invalid characters with a dash, strip
leading dots and dashes, and cap the length at 128. master still maps to
latest.

The branch name now reaches the shell through an env var, because a name
containing $(...) was previously executed by the step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 21:39:59 +01:00

50 lines
1.6 KiB
YAML

name: build
run-name: ${{ gitea.actor }} is building docker image ${{ gitea.repository }} on ${{ gitea.ref }}
on:
workflow_call:
secrets:
PERSONAL_ACCESS_TOKEN:
required: true
env:
IMAGE_TAG: ${{ gitea.ref_name == 'master' && 'latest' || gitea.ref_name }}
IMAGE_NAME: ${{ gitea.repository }}
jobs:
build:
runs-on: docker
steps:
- name: get registry from current GITHUB_SERVER_URL
run: echo "REGISTRY=${GITHUB_SERVER_URL//https:\/\//}" >> $GITHUB_ENV
# Docker tags allow [A-Za-z0-9_.-], up to 128 chars, no leading dot or dash.
# The branch name stays in an env var so it is never parsed as shell code.
- name: build image reference
env:
RAW_TAG: ${{ env.IMAGE_TAG }}
run: |
TAG=$(printf '%s' "$RAW_TAG" | tr -c 'A-Za-z0-9_.-' '-' | sed 's/^[.-]*//' | cut -c1-128)
echo "IMAGE_URL=${{ env.REGISTRY }}/${GITHUB_REPOSITORY,,}:${TAG}" >> $GITHUB_ENV
- name: Check out repository code
uses: https://gitea.com/actions/checkout@v3
- name: login to registry
run: |
docker login -u ${{ gitea.actor }} -p ${{ secrets.PERSONAL_ACCESS_TOKEN }} ${{ env.REGISTRY }}
- name: build image
run: |
docker build --progress plain \
--pull \
--no-cache \
-t ${{ env.IMAGE_URL }} .
- name: push image
run: |
docker push ${{ env.IMAGE_URL }}
- name: logout from registry
run: |
docker logout ${{ env.REGISTRY }}