diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index e4ae548..e414091 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -16,20 +16,62 @@ jobs: with: fetch-depth: 0 - - name: Prepare repository for mirroring + - name: Set up SSH + uses: webfactory/ssh-agent@v0.8.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Add known hosts run: | - git branch -r | grep 'origin/' | grep -v 'origin/HEAD' | while read remote; do - git branch --delete --remotes "$remote" - done + mkdir -p ~/.ssh + ssh-keyscan gitlab.com >> ~/.ssh/known_hosts + ssh-keyscan bitbucket.org >> ~/.ssh/known_hosts - name: Mirror to GitLab - uses: pixta-dev/repository-mirroring-action@v1 - with: - target_repo_url: git@gitlab.com:miti99/miti99.gitlab.io.git - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + # Add GitLab remote + git remote add gitlab git@gitlab.com:miti99/miti99.gitlab.io.git + + # Fetch from GitLab to get information about the default branch + git fetch gitlab + + # Get current branch name + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + + # Get list of local branches + LOCAL_BRANCHES=$(git branch | grep -v "origin/" | tr -d '* ' | tr '\n' ' ') + + # Push each local branch individually to GitLab + for branch in $LOCAL_BRANCHES; do + # Push branch to GitLab + git push gitlab $branch:$branch --force + done + + # Push all tags + git push gitlab --tags --force - name: Mirror to Bitbucket - uses: pixta-dev/repository-mirroring-action@v1 - with: - target_repo_url: git@bitbucket.org:miti99/miti99.bitbucket.io.git - ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + run: | + # Add Bitbucket remote + git remote add bitbucket git@bitbucket.org:miti99/miti99.bitbucket.io.git + + # Fetch from Bitbucket to get information about the default branch + git fetch bitbucket + + # Get current branch name + CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) + + # Get list of local branches + LOCAL_BRANCHES=$(git branch | grep -v "origin/" | tr -d '* ' | tr '\n' ' ') + + # Push each local branch individually to Bitbucket + for branch in $LOCAL_BRANCHES; do + # Push branch to Bitbucket + git push bitbucket $branch:$branch --force + done + + # Push all tags + git push bitbucket --tags --force