diff options
| author | JP Dillingham <jp@dillingham.me> | 2025-11-22 15:42:44 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2025-11-22 15:45:42 -0600 |
| commit | 4cbf823f928ef5b1445ca2d79684a71b69a05f43 (patch) | |
| tree | d5c37f81aac181017d1914d008c3f17133a640e5 /.github | |
| parent | f310639e80b2403ec64c5e54a987593c09538f17 (diff) | |
| parent | fc90283449792f87479534d32edb5cc3e9f77790 (diff) | |
| download | slskd-4cbf823f928ef5b1445ca2d79684a71b69a05f43.tar.gz | |
Merge pull request #1536 from slskd/mirror
Add GitHub Action to mirror repository to GitLab and Codeberg
Diffstat (limited to '.github')
| -rw-r--r-- | .github/workflows/mirror.yml | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml new file mode 100644 index 00000000..3747426b --- /dev/null +++ b/.github/workflows/mirror.yml @@ -0,0 +1,77 @@ +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 + 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 + 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 + + # 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 ${{ 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 |
