Skip to content

Commit f2bf703

Browse files
committed
ci: add workflow that syncs repository branches
Signed-off-by: You-Sheng Yang <vicamo@gmail.com>
1 parent dee6c08 commit f2bf703

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
try_run:
6+
description: 'Do not actually push new HEADs'
7+
requited: true
8+
type: boolean
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
sync-repo:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v6
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Enumerate tracking branches
22+
run: |
23+
declare -a branches=($(git branch -a|grep canonical/linux|cut -d/ -f3,4))
24+
echo "TRACKING_SOURCES=${branches[*]}" | tee -a "${GITHUB_ENV}"
25+
26+
- name: Fetch remotes
27+
run: |
28+
git remote add noble https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/noble
29+
git remote add oem-noble https://git.launchpad.net/~canonical-kernel/ubuntu/+source/linux-oem/+git/noble
30+
git fetch -p --all
31+
32+
- name: Collect updating refs
33+
run: |
34+
declare -a refspecs
35+
36+
# Latest
37+
for source in ${TRACKING_SOURCES}; do
38+
series="${source#*/}"
39+
package="${source%/*}"
40+
41+
remote_branch=
42+
flavor=
43+
case "${package}" in
44+
linux)
45+
remote_branch="${series}/master-next"
46+
flavor=master
47+
tag_prefix=Ubuntu-
48+
;;
49+
linux-hwe-*)
50+
remote_branch="${series}/${package#linux-}-next"
51+
flavor=hwe
52+
tag_prefix="Ubuntu-${package#linux-}"
53+
;;
54+
linux-oem-*)
55+
remote_branch="oem-${series}/${package#linux-}-next"
56+
flavor=oem
57+
tag_prefix="Ubuntu-${package#linux-}"
58+
;;
59+
*)
60+
echo "Unsupported source ${source}" >&2; exit 1
61+
;;
62+
esac
63+
64+
versions=($(git show ${remote_branch}:debian.${flavor}/changelog | awk "/^${package} / { print \$2 }" | tr -d '()' | tr '~' '_'))
65+
latest_tag=
66+
for version in "${versions[@]}"; do
67+
latest_tag="$(git tag -l | { grep "^${tag_prefix}-${version}\$" || true; })"
68+
if [ -n "${latest_tag}" ]; then
69+
refspecs+=("${latest_tag}:refs/heads/${source}/latest")
70+
break
71+
fi
72+
done
73+
74+
case "${package}" in
75+
linux)
76+
refspecs+=("${series}/master-next:refs/heads/${source}/staging")
77+
;;
78+
linux-hwe-*)
79+
refspecs+=("${series}/${package#linux-}-next:refs/heads/${source}/staging")
80+
;;
81+
linux-oem-*)
82+
refspecs+=("oem-${series}/${package#linux-}-next:refs/heads/${source}/staging")
83+
;;
84+
*)
85+
echo "Unsupported source ${source}" >&2; exit 1
86+
;;
87+
esac
88+
done
89+
90+
echo "PUSH_REFSPECS=${refspecs[*]}" | tee -a "${GITHUB_ENV}"
91+
92+
- name: Push changes
93+
if: ${{ !inputs.try_run && contains(env.PUSH_REFSPECS, ':') }}
94+
run: |
95+
github_server_proto="${GITHUB_SERVER_URL%%//*}"
96+
github_server_host="${GITHUB_SERVER_URL#*//}"
97+
remote="${github_server_proto}//oauth2:${{ secrets.REPO_SYNC_TOKEN }}@${github_server_host}/${GITHUB_REPOSITORY}.git"
98+
99+
echo git push --force --atomic "${remote}" ${PUSH_REFSPECS}

0 commit comments

Comments
 (0)