From 7e4bc62bb9b96faa8d8b0cb09d5499baaa9b9662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 13 Oct 2025 11:50:42 +0200 Subject: [PATCH 1/2] Add branch check to avoid force-pushes to existing PRs --- .github/workflows/update-dependencies.yaml | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/update-dependencies.yaml b/.github/workflows/update-dependencies.yaml index cbac9992128..d0fb1e0cae1 100644 --- a/.github/workflows/update-dependencies.yaml +++ b/.github/workflows/update-dependencies.yaml @@ -44,6 +44,8 @@ jobs: name: Update ${{ matrix.group_name }} to latest runs-on: ubuntu-latest needs: configure_matrix + env: + UPDATE_BRANCH_NAME: ci/update-${{ matrix.group_name }} strategy: matrix: group_name: ${{ fromJSON(needs.configure_matrix.outputs.group_name) }} @@ -77,12 +79,36 @@ jobs: - name: Run "update dependencies" script run: npx compass-scripts update-dependencies preset-${{ matrix.group_name }} + # Conditionally performing a sparse checkout of the existing branch to compare changes + # and avoid the "create-pull-request" action force-pushing when changes aren't necessary. + # This also allows us pushing commits to the update branch to fix any breaking changes + # without risking these commits being overwritten by the action. + - name: Check existence of an existing branch + id: check-branch-exists + run: | + if git ls-remote --exit-code --heads origin ${{ env.UPDATE_BRANCH_NAME }}; then + echo "branch_exists=true" >> "$GITHUB_OUTPUT" + else + echo "branch_exists=false" >> "$GITHUB_OUTPUT" + fi + + - name: Checkout existing branch + if: steps.check-branch-exists.outputs.branch_exists == 'true' + uses: actions/checkout@v4 + with: + ref: ${{ env.UPDATE_BRANCH_NAME }} + path: existing-branch-checkout + sparse-checkout: | + package-lock.json + sparse-checkout-cone-mode: false + - name: Create Pull Request + if: steps.check-branch-exists.outputs.branch_exists == 'false' || hashFiles('package-lock.json') != hashFiles('existing-branch-checkout/package-lock.json') uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5 with: token: ${{ steps.app-token.outputs.token }} commit-message: 'chore(deps): update ${{ matrix.group_name }} to latest' - branch: ci/update-${{ matrix.group_name }} + branch: ${{ env.UPDATE_BRANCH_NAME }} title: 'chore(deps): update ${{ matrix.group_name }} to latest' labels: | no-title-validation From 1977c6df534897c6e3ff98b290db3b68e88b2114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 13 Oct 2025 14:05:11 +0200 Subject: [PATCH 2/2] Add existing-branch-checkout to gitignore --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 8ec88947dcc..b45a4e786b8 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ config/*/.npmrc .sbom .logs .evergreen/logs + +# The update-dependencies workflow does a sparse checkout +# and we don't want to include these files in the PRs it creates. +existing-branch-checkout/