fix: mirror GitLab com project access token e URL encoding #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Espelha main do GitHub para GitLab a cada push. | |
| # | |
| # Secrets no GitHub: | |
| # GITLAB_MIRROR_USER — username do Project Access Token (ex.: project_83796735_bot) | |
| # GITLAB_MIRROR_TOKEN — token gerado no projeto GitLab | |
| # | |
| # Criar em: | |
| # https://gitlab.com/mariahilmar-group/mgi-kpi-pipeline/-/settings/access_tokens | |
| name: Mirror to GitLab | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| concurrency: | |
| group: mirror-gitlab | |
| cancel-in-progress: true | |
| jobs: | |
| mirror: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Push to GitLab | |
| env: | |
| GITLAB_MIRROR_USER: ${{ secrets.GITLAB_MIRROR_USER }} | |
| GITLAB_MIRROR_TOKEN: ${{ secrets.GITLAB_MIRROR_TOKEN }} | |
| run: | | |
| if [ -z "$GITLAB_MIRROR_TOKEN" ] || [ -z "$GITLAB_MIRROR_USER" ]; then | |
| echo "ERRO: defina GITLAB_MIRROR_USER e GITLAB_MIRROR_TOKEN no GitHub." | |
| exit 1 | |
| fi | |
| TOKEN_ENCODED=$(python3 -c "import os, urllib.parse; print(urllib.parse.quote(os.environ['GITLAB_MIRROR_TOKEN'], safe=''))") | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git push "https://${GITLAB_MIRROR_USER}:${TOKEN_ENCODED}@gitlab.com/mariahilmar-group/mgi-kpi-pipeline.git" "HEAD:refs/heads/main" |