Skip to content

Commit a8086e3

Browse files
authored
chore(ci): update dependencies without force push COMPASS-9939 (#7445)
* Add branch check to avoid force-pushes to existing PRs * Add existing-branch-checkout to gitignore
1 parent a4024bd commit a8086e3

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

.github/workflows/update-dependencies.yaml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
name: Update ${{ matrix.group_name }} to latest
4545
runs-on: ubuntu-latest
4646
needs: configure_matrix
47+
env:
48+
UPDATE_BRANCH_NAME: ci/update-${{ matrix.group_name }}
4749
strategy:
4850
matrix:
4951
group_name: ${{ fromJSON(needs.configure_matrix.outputs.group_name) }}
@@ -77,12 +79,36 @@ jobs:
7779
- name: Run "update dependencies" script
7880
run: npx compass-scripts update-dependencies preset-${{ matrix.group_name }}
7981

82+
# Conditionally performing a sparse checkout of the existing branch to compare changes
83+
# and avoid the "create-pull-request" action force-pushing when changes aren't necessary.
84+
# This also allows us pushing commits to the update branch to fix any breaking changes
85+
# without risking these commits being overwritten by the action.
86+
- name: Check existence of an existing branch
87+
id: check-branch-exists
88+
run: |
89+
if git ls-remote --exit-code --heads origin ${{ env.UPDATE_BRANCH_NAME }}; then
90+
echo "branch_exists=true" >> "$GITHUB_OUTPUT"
91+
else
92+
echo "branch_exists=false" >> "$GITHUB_OUTPUT"
93+
fi
94+
95+
- name: Checkout existing branch
96+
if: steps.check-branch-exists.outputs.branch_exists == 'true'
97+
uses: actions/checkout@v4
98+
with:
99+
ref: ${{ env.UPDATE_BRANCH_NAME }}
100+
path: existing-branch-checkout
101+
sparse-checkout: |
102+
package-lock.json
103+
sparse-checkout-cone-mode: false
104+
80105
- name: Create Pull Request
106+
if: steps.check-branch-exists.outputs.branch_exists == 'false' || hashFiles('package-lock.json') != hashFiles('existing-branch-checkout/package-lock.json')
81107
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
82108
with:
83109
token: ${{ steps.app-token.outputs.token }}
84110
commit-message: 'chore(deps): update ${{ matrix.group_name }} to latest'
85-
branch: ci/update-${{ matrix.group_name }}
111+
branch: ${{ env.UPDATE_BRANCH_NAME }}
86112
title: 'chore(deps): update ${{ matrix.group_name }} to latest'
87113
labels: |
88114
no-title-validation

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ config/*/.npmrc
3535
.sbom
3636
.logs
3737
.evergreen/logs
38+
39+
# The update-dependencies workflow does a sparse checkout
40+
# and we don't want to include these files in the PRs it creates.
41+
existing-branch-checkout/

0 commit comments

Comments
 (0)