|
1 | 1 | name: Auto-merge Dependabot PRs |
2 | 2 |
|
| 3 | +# This workflow demonstrates enabling auto-merge for Dependabot PRs. |
| 4 | +# GitHub's auto-merge will handle the actual merge, and if configured |
| 5 | +# with the CI script approach in the release/CI workflows, lockfile |
| 6 | +# conflicts will be automatically resolved. |
| 7 | + |
3 | 8 | 'on': |
4 | 9 | pull_request: |
5 | 10 | types: [opened, synchronize, reopened] |
|
15 | 20 | if: github.actor == 'dependabot[bot]' |
16 | 21 |
|
17 | 22 | steps: |
18 | | - - name: Checkout PR |
19 | | - uses: actions/checkout@v4 |
20 | | - with: |
21 | | - ref: ${{ github.event.pull_request.head.ref }} |
22 | | - fetch-depth: 0 |
23 | | - |
24 | | - - uses: pnpm/action-setup@v3 |
25 | | - with: |
26 | | - version: 10 |
27 | | - |
28 | | - - name: Setup Node.js |
29 | | - uses: actions/setup-node@v4 |
30 | | - with: |
31 | | - node-version: 20 |
32 | | - cache: 'pnpm' |
33 | | - |
34 | | - - name: Auto Merge with Lockfile Fix |
35 | | - run: | |
36 | | - # --- Step 1: Configure temporary merge driver --- |
37 | | - # Define a merge driver that runs pnpm install |
38 | | - git config merge.pnpm-merge.name "pnpm-lock.yaml merge driver" |
39 | | - git config merge.pnpm-merge.driver \ |
40 | | - "pnpm install --no-frozen-lockfile" |
41 | | -
|
42 | | - # --- Step 2: Bind the strategy (key step) --- |
43 | | - # Tell Git: for pnpm-lock.yaml, use the pnpm-merge driver |
44 | | - # .git/info/attributes only affects CI, doesn't dirty codebase |
45 | | - echo "pnpm-lock.yaml merge=pnpm-merge" >> .git/info/attributes |
46 | | -
|
47 | | - # --- Step 3: Fetch and merge as usual --- |
48 | | - # If lock file conflicts, Git auto-resolves without errors |
49 | | - git fetch origin main |
50 | | - git merge origin/main --no-edit || { |
51 | | - echo "Merge failed, checking if it's a lockfile conflict..." |
52 | | - # If merge failed, check if pnpm-lock.yaml is in conflict |
53 | | - if git status | grep -q "pnpm-lock.yaml"; then |
54 | | - echo "Detected pnpm-lock.yaml conflict, regenerating..." |
55 | | - # The merge driver should have already run pnpm install |
56 | | - # Add the regenerated lockfile |
57 | | - git add pnpm-lock.yaml |
58 | | - git commit -m "chore: regenerate pnpm-lock.yaml" |
59 | | - else |
60 | | - echo "Merge conflict is not related to lockfile" |
61 | | - exit 1 |
62 | | - fi |
63 | | - } |
64 | | -
|
65 | | - # Push the merged changes |
66 | | - git push origin ${{ github.event.pull_request.head.ref }} |
67 | | -
|
68 | 23 | - name: Enable auto-merge |
69 | | - if: success() |
70 | 24 | run: | |
71 | 25 | gh pr merge --auto --squash \ |
72 | 26 | "${{ github.event.pull_request.number }}" |
|
0 commit comments