fix(ci): tolerate /user 401 and fallback to configured auth user
This commit is contained in:
parent
0355c7b45f
commit
0f89d90cbc
1 changed files with 13 additions and 2 deletions
15
.github/workflows/sync-to-gitea.yml
vendored
15
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -18,16 +18,27 @@ jobs:
|
|||
|
||||
- name: Sync to Gitea
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_TOKEN_PRIMARY: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_TOKEN_FALLBACK: ${{ secrets.GITEA_SECRET }}
|
||||
GITEA_USERNAME: ${{ secrets.GITEA_USERNAME }}
|
||||
REPO: ${{ github.event.repository.name }}
|
||||
BRANCH: ${{ github.ref_name }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
|
||||
GITEA_TOKEN="${GITEA_TOKEN_PRIMARY:-${GITEA_TOKEN_FALLBACK:-}}"
|
||||
if [ -z "${GITEA_TOKEN}" ]; then
|
||||
echo "Missing token secret: set GITEA_TOKEN (preferred) or GITEA_SECRET"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git config user.name "github-actions[bot]"
|
||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
GITEA_USER="$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" https://ci.nxtgauge.com/api/v1/user | jq -r '.login')"
|
||||
GITEA_USER="$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" https://ci.nxtgauge.com/api/v1/user 2>/dev/null | jq -r '.login // empty' || true)"
|
||||
if [ -z "$GITEA_USER" ]; then
|
||||
GITEA_USER="${GITEA_USERNAME:-Admin}"
|
||||
fi
|
||||
TARGET="https://ci.nxtgauge.com/Admin/${REPO}.git"
|
||||
AUTH="$(printf '%s' "${GITEA_USER}:${GITEA_TOKEN}" | base64 | tr -d '\n')"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue