-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (53 loc) · 2.19 KB
/
Copy pathsync.yml
File metadata and controls
55 lines (53 loc) · 2.19 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
name: Sync Forks
on:
schedule:
- cron: '0 12 * * *'
workflow_dispatch:
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Sync all forks
env:
GH_TOKEN: ${{ secrets.SYNC_UPSTREAM_REPO_TOKEN }}
OWNER: ${{ github.repository_owner }}
run: |
echo "Sync all forks"
echo "========================================="
echo " Discovering forks for ${OWNER}"
echo "========================================="
forks=$(gh api user/repos --paginate --jq ".[] | select(.fork and .owner.login == \"${OWNER}\") | .full_name")
entries=()
for repo in $forks; do
info=$(gh api "repos/${repo}" --jq '{upstream: .parent.full_name, branch: .parent.default_branch}')
upstream=$(echo "$info" | jq -r '.upstream')
branch=$(echo "$info" | jq -r '.branch')
if [ "$upstream" = "null" ]; then
echo " [SKIP] ${repo}: no parent info"
continue
fi
echo " [FOUND] ${upstream} -> ${repo} (branch: ${branch})"
entries+=("${repo}|${upstream}|${branch}")
done
echo ""
echo "========================================="
echo " Syncing ${#entries[@]} fork(s)"
echo "========================================="
for entry in "${entries[@]}"; do
IFS='|' read -r repo upstream branch <<< "$entry"
echo ""
echo "-----------------------------------------"
echo " ${upstream} -> ${repo} (${branch})"
echo "-----------------------------------------"
git clone --bare "https://x-access-token:${GH_TOKEN}@github.com/${upstream}.git" tmp-repo
cd tmp-repo
git push --force "https://x-access-token:${GH_TOKEN}@github.com/${repo}.git" \
"refs/heads/${branch}:refs/heads/${branch}" || echo " [WARN] Failed to sync ${repo}"
cd ..
rm -rf tmp-repo
echo " Done."
done
echo ""
echo "========================================="
echo " All syncs complete."
echo "========================================="