From f7ab369d476ec2729b3aceb19ccc336ce4b04adf Mon Sep 17 00:00:00 2001 From: DevTekVE Date: Thu, 1 Aug 2024 17:22:43 +0200 Subject: [PATCH] First attempt at mirroring to gitlab --- .github/workflows/mirror_to_gitlab.yaml | 55 +++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/mirror_to_gitlab.yaml diff --git a/.github/workflows/mirror_to_gitlab.yaml b/.github/workflows/mirror_to_gitlab.yaml new file mode 100644 index 0000000000..bbb731759d --- /dev/null +++ b/.github/workflows/mirror_to_gitlab.yaml @@ -0,0 +1,55 @@ +name: Mirror to GitLab + +on: + push: + delete: + workflow_dispatch: # This enables manual triggering + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Wait for other instances of this workflow to conclude + uses: softprops/turnstyle@8db075d65b19bf94e6e8687b504db69938dc3c65 + with: + same-branch-only: 'true' + abort-after-seconds: 300 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout Repository + uses: actions/checkout@v3 + with: + ref: ${{ github.ref }} + fetch-depth: 0 # Fetch full history + + - name: Set up Git + run: | + git config --global user.name 'GitHub Action' + git config --global user.email 'action@github.com' + + - name: Set up SSH + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Add GitLab public keys + run: | + ssh-keyscan -H gitlab.com >> ~/.ssh/known_hosts + + - name: Sync and commit changes + id: sync-and-commit + run: | + git lfs pull + + # Add GitLab remote + git remote add gitlab git@gitlab.com:sunnypilot/public/sunnypilot.git + + # Fetch from GitLab and check if the branch exists + if git fetch gitlab ${{ github.ref }}; then + # Merge changes from GitLab if the branch exists + git merge gitlab/${{ github.ref_name }} --allow-unrelated-histories --strategy-option=theirs + else + echo "Branch does not exist on GitLab, skipping merge." + fi + git push -u gitlab ${{ github.ref }} # If you have issues with "push rejected missing LFS" or something. Make sure you disabled LFS on the GITLAB repo if you intend to use a different LFS repo other than the target repo \ No newline at end of file