diff --git a/.github/workflows/update-portage-stable-packages-from-list.yaml b/.github/workflows/update-gentoo-submodule.yaml similarity index 53% rename from .github/workflows/update-portage-stable-packages-from-list.yaml rename to .github/workflows/update-gentoo-submodule.yaml index 8a45e31f2bb..000b6e22ca4 100644 --- a/.github/workflows/update-portage-stable-packages-from-list.yaml +++ b/.github/workflows/update-gentoo-submodule.yaml @@ -12,6 +12,7 @@ jobs: uses: actions/checkout@v7 with: token: ${{ secrets.BOT_PR_TOKEN }} + ref: ${{ github.event.repository.default_branch }} path: scripts sparse-checkout: | .gitmodules @@ -19,23 +20,39 @@ jobs: sparse-checkout-cone-mode: false - name: Update Gentoo submodule id: update-gentoo + working-directory: scripts env: WORK_SCRIPTS_DIR: "${{ github.workspace }}/scripts" run: | set -euo pipefail - source scripts/.github/workflows/common.sh + source .github/workflows/common.sh prepare_git_repo submodule=sdk_container/src/third_party/gentoo - url=$(git -C "${WORK_SCRIPTS_DIR}" config --file .gitmodules --get "submodule.${submodule}.url") - branch=$(git -C "${WORK_SCRIPTS_DIR}" config --file .gitmodules --get "submodule.${submodule}.branch") + 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}") short_commit=${latest_commit:0:12} - git -C "${WORK_SCRIPTS_DIR}" update-index --cacheinfo "160000,${latest_commit},${submodule}" - if git -C "${WORK_SCRIPTS_DIR}" diff --cached --quiet -- "${submodule}"; then + git update-index --cacheinfo "160000,${latest_commit},${submodule}" + if git diff --cached --quiet -- "${submodule}"; then echo 'UPDATE_NEEDED=0' >>"${GITHUB_OUTPUT}" exit 0 fi - git -C "${WORK_SCRIPTS_DIR}" commit --signoff -m "gentoo: Update to ${short_commit}" + git commit --signoff -m "gentoo: Update to ${short_commit}" + previous_branch="buildbot/update-gentoo-submodule" + default_branch="${{ github.event.repository.default_branch }}" + if git fetch --no-tags --no-recurse-submodules --depth=1000 origin \ + "+refs/heads/${previous_branch}:refs/remotes/origin/${previous_branch}"; then + git fetch --no-tags --no-recurse-submodules --deepen=1000 origin "${default_branch}" + additional_commits=$(git rev-list --reverse --no-merges \ + "origin/${default_branch}..origin/${previous_branch}" -- ":^:${submodule}") + if [[ -n "${additional_commits}" ]]; then + mapfile -t commits <<< "${additional_commits}" + if ! git cherry-pick "${commits[@]}"; then + echo '::warning::Could not replay additional commits; keeping only the Gentoo submodule update.' + git cherry-pick --abort + fi + fi + fi cleanup_repo echo 'UPDATE_NEEDED=1' >>"${GITHUB_OUTPUT}" echo "LATEST_COMMIT=${latest_commit}" >>"${GITHUB_OUTPUT}"