From ce6a9863bd5824e326b8760576fc1c67c8129894 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Nov 2025 15:28:14 -0600 Subject: add mirror workflow --- .github/workflows/mirror.yml | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/mirror.yml (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 00000000..d20d0e2c --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,87 @@ +name: Mirror Repository + +on: + push: + branches: + - '**' # Trigger on push to any branch + delete: + branches: + - '**' # Trigger when branches are deleted + +jobs: + mirror: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch full history for proper mirroring + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure SSH + env: + SSH_KEY: ${{ secrets.GIT_MIRROR_SSH_KEY }} + run: | + if [ -z "$SSH_KEY" ]; then + echo "⚠️ SSH key not configured. Skipping mirror sync." + echo "Please set GIT_MIRROR_SSH_KEY secret to enable mirroring." + exit 1 + fi + + # Set up SSH key + mkdir -p ~/.ssh + echo "$SSH_KEY" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + + # Add known hosts to avoid SSH prompts + ssh-keyscan gitlab.com >> ~/.ssh/known_hosts + ssh-keyscan codeberg.org >> ~/.ssh/known_hosts + + # Configure Git + git config --global user.name "GitHub Actions" + git config --global user.email "actions@github.com" + + - name: Mirror to GitLab + run: | + echo "🔄 Syncing to GitLab..." + # Add GitLab remote with SSH + git remote add gitlab git@gitlab.com:slskd/slskd.git + + # Push all branches and tags to GitLab + git push gitlab --all --force + git push gitlab --tags --force + + echo "✅ Successfully synced to GitLab" + + - name: Mirror to Codeberg + run: | + echo "🔄 Syncing to Codeberg..." + # Add Codeberg remote with SSH + git remote add codeberg git@codeberg.org:slskd/slskd.git + + # Push all branches and tags to Codeberg + git push codeberg --all --force + git push codeberg --tags --force + + echo "✅ Successfully synced to Codeberg" + + - name: Handle branch deletion + if: github.event_name == 'delete' && github.event.ref_type == 'branch' + run: | + DELETED_BRANCH="${{ github.event.ref }}" + echo "🗑️ Branch '$DELETED_BRANCH' was deleted, syncing deletion to mirrors..." + + # Delete branch from GitLab + git push git@gitlab.com:slskd/slskd.git --delete "$DELETED_BRANCH" || echo "Branch may not exist on GitLab" + + # Delete branch from Codeberg + git push git@codeberg.org:slskd/slskd.git --delete "$DELETED_BRANCH" || echo "Branch may not exist on Codeberg" + + - name: Summary + run: | + echo "🎉 Repository mirroring completed!" + echo "📊 Summary:" + echo " - GitHub: ✅ Source repository" + echo " - GitLab: ✅ Synced" + echo " - Codeberg: ✅ Synced" \ No newline at end of file -- cgit v1.2.3 From fc90283449792f87479534d32edb5cc3e9f77790 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 22 Nov 2025 15:41:32 -0600 Subject: use a matrix --- .github/workflows/mirror.yml | 69 +++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index d20d0e2c..7a52415b 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -11,7 +11,17 @@ on: jobs: mirror: runs-on: ubuntu-latest - + strategy: + matrix: + target: + - name: GitLab + host: gitlab.com + repo: git@gitlab.com:slskd/slskd.git + - name: Codeberg + host: codeberg.org + repo: git@codeberg.org:slskd/slskd.git + fail-fast: false # Continue with other mirrors even if one fails + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -34,54 +44,35 @@ jobs: echo "$SSH_KEY" > ~/.ssh/id_ed25519 chmod 600 ~/.ssh/id_ed25519 - # Add known hosts to avoid SSH prompts - ssh-keyscan gitlab.com >> ~/.ssh/known_hosts - ssh-keyscan codeberg.org >> ~/.ssh/known_hosts + # Start SSH agent and add key + eval "$(ssh-agent -s)" + ssh-add ~/.ssh/id_ed25519 + + # Add known host to avoid SSH prompts + ssh-keyscan ${{ matrix.target.host }} >> ~/.ssh/known_hosts # Configure Git git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" - - name: Mirror to GitLab + - name: Mirror to ${{ matrix.target.name }} + if: github.event_name != 'delete' run: | - echo "🔄 Syncing to GitLab..." - # Add GitLab remote with SSH - git remote add gitlab git@gitlab.com:slskd/slskd.git - - # Push all branches and tags to GitLab - git push gitlab --all --force - git push gitlab --tags --force + echo "🔄 Syncing to ${{ matrix.target.name }}..." + # Add remote with SSH + git remote add mirror ${{ matrix.target.repo }} - echo "✅ Successfully synced to GitLab" - - - name: Mirror to Codeberg - run: | - echo "🔄 Syncing to Codeberg..." - # Add Codeberg remote with SSH - git remote add codeberg git@codeberg.org:slskd/slskd.git + # Push all branches and tags + git push mirror --all --force + git push mirror --tags --force - # Push all branches and tags to Codeberg - git push codeberg --all --force - git push codeberg --tags --force + echo "✅ Successfully synced to ${{ matrix.target.name }}" - echo "✅ Successfully synced to Codeberg" - - - name: Handle branch deletion + - name: Handle branch deletion on ${{ matrix.target.name }} if: github.event_name == 'delete' && github.event.ref_type == 'branch' run: | DELETED_BRANCH="${{ github.event.ref }}" - echo "🗑️ Branch '$DELETED_BRANCH' was deleted, syncing deletion to mirrors..." - - # Delete branch from GitLab - git push git@gitlab.com:slskd/slskd.git --delete "$DELETED_BRANCH" || echo "Branch may not exist on GitLab" + echo "🗑️ Branch '$DELETED_BRANCH' was deleted, syncing deletion to ${{ matrix.target.name }}..." - # Delete branch from Codeberg - git push git@codeberg.org:slskd/slskd.git --delete "$DELETED_BRANCH" || echo "Branch may not exist on Codeberg" - - - name: Summary - run: | - echo "🎉 Repository mirroring completed!" - echo "📊 Summary:" - echo " - GitHub: ✅ Source repository" - echo " - GitLab: ✅ Synced" - echo " - Codeberg: ✅ Synced" \ No newline at end of file + # Delete branch from mirror + git push ${{ matrix.target.repo }} --delete "$DELETED_BRANCH" || echo "Branch may not exist on ${{ matrix.target.name }}" \ No newline at end of file -- cgit v1.2.3 From fd35d5cdb9283a65ec34d2010cd9ec1562f15c98 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 10:52:29 -0600 Subject: tweak mirror --- .github/workflows/mirror.yml | 56 ++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 18 deletions(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 3747426b..132c4d7c 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -7,6 +7,25 @@ on: delete: branches: - '**' # Trigger when branches are deleted + workflow_dispatch: # Allow manual triggering from GitHub UI + inputs: + target: + description: 'Target to mirror to' + required: false + default: 'all' + type: choice + options: + - all + - GitLab + - Codeberg + delay: + description: 'Delay in seconds before mirroring' + required: false + default: '0' + +concurrency: + group: mirror-sync + cancel-in-progress: false jobs: mirror: @@ -23,7 +42,13 @@ jobs: fail-fast: false # Continue with other mirrors even if one fails steps: + - name: Wait for things to settle + run: | + echo "⏳ Waiting 15 seconds..." + sleep 15 + - name: Checkout repository + if: github.event_name != 'delete' # Skip checkout for delete events uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch full history for proper mirroring @@ -57,21 +82,16 @@ jobs: - name: Mirror to ${{ matrix.target.name }} run: | - echo "🔄 Syncing to ${{ matrix.target.name }}..." - # Add remote with SSH - git remote add mirror ${{ matrix.target.repo }} - - # Push all branches and tags - git push mirror --all --force - git push mirror --tags --force - - echo "✅ Successfully synced to ${{ matrix.target.name }}" - - - name: Handle branch deletion on ${{ matrix.target.name }} - if: github.event_name == 'delete' && github.event.ref_type == 'branch' - run: | - DELETED_BRANCH="${{ github.event.ref }}" - echo "🗑️ Branch '$DELETED_BRANCH' was deleted, syncing deletion to ${{ matrix.target.name }}..." - - # Delete branch from mirror - git push ${{ matrix.target.repo }} --delete "$DELETED_BRANCH" || echo "Branch may not exist on ${{ matrix.target.name }}" \ No newline at end of file + echo "🔄 Mirroring repository to ${{ matrix.target.name }}..." + + # Clone the GitHub repository as a mirror (bare repo with all refs) + git clone --mirror https://github.com/${{ github.repository }}.git mirror-repo + cd mirror-repo + + # Set the push URL to the target repository + git remote set-url --push origin ${{ matrix.target.repo }} + + # Push everything to the mirror (handles all branches, tags, and deletions) + git push --mirror + + echo "✅ Successfully mirrored to ${{ matrix.target.name }}" \ No newline at end of file -- cgit v1.2.3 From b0175a8980e4201535df2cf14fdd84cf9e857efc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 10:57:17 -0600 Subject: mirror tweak --- .github/workflows/mirror.yml | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 132c4d7c..ed94f14a 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -7,21 +7,7 @@ on: delete: branches: - '**' # Trigger when branches are deleted - workflow_dispatch: # Allow manual triggering from GitHub UI - inputs: - target: - description: 'Target to mirror to' - required: false - default: 'all' - type: choice - options: - - all - - GitLab - - Codeberg - delay: - description: 'Delay in seconds before mirroring' - required: false - default: '0' + workflow_dispatch: concurrency: group: mirror-sync @@ -42,18 +28,6 @@ jobs: fail-fast: false # Continue with other mirrors even if one fails steps: - - name: Wait for things to settle - run: | - echo "⏳ Waiting 15 seconds..." - sleep 15 - - - name: Checkout repository - if: github.event_name != 'delete' # Skip checkout for delete events - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch full history for proper mirroring - token: ${{ secrets.GITHUB_TOKEN }} - - name: Configure SSH env: SSH_KEY: ${{ secrets.GIT_MIRROR_SSH_KEY }} -- cgit v1.2.3 From c6e374fe2c192dfea167eb81994f745f8f2177c9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 11:29:36 -0600 Subject: mirror tweak again --- .github/workflows/mirror.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index ed94f14a..2bf5578c 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -54,18 +54,12 @@ jobs: git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" + - name: Check out GitHub Repository + run: | + git clone --mirror git@github.com:slskd/slskd + git for-each-ref --format="delete %(refname)" refs/pull refs/original | git update-ref --stdin + - name: Mirror to ${{ matrix.target.name }} run: | - echo "🔄 Mirroring repository to ${{ matrix.target.name }}..." - - # Clone the GitHub repository as a mirror (bare repo with all refs) - git clone --mirror https://github.com/${{ github.repository }}.git mirror-repo - cd mirror-repo - - # Set the push URL to the target repository - git remote set-url --push origin ${{ matrix.target.repo }} - - # Push everything to the mirror (handles all branches, tags, and deletions) - git push --mirror - - echo "✅ Successfully mirrored to ${{ matrix.target.name }}" \ No newline at end of file + git remote add mirror ${{ matrix.target.repo }} + git push --mirror mirror \ No newline at end of file -- cgit v1.2.3 From 5ccb3d1350f466b6c3f8ff00791cc56dafd3a4c5 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 11:43:08 -0600 Subject: mirror --- .github/workflows/mirror.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 2bf5578c..3a949fb8 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -55,8 +55,12 @@ jobs: git config --global user.email "actions@github.com" - name: Check out GitHub Repository + uses: actions/checkout@v6 + with: + fetch-depth: 0 + + - name: Clean up hidden GitHub refs run: | - git clone --mirror git@github.com:slskd/slskd git for-each-ref --format="delete %(refname)" refs/pull refs/original | git update-ref --stdin - name: Mirror to ${{ matrix.target.name }} -- cgit v1.2.3 From 23c16c7cc029341fcce54dcf81c857b113768491 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 17:56:03 -0600 Subject: mirror again --- .github/workflows/mirror.yml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 3a949fb8..0d11a6b7 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -54,16 +54,12 @@ jobs: git config --global user.name "GitHub Actions" git config --global user.email "actions@github.com" - - name: Check out GitHub Repository - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Clean up hidden GitHub refs + - name: Check out repo run: | - git for-each-ref --format="delete %(refname)" refs/pull refs/original | git update-ref --stdin + git clone --bare https://github.com/slskd/slskd slskd - name: Mirror to ${{ matrix.target.name }} + working-directory: ./slskd run: | git remote add mirror ${{ matrix.target.repo }} git push --mirror mirror \ No newline at end of file -- cgit v1.2.3 From 8792e614e7c3b181bdb37bb6b94bce08f04ab256 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 27 Nov 2025 18:29:03 -0600 Subject: mirror? --- .github/workflows/mirror.yml | 1 + 1 file changed, 1 insertion(+) (limited to '.github/workflows') diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 0d11a6b7..f3aaa95f 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -1,6 +1,7 @@ name: Mirror Repository on: + create: push: branches: - '**' # Trigger on push to any branch -- cgit v1.2.3