|
44 | 44 | name: Update ${{ matrix.group_name }} to latest |
45 | 45 | runs-on: ubuntu-latest |
46 | 46 | needs: configure_matrix |
| 47 | + env: |
| 48 | + UPDATE_BRANCH_NAME: ci/update-${{ matrix.group_name }} |
47 | 49 | strategy: |
48 | 50 | matrix: |
49 | 51 | group_name: ${{ fromJSON(needs.configure_matrix.outputs.group_name) }} |
@@ -77,12 +79,36 @@ jobs: |
77 | 79 | - name: Run "update dependencies" script |
78 | 80 | run: npx compass-scripts update-dependencies preset-${{ matrix.group_name }} |
79 | 81 |
|
| 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 | + |
80 | 105 | - 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') |
81 | 107 | uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5 |
82 | 108 | with: |
83 | 109 | token: ${{ steps.app-token.outputs.token }} |
84 | 110 | commit-message: 'chore(deps): update ${{ matrix.group_name }} to latest' |
85 | | - branch: ci/update-${{ matrix.group_name }} |
| 111 | + branch: ${{ env.UPDATE_BRANCH_NAME }} |
86 | 112 | title: 'chore(deps): update ${{ matrix.group_name }} to latest' |
87 | 113 | labels: | |
88 | 114 | no-title-validation |
|
0 commit comments