Use Gitea token fallback for registry login
Some checks failed
Container Image / build-and-push (push) Failing after 6s

This commit is contained in:
MrSphay
2026-06-05 13:00:19 +02:00
parent 7d943a7a19
commit e7a3362b86

View File

@@ -24,7 +24,8 @@ jobs:
IMAGE_NAME: odysseus IMAGE_NAME: odysseus
FALLBACK_OWNER: mrsphay FALLBACK_OWNER: mrsphay
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }} REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} ACTIONS_TOKEN: ${{ gitea.token }}
SECRET_GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5
@@ -37,21 +38,34 @@ jobs:
run: | run: |
set -euo pipefail set -euo pipefail
registry_token="${REGISTRY_TOKEN:-${GITEA_TOKEN:-}}" owner="${GITHUB_REPOSITORY_OWNER:-MrSphay}"
if [ -z "${registry_token}" ]; then registry_user="${REGISTRY_USER:-${owner}}"
echo "REGISTRY_TOKEN or GITEA_TOKEN is required to publish ${REGISTRY}/${FALLBACK_OWNER}/${IMAGE_NAME}." image_owner="$(printf '%s' "${owner:-${FALLBACK_OWNER}}" | tr '[:upper:]' '[:lower:]')"
exit 1 image="${REGISTRY}/${image_owner}/${IMAGE_NAME}"
fi
owner="${GITHUB_REPOSITORY_OWNER:-${FALLBACK_OWNER}}"
owner="$(printf '%s' "${owner}" | tr '[:upper:]' '[:lower:]')"
registry_user="${GITHUB_ACTOR:-${owner}}"
image="${REGISTRY}/${owner}/${IMAGE_NAME}"
short_sha="$(printf '%s' "${GITHUB_SHA}" | cut -c1-7)" short_sha="$(printf '%s' "${GITHUB_SHA}" | cut -c1-7)"
ref_name="${GITHUB_REF_NAME:-dev}" ref_name="${GITHUB_REF_NAME:-dev}"
ref_tag="$(printf '%s' "${ref_name}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-' | sed 's/^-//; s/-$//')" ref_tag="$(printf '%s' "${ref_name}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9._-' '-' | sed 's/^-//; s/-$//')"
echo "${registry_token}" | docker login "${REGISTRY}" --username "${registry_user}" --password-stdin login_ok=false
for token_name in REGISTRY_TOKEN ACTIONS_TOKEN SECRET_GITEA_TOKEN; do
token_value="${!token_name:-}"
if [ -z "${token_value}" ]; then
continue
fi
echo "Trying registry login with ${token_name} as ${registry_user}."
if echo "${token_value}" | docker login "${REGISTRY}" --username "${registry_user}" --password-stdin; then
login_ok=true
break
fi
docker logout "${REGISTRY}" >/dev/null 2>&1 || true
done
if [ "${login_ok}" != "true" ]; then
echo "Registry login failed. Configure REGISTRY_TOKEN with package read/write access, or allow packages: write for the repository GITEA_TOKEN."
exit 1
fi
docker build --pull \ docker build --pull \
--tag "${image}:sha-${short_sha}" \ --tag "${image}:sha-${short_sha}" \