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