-
Notifications
You must be signed in to change notification settings - Fork 0
65 lines (57 loc) · 1.95 KB
/
Copy pathmirror.yml
File metadata and controls
65 lines (57 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
name: Mirror to Codeberg
on:
push:
branches: [main]
tags: ["v*"]
workflow_dispatch:
permissions:
contents: read
# One push at a time. Concurrent mirrors race on Codeberg refs
# (`cannot lock ref ... is at X but expected Y`) and the old
# cssnr action silently ignored `force_push`.
concurrency:
group: mirror-to-codeberg
cancel-in-progress: false
jobs:
mirror:
name: Mirror
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Push main and tags to Codeberg
env:
CODEBERG_TOKEN: ${{ secrets.CODEBERG_TOKEN }}
run: |
set -euo pipefail
if [ -z "${CODEBERG_TOKEN:-}" ]; then
echo "CODEBERG_TOKEN is not available in this context; skipping."
exit 0
fi
repo="${GITHUB_REPOSITORY#*/}"
git remote add codeberg "https://thedavidweng:${CODEBERG_TOKEN}@codeberg.org/thedavidweng/${repo}.git"
push_with_retry() {
local attempt=1
while [ "$attempt" -le 4 ]; do
if git push --force "$@"; then
return 0
fi
echo "push failed (attempt ${attempt}); retrying in $((attempt * 15))s"
sleep $((attempt * 15))
attempt=$((attempt + 1))
done
return 1
}
# Push only the default branch + tags. Codeberg does not sell
# extra git quota; they ask public projects not to waste
# disk/traffic on unused remotes (see docs FAQ).
if git show-ref --verify --quiet refs/remotes/origin/main; then
push_with_retry codeberg refs/remotes/origin/main:refs/heads/main
else
push_with_retry codeberg HEAD:refs/heads/main
fi
push_with_retry codeberg --tags