From 0406160452bc011ee5c17fb4cf29ddbad1d53402 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Thu, 5 Dec 2024 12:03:18 +0700 Subject: [PATCH] ci: Push to mirror repo with github actions --- .github/workflows/mirror.yml | 47 ++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/mirror.yml diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 0000000000..a0432e3224 --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,47 @@ +# REF: https://github.com/JamesRobionyRogers/GitHub-to-GitBucket-Action/blob/47a44e9/.github/workflows/push-to-gitbucket.yml +name: Mirror Repository + +on: + workflow_dispatch: + push: + branches: + - master + +jobs: + mirror: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Fetch all branches + run: | + git fetch --all + git fetch --tags + + - name: List branches + run: | + git branch -a + + # Enables tracking of remote branches ensuring all branches are pushed to mirror repo + - name: Track remote branches + run: | + for branch in $(git branch -r | grep -v '\->'); do + local_branch=${branch#origin/} + git branch --track "$local_branch" "$branch" || true + done + + - name: Push to mirror repo (GitLab) + env: + MIRROR_URL: "gitlab.com/null2264/yokai.git" + MIRROR_USERNAME: ${{ secrets.MIRROR_USERNAME }} + MIRROR_AUTH: ${{ secrets.MIRROR_AUTH }} + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + git remote add mirror https://$MIRROR_USERNAME:$MIRROR_AUTH@$MIRROR_URL + git push --mirror -v mirror