From 1311ff1fd817990e4ff392c69c5c55547c1b3c4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roque=20L=C3=B3pez?= Date: Thu, 6 Jun 2024 15:15:19 -0400 Subject: [PATCH] Update push_gitlab.yml --- .github/workflows/push_gitlab.yml | 67 ++++++++++++------------------- 1 file changed, 25 insertions(+), 42 deletions(-) diff --git a/.github/workflows/push_gitlab.yml b/.github/workflows/push_gitlab.yml index 5fed1c7..0b24d69 100644 --- a/.github/workflows/push_gitlab.yml +++ b/.github/workflows/push_gitlab.yml @@ -1,51 +1,34 @@ -name: Push to GitLab +name: Mirror to GitLab on: push: branches: - - gitlab + - '*' jobs: - push_to_gitlab: + mirror_to_gitlab: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v2 - with: - fetch-depth: 0 # Fetch all history to ensure all branches are included - - - name: Fetch all branches and tags - run: | - git fetch --all - git fetch --tags - - - name: Set up Git - run: | - git config --global user.name 'github-actions' - git config --global user.email 'actions@github.com' - git config --global http.postBuffer 10000000 # 10 MB - - - name: Add GitLab remote - env: - GITLAB_URL: ${{ secrets.GITLAB_URL }} - GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} - run: | - git remote add gitlab https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ secrets.GITLAB_URL }} - - - name: Push all branches to GitLab - env: - GITLAB_URL: ${{ secrets.GITLAB_URL }} - GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} - run: | - # Push all branches - for branch in $(git for-each-ref --format '%(refname:short)' refs/heads/); do - git push gitlab $branch:$branch - done - - - name: Push all tags to GitLab - env: - GITLAB_URL: ${{ secrets.GITLAB_URL }} - GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} - run: | - git push --tags gitlab + - name: Checkout Repository + uses: actions/checkout@v2 + with: + ref: ${{ github.event.ref }} + + - name: Set up Git + run: | + git config --global user.name 'GitHub Actions' + git config --global user.email 'actions@github.com' + + - name: Add GitLab remote + run: | + git remote add gitlab https://oauth2:${{ secrets.GITLAB_TOKEN }}@${{ secrets.GITLAB_URL }} + + - name: Fetch all branches from GitLab + run: | + git fetch gitlab --prune + git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done + + - name: Push all branches to GitLab + run: | + git push gitlab --all