ci(release): fix git auth + fail-fast when GITLAB_TOKEN missing
semantic-release провалился с 'HTTP Basic: Access denied' потому что: 1. CI default git remote использует CI_JOB_TOKEN scope — не может push'ить tags/commits в protected refs (main branch). 2. GITLAB_TOKEN ещё не настроен в Settings → CI/CD → Variables. 3. Без explicit git remote rewrite semantic-release/git plugin падает с cryptic 'Authentication failed' вместо понятного 'token missing'. Fixes: - before_script: fail-fast если GITLAB_TOKEN пустой — печатает setup инструкцию (write_repository + api scopes, Masked + Protected flags) и exit 0. Pipeline не краснеет (allow_failure: true). - git remote set-url origin https://gitlab-ci-token:${GITLAB_TOKEN}@... — переопределяет default remote чтобы git push мог работать с Project Access Token'ом. - git config user.email/name — semantic-release commit author. После настройки GITLAB_TOKEN в GitLab UI следующий push в main создаст первый авто-tag (v1.3.0 minimum по conventional commits с момента v1.2.2).
This commit is contained in:
+25
-1
@@ -406,12 +406,36 @@ release:
|
||||
# GL_TOKEN — @semantic-release/gitlab plugin requires this name specifically.
|
||||
GL_TOKEN: $GITLAB_TOKEN
|
||||
before_script:
|
||||
# Fail fast если token не настроен. Job всё равно allow_failure: true —
|
||||
# pipeline не покраснеет, но в logs понятная причина (вместо cryptic
|
||||
# "Authentication failed").
|
||||
- |
|
||||
if [ -z "$GITLAB_TOKEN" ]; then
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
echo "GITLAB_TOKEN is empty — release job will skip."
|
||||
echo ""
|
||||
echo "Setup (one-time):"
|
||||
echo " 1. Settings → Access Tokens → create Project Access Token"
|
||||
echo " scopes: write_repository + api, role: Maintainer"
|
||||
echo " 2. Settings → CI/CD → Variables → add GITLAB_TOKEN"
|
||||
echo " flags: Masked + Protected"
|
||||
echo ""
|
||||
echo "См. RELEASE.md в репозитории для подробностей."
|
||||
echo "═══════════════════════════════════════════════════════════════"
|
||||
exit 0
|
||||
fi
|
||||
- apk add --no-cache git ca-certificates
|
||||
# Configure git remote с токеном для push. CI default remote — HTTPS с
|
||||
# CI_JOB_TOKEN scope, который НЕ может push'ить tags/commits. Переопределяем
|
||||
# на Project Access Token (GITLAB_TOKEN).
|
||||
- git remote set-url origin "https://gitlab-ci-token:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"
|
||||
- git config user.email "${GITLAB_USER_EMAIL:-ci@ordinis.local}"
|
||||
- git config user.name "semantic-release"
|
||||
- npm install -g --silent pnpm@9.15.4
|
||||
- cd ordinis-admin-ui
|
||||
- pnpm install --frozen-lockfile --silent
|
||||
script:
|
||||
- npx semantic-release
|
||||
# Не блокирует следующие pipelines если release fail'нул (e.g. нет
|
||||
# релизных commits). Manual investigation если нужно.
|
||||
# релизных commits, нет GITLAB_TOKEN, transient network error).
|
||||
allow_failure: true
|
||||
|
||||
Reference in New Issue
Block a user