From f2233f45cdc651f954dc8c908dfc600967293ba4 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 19 Nov 2026 14:54:01 +0000 Subject: [PATCH 1/2] .github: Change Gentoo update job from 4am Sun-Thu to Mon-Fri We want it ready on the morning of a weekday. Signed-off-by: James Le Cuirot --- .github/workflows/update-gentoo-submodule.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-gentoo-submodule.yaml b/.github/workflows/update-gentoo-submodule.yaml index 000b6e22ca4..66fb0ecacd7 100644 --- a/.github/workflows/update-gentoo-submodule.yaml +++ b/.github/workflows/update-gentoo-submodule.yaml @@ -1,7 +1,7 @@ name: Keep Gentoo submodule updated on: schedule: - - cron: '0 4 * * 0-4' + - cron: '0 4 * * 1-5' workflow_dispatch: jobs: From c8a401e0e692bbbf3933b01ca2221c646891f895 Mon Sep 17 00:00:00 2001 From: James Le Cuirot Date: Thu, 19 Nov 2026 15:09:18 +0000 Subject: [PATCH 2/2] .github: Sync flatcar-hub/gentoo from our job instead of doing it there Periodically doing this in the remote repo has proven unreliable. Let's do it less frequently, just as needed, from the update job that consumes the repo. This job runs on the CNCF runners too, which will hopefully be more reliable. Modifying the remote repo requires authentication, which is handled by the new Flatcar Hub Automation app. Note that this was entirely written by Copilot. Signed-off-by: James Le Cuirot --- .github/workflows/rebase-gentoo.sh | 62 ++++++++++++++ .../workflows/update-gentoo-submodule.yaml | 82 +++++++++++++++++-- 2 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/rebase-gentoo.sh diff --git a/.github/workflows/rebase-gentoo.sh b/.github/workflows/rebase-gentoo.sh new file mode 100644 index 00000000000..258c669b321 --- /dev/null +++ b/.github/workflows/rebase-gentoo.sh @@ -0,0 +1,62 @@ +#!/bin/bash + +set -euo pipefail + +source "${GHA_SCRIPTS_DIR}/.github/workflows/common.sh" +prepare_git_repo + +: "${BRANCH:?Set BRANCH to the Gentoo upstream branch.}" + +latest_commit=$(git rev-parse HEAD) +echo "LATEST_COMMIT=${latest_commit}" >>"${GITHUB_OUTPUT}" +echo "SHORT_COMMIT=${latest_commit:0:12}" >>"${GITHUB_OUTPUT}" + +tracking_refspec='+refs/heads/tracking-*:refs/remotes/origin/tracking-*' +branch_refspec="+refs/heads/${BRANCH}:refs/remotes/origin/${BRANCH}" +depth=1000 +# Including the base branch also makes this fetch succeed when no tracking branches exist. +git fetch --filter=blob:none --no-tags --no-recurse-submodules --depth="${depth}" \ + origin "${branch_refspec}" "${tracking_refspec}" +tracking_branches=$(git for-each-ref --format='%(objectname) %(refname:strip=3)' refs/remotes/origin/) + +while read -r previous_commit branch; do + [[ "${branch}" == tracking-* ]] || continue + + history_size=0 + while true; do + if base=$(git merge-base "${latest_commit}" "${previous_commit}"); then + break + else + status=$? + if [[ "${status}" != 1 ]]; then + exit "${status}" + fi + fi + current_history_size=$(git rev-list --count "${latest_commit}" "${previous_commit}") + if [[ "${current_history_size}" == "${history_size}" || + $(git rev-parse --is-shallow-repository) == false ]]; then + echo "::warning::Cannot rebase ${branch}: no common ancestor with ${BRANCH}; remote branch unchanged." + continue 2 + fi + history_size="${current_history_size}" + # Deepen the original tips, not potentially rewritten remote branches. + git fetch --filter=blob:none --no-tags --no-recurse-submodules --deepen="${depth}" \ + origin "${latest_commit}" "${previous_commit}" + depth=$((depth * 2)) + done + + git checkout --no-track -b "${branch}" "${previous_commit}" + if ! git rebase --onto "${latest_commit}" "${base}"; then + if [[ -z $(git ls-files --unmerged) ]]; then + echo "::error::Rebasing ${branch} failed without merge conflicts; inspect the Git error above." + exit 1 + fi + git rebase --abort + echo "::warning::Cannot rebase ${branch} onto ${BRANCH}: resolve the conflicts manually; remote branch unchanged." + continue + fi + if [[ $(git rev-parse HEAD) != "${previous_commit}" ]]; then + git push --force-with-lease="refs/heads/${branch}:${previous_commit}" \ + origin "HEAD:refs/heads/${branch}" + fi +done <<<"${tracking_branches}" diff --git a/.github/workflows/update-gentoo-submodule.yaml b/.github/workflows/update-gentoo-submodule.yaml index 66fb0ecacd7..593c6bb95ab 100644 --- a/.github/workflows/update-gentoo-submodule.yaml +++ b/.github/workflows/update-gentoo-submodule.yaml @@ -5,7 +5,77 @@ on: workflow_dispatch: jobs: + sync-gentoo: + runs-on: ubuntu-latest + outputs: + repository: ${{ steps.gentoo.outputs.repository }} + branch: ${{ steps.gentoo.outputs.branch }} + latest_commit: ${{ steps.rebase.outputs.LATEST_COMMIT }} + short_commit: ${{ steps.rebase.outputs.SHORT_COMMIT }} + steps: + - name: Check out scripts + uses: actions/checkout@v7 + with: + path: scripts + sparse-checkout: | + .gitmodules + .github/workflows/common.sh + .github/workflows/rebase-gentoo.sh + sparse-checkout-cone-mode: false + - name: Determine Gentoo repository and branch + id: gentoo + working-directory: scripts + run: | + set -euo pipefail + submodule=sdk_container/src/third_party/gentoo + url=$(git config --file .gitmodules --get "submodule.${submodule}.url") + branch=$(git config --file .gitmodules --get "submodule.${submodule}.branch") + if [[ ! "${url}" =~ ^https://github\.com/([^/]+)/([^/]+)\.git$ ]]; then + echo "::error::Expected a GitHub HTTPS submodule URL ending in .git; got ${url}." + exit 1 + fi + { + echo "owner=${BASH_REMATCH[1]}" + echo "name=${BASH_REMATCH[2]}" + echo "repository=${BASH_REMATCH[1]}/${BASH_REMATCH[2]}" + echo "branch=${branch}" + } >>"${GITHUB_OUTPUT}" + - name: Generate Gentoo update token + id: gentoo-token + uses: actions/create-github-app-token@v3 + with: + client-id: ${{ vars.FLATCAR_HUB_APP_CLIENT_ID }} + private-key: ${{ secrets.FLATCAR_HUB_APP_PRIVATE_KEY }} + owner: ${{ steps.gentoo.outputs.owner }} + repositories: ${{ steps.gentoo.outputs.name }} + permission-contents: write + - name: Sync Gentoo fork + env: + GH_TOKEN: ${{ steps.gentoo-token.outputs.token }} + REPOSITORY: ${{ steps.gentoo.outputs.repository }} + BRANCH: ${{ steps.gentoo.outputs.branch }} + run: gh repo sync "${REPOSITORY}" --branch "${BRANCH}" + - name: Check out Gentoo history + uses: actions/checkout@v7 + with: + repository: ${{ steps.gentoo.outputs.repository }} + ref: ${{ steps.gentoo.outputs.branch }} + token: ${{ steps.gentoo-token.outputs.token }} + path: gentoo + # Rebasing only needs blobs for changed paths, not the entire Gentoo tree. + sparse-checkout: '!/*' + sparse-checkout-cone-mode: false + - name: Rebase Gentoo tracking branches + id: rebase + working-directory: gentoo + env: + WORK_SCRIPTS_DIR: "${{ github.workspace }}/gentoo" + GHA_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + BRANCH: ${{ steps.gentoo.outputs.branch }} + run: bash ../scripts/.github/workflows/rebase-gentoo.sh + keep-gentoo-updated: + needs: sync-gentoo runs-on: ubuntu-latest steps: - name: Check out scripts @@ -15,7 +85,6 @@ jobs: ref: ${{ github.event.repository.default_branch }} path: scripts sparse-checkout: | - .gitmodules .github/workflows/common.sh sparse-checkout-cone-mode: false - name: Update Gentoo submodule @@ -23,14 +92,13 @@ jobs: working-directory: scripts env: WORK_SCRIPTS_DIR: "${{ github.workspace }}/scripts" + LATEST_COMMIT: ${{ needs.sync-gentoo.outputs.latest_commit }} run: | set -euo pipefail source .github/workflows/common.sh prepare_git_repo submodule=sdk_container/src/third_party/gentoo - url=$(git config --file .gitmodules --get "submodule.${submodule}.url") - branch=$(git config --file .gitmodules --get "submodule.${submodule}.branch") - read -r latest_commit _ < <(git ls-remote --exit-code "${url}" "refs/heads/${branch}") + latest_commit="${LATEST_COMMIT}" short_commit=${latest_commit:0:12} git update-index --cacheinfo "160000,${latest_commit},${submodule}" if git diff --cached --quiet -- "${submodule}"; then @@ -55,8 +123,6 @@ jobs: fi cleanup_repo echo 'UPDATE_NEEDED=1' >>"${GITHUB_OUTPUT}" - echo "LATEST_COMMIT=${latest_commit}" >>"${GITHUB_OUTPUT}" - echo "SHORT_COMMIT=${short_commit}" >>"${GITHUB_OUTPUT}" - name: Create pull request uses: peter-evans/create-pull-request@v8 if: steps.update-gentoo.outputs.UPDATE_NEEDED == 1 @@ -65,6 +131,6 @@ jobs: path: scripts branch: buildbot/update-gentoo-submodule delete-branch: true - title: Update gentoo submodule to ${{ steps.update-gentoo.outputs.SHORT_COMMIT }} - body: Update `sdk_container/src/third_party/gentoo` to flatcar-hub/gentoo@${{ steps.update-gentoo.outputs.LATEST_COMMIT }}. + title: Update gentoo submodule to ${{ needs.sync-gentoo.outputs.short_commit }} + body: Update `sdk_container/src/third_party/gentoo` to ${{ needs.sync-gentoo.outputs.repository }}@${{ needs.sync-gentoo.outputs.latest_commit }}. labels: auto-ci,jenkins-ci,main