fix(ci): use basic auth header with token-owner login
This commit is contained in:
parent
c1216323c4
commit
0355c7b45f
1 changed files with 10 additions and 14 deletions
24
.github/workflows/sync-to-gitea.yml
vendored
24
.github/workflows/sync-to-gitea.yml
vendored
|
|
@ -18,27 +18,23 @@ jobs:
|
||||||
|
|
||||||
- name: Sync to Gitea
|
- name: Sync to Gitea
|
||||||
env:
|
env:
|
||||||
GITEA_TOKEN_PRIMARY: ${{ secrets.GITEA_TOKEN }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
GITEA_TOKEN_FALLBACK: ${{ secrets.GITEA_SECRET }}
|
|
||||||
REPO: ${{ github.event.repository.name }}
|
REPO: ${{ github.event.repository.name }}
|
||||||
BRANCH: ${{ github.ref_name }}
|
BRANCH: ${{ github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
GITEA_TOKEN="${GITEA_TOKEN_PRIMARY:-${GITEA_TOKEN_FALLBACK:-}}"
|
|
||||||
if [ -z "${GITEA_TOKEN}" ]; then
|
|
||||||
echo "Missing GITEA token secret. Set GITEA_TOKEN (preferred) or GITEA_SECRET."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
git config user.name "github-actions[bot]"
|
git config user.name "github-actions[bot]"
|
||||||
git config user.email "github-actions[bot]@users.noreply.github.com"
|
git config user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
|
|
||||||
GITEA_URL="https://Admin:${GITEA_TOKEN}@ci.nxtgauge.com/Admin/${REPO}.git"
|
GITEA_USER="$(curl -fsS -H "Authorization: token ${GITEA_TOKEN}" https://ci.nxtgauge.com/api/v1/user | jq -r '.login')"
|
||||||
echo "Sync target: Admin/${REPO}.git on branch ${BRANCH}"
|
TARGET="https://ci.nxtgauge.com/Admin/${REPO}.git"
|
||||||
|
AUTH="$(printf '%s' "${GITEA_USER}:${GITEA_TOKEN}" | base64 | tr -d '\n')"
|
||||||
|
|
||||||
|
curl -fsS -H "Authorization: Basic ${AUTH}" "${TARGET}/info/refs?service=git-receive-pack" >/dev/null
|
||||||
|
|
||||||
git remote remove gitea 2>/dev/null || true
|
git remote remove gitea 2>/dev/null || true
|
||||||
git remote add gitea "${GITEA_URL}"
|
git remote add gitea "${TARGET}"
|
||||||
|
|
||||||
git ls-remote "${GITEA_URL}" >/dev/null
|
git -c http.extraheader="Authorization: Basic ${AUTH}" push gitea "HEAD:${BRANCH}" --force
|
||||||
|
git -c http.extraheader="Authorization: Basic ${AUTH}" push gitea --tags --force
|
||||||
git push "${GITEA_URL}" "HEAD:${BRANCH}" --force
|
|
||||||
git push "${GITEA_URL}" --tags --force
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue