rehlds / .github

Technical repository for ReHLDS organization-wide CI, labels synchronization, and central task/discussion tracking.
2 stars 0 forks source link

Automatic sync with Gitlab's read-only mirror #23

Open stamepicmorg opened 4 days ago

stamepicmorg commented 4 days ago

Setup workflow with sync from GitHub to Gitlab.

Proposal

We propose adding a workflow file to each corresponding repository in the ReHLDS organization.

This will allow the same changes to be sent to GitLab automatically with each commit.

Implementation Steps

1) Create a Template:

name: Automatic sync with Gitlab's read-only mirror

on: [workflow_dispatch, push]

jobs:
  mirror:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up SSH key for Runner
        env:
          SSH_KEY: ${{ secrets.GITLAB_DEPLOY_KEY }}
        run: |
          mkdir -p ~/.ssh
          echo "$SSH_KEY" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
          ssh-keyscan -t rsa gitlab.com >> ~/.ssh/known_hosts

      - name: Clone repository from GitHub as mirror and push to Gitlab
        env:
          REPO_ORIGINAL: "url-github"
          REPO_TARGET:   "ssh-gitlab"
        run: |
          git clone --mirror "$REPO_ORIGINAL" repo-mirror
          cd repo-mirror
          git remote set-url origin "$REPO_TARGET"
          git push --mirror --force

2) Add secret to repository with GITLAB_DEPLOY_KEY name.

3) Enable deploy key in eah repository at gitlab.

wopox1337 commented 3 days ago

I think we'd better do it in the rehlds/.GitHub CI repo