Skip to content

Commit a6ccf01

Browse files
committed
fix: mirror GitLab com project access token e URL encoding
1 parent 7e1ef85 commit a6ccf01

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

.github/workflows/mirror-gitlab.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# Espelha main do GitHub para GitLab a cada push.
22
#
3-
# Secret no GitHub: GITLAB_MIRROR_TOKEN
4-
# Token no GitLab: Project Access Token com write_repository
5-
# https://gitlab.com/mariahilmar-group/mgi-kpi-pipeline/-/settings/access_tokens
3+
# Secrets no GitHub:
4+
# GITLAB_MIRROR_USER — username do Project Access Token (ex.: project_83796735_bot)
5+
# GITLAB_MIRROR_TOKEN — token gerado no projeto GitLab
6+
#
7+
# Criar em:
8+
# https://gitlab.com/mariahilmar-group/mgi-kpi-pipeline/-/settings/access_tokens
69

710
name: Mirror to GitLab
811

@@ -26,13 +29,14 @@ jobs:
2629

2730
- name: Push to GitLab
2831
env:
32+
GITLAB_MIRROR_USER: ${{ secrets.GITLAB_MIRROR_USER }}
2933
GITLAB_MIRROR_TOKEN: ${{ secrets.GITLAB_MIRROR_TOKEN }}
3034
run: |
31-
if [ -z "$GITLAB_MIRROR_TOKEN" ]; then
32-
echo "ERRO: defina GITLAB_MIRROR_TOKEN nos secrets do GitHub."
35+
if [ -z "$GITLAB_MIRROR_TOKEN" ] || [ -z "$GITLAB_MIRROR_USER" ]; then
36+
echo "ERRO: defina GITLAB_MIRROR_USER e GITLAB_MIRROR_TOKEN no GitHub."
3337
exit 1
3438
fi
39+
TOKEN_ENCODED=$(python3 -c "import os, urllib.parse; print(urllib.parse.quote(os.environ['GITLAB_MIRROR_TOKEN'], safe=''))")
3540
git config user.name "github-actions[bot]"
3641
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
37-
git remote add gitlab https://gitlab.com/mariahilmar-group/mgi-kpi-pipeline.git
38-
git -c "http.extraHeader=PRIVATE-TOKEN: ${GITLAB_MIRROR_TOKEN}" push gitlab HEAD:main
42+
git push "https://${GITLAB_MIRROR_USER}:${TOKEN_ENCODED}@gitlab.com/mariahilmar-group/mgi-kpi-pipeline.git" "HEAD:refs/heads/main"

0 commit comments

Comments
 (0)