|
| 1 | +name: Dependabot Auto Merge and Resolve Lockfile Conflicts |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + types: |
| 8 | + - opened |
| 9 | + - synchronize |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + resolve-conflicts: |
| 17 | + if: github.event.pull_request.user.login == 'dependabot[bot]' |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + ref: ${{ github.event.pull_request.head.ref }} |
| 25 | + |
| 26 | + - name: Set up pnpm |
| 27 | + uses: pnpm/action-setup@v4 |
| 28 | + with: |
| 29 | + version: 9 |
| 30 | + |
| 31 | + - name: Set up Node.js |
| 32 | + uses: actions/setup-node@v4 |
| 33 | + with: |
| 34 | + node-version: "lts/*" |
| 35 | + cache: pnpm |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: pnpm install --frozen-lockfile |
| 39 | + |
| 40 | + - name: Check for lockfile conflicts |
| 41 | + id: check-conflict |
| 42 | + run: | |
| 43 | + if git diff --name-only | grep 'pnpm-lock.yaml'; then |
| 44 | + echo "Lockfile conflict detected." |
| 45 | + echo "conflict=true" >> $GITHUB_ENV |
| 46 | + else |
| 47 | + echo "No lockfile conflict." |
| 48 | + echo "conflict=false" >> $GITHUB_ENV |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Resolve lockfile conflict |
| 52 | + if: env.conflict == 'true' |
| 53 | + run: | |
| 54 | + echo "Deleting pnpm-lock.yaml..." |
| 55 | + rm pnpm-lock.yaml |
| 56 | + echo "Reinstalling dependencies..." |
| 57 | + pnpm install |
| 58 | +
|
| 59 | + - name: Commit and push updated lockfile |
| 60 | + if: env.conflict == 'true' |
| 61 | + run: | |
| 62 | + git config --global user.name "dependabot-bot" |
| 63 | + git config --global user.email "[email protected]" |
| 64 | + git add pnpm-lock.yaml |
| 65 | + git commit -m "fix: Resolve pnpm-lock.yaml conflicts" |
| 66 | + git push origin ${{ github.event.pull_request.head.ref }} |
| 67 | +
|
| 68 | + auto-merge: |
| 69 | + needs: resolve-conflicts |
| 70 | + if: github.event.pull_request.user.login == 'dependabot[bot]' && github.job == 'resolve-conflicts' && github.event.pull_request.head.ref != 'null' |
| 71 | + runs-on: ubuntu-latest |
| 72 | + |
| 73 | + steps: |
| 74 | + - name: Fetch Dependabot metadata |
| 75 | + id: metadata |
| 76 | + uses: dependabot/fetch-metadata@v1 |
| 77 | + with: |
| 78 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 79 | + |
| 80 | + - name: Enable auto-merge for Dependabot PRs |
| 81 | + run: gh pr merge --auto --merge "$PR_URL" |
| 82 | + env: |
| 83 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 84 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments