55# - MIRROR_HOST: (optional) Hostname of target Git server, defaults to Codeberg
66# - MIRROR_USER: (optional) User or org name of target repo, defaults to alicia
77# - MIRROR_REPO: (optional) Name of target repo, defaults to same as source repo
8+ #
9+ # The workflow is triggered:
10+ # 1. weekly (at 01:30 on Sunday mornings) via a cron
11+ # 2. Whenever a new tagged version is published to git
12+ # 4. Or, can be triggered manually via the "Run workflow" button
813
914name : 🪞 Mirror to Codeberg
1015
1116on :
12- workflow_dispatch :
1317 schedule :
1418 - cron : ' 30 01 * * 0'
1519 push :
1620 tags : [ 'v*' ]
21+ workflow_dispatch :
22+ inputs :
23+ host : { description: 'Git host (default: git@codeberg.org)' }
24+ user : { description: 'Git user/org name (default: current repo owner)' }
25+ repo : { description: 'Repository name (default: current repo name)' }
1726
1827jobs :
1928 codeberg :
2029 runs-on : ubuntu-latest
21- env : # Get values for target repo from env vars or fallback to defaults
22- MIRROR_HOST : ${{ vars.MIRROR_HOST || 'git@codeberg.org' }}
23- MIRROR_USER : ${{ vars.MIRROR_USER || 'alicia' }}
24- MIRROR_REPO : ${{ vars.MIRROR_REPO || github.event.repository.name }}
30+ env : # Get values for target repo from inputs, env vars, or fallback to defaults
31+ MIRROR_HOST : ${{ inputs.host || vars.MIRROR_HOST || 'git@codeberg.org' }}
32+ MIRROR_USER : ${{ inputs.user || vars.MIRROR_USER || 'alicia' }}
33+ MIRROR_REPO : ${{ inputs.repo || vars.MIRROR_REPO || github.event.repository.name }}
2534 HAS_SSH : ${{ secrets.MIRROR_SSH != '' }}
2635 steps :
2736 - name : Cancel if SSH key not set
@@ -33,12 +42,46 @@ jobs:
3342 with : { fetch-depth: 0 }
3443
3544 - name : Mirror repository to target
45+ id : mirror
3646 run : |
37- set -e
47+ set -euo pipefail
48+ LOG="$RUNNER_TEMP/mirror.log"
49+
50+ # Derive host from MIRROR_HOST (handles git@host, ssh://git@host:22, etc.)
51+ HOST="${{ env.MIRROR_HOST }}"
52+ HOST="${HOST#*://}"; HOST="${HOST#*@}"; HOST="${HOST%%:*}"
53+
3854 mkdir -p ~/.ssh
3955 echo "${{ secrets.MIRROR_SSH }}" > ~/.ssh/id_rsa
4056 chmod 600 ~/.ssh/id_rsa
41- ssh-keyscan codeberg.org >> ~/.ssh/known_hosts
42- git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true
43- git push mirror --all
44- git push mirror --tags
57+ ssh-keyscan "$HOST" >> ~/.ssh/known_hosts 2>/dev/null || true
58+ {
59+ git remote add mirror ${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git || true
60+ git push mirror --all
61+ git push mirror --tags
62+ } |& tee "$LOG"
63+
64+ - name : Summarize
65+ if : always()
66+ continue-on-error : true
67+ run : |
68+ LOG="$RUNNER_TEMP/mirror.log"
69+ TARGET="${{ env.MIRROR_HOST }}:${{ env.MIRROR_USER }}/${{ env.MIRROR_REPO }}.git"
70+ if [ "${{ env.HAS_SSH }}" != "true" ]; then
71+ {
72+ echo "🚫 **Cancelled, because no SSH key was set**.<br>"
73+ echo "_Looks like you forgot to set the \`MIRROR_SSH\` secret to your encrypted private key?_"
74+ } >> "$GITHUB_STEP_SUMMARY"; exit 0
75+ fi
76+ if [ "${{ steps.mirror.outcome }}" = "success" ]; then
77+ {
78+ echo "✅ **Completed**.<br>_You can now access the repository at_ \`${TARGET}\` 🥳"
79+ echo; echo '```'; (tail -n 200 "$LOG" || true); echo '```'
80+ } >> "$GITHUB_STEP_SUMMARY"
81+ else
82+ {
83+ echo "❌ **Failed**.<br>_Because the mirror push did not complete successfully._"
84+ echo; echo '```'; ([ -f "$LOG" ] && tail -n 200 "$LOG" || echo "No log output captured."); echo '```'
85+ } >> "$GITHUB_STEP_SUMMARY"
86+ fi
87+
0 commit comments