Skip to content

Commit 58173d8

Browse files
fix(ci): drop brittle PAT-based dependabot automerge (#901)
* fix(ci): drop brittle PAT-based dependabot automerge * fix(ci): pin merge sha to prevent TOCTOU race in dependabot automerge
1 parent bf0fc84 commit 58173d8

1 file changed

Lines changed: 39 additions & 7 deletions

File tree

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
name: Dependabot Auto-merge
22

3-
# NOTE: `merge-me-action` still needs the bot PAT here.
4-
# Using `secrets.GITHUB_TOKEN` fails on `workflow_run` with
5-
# "Resource not accessible by integration" when the action queries
6-
# branch protection rules over GraphQL.
7-
# See: https://github.com/ridedott/merge-me-action/issues/1581
3+
# Run in the trusted `workflow_run` context and merge Dependabot PRs directly
4+
# with the repository token instead of depending on an external PAT.
85

96
on:
107
workflow_run:
@@ -14,6 +11,10 @@ on:
1411
# List all required workflow names here.
1512
- Build
1613

14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
1718
jobs:
1819
auto_merge:
1920
name: Auto-merge
@@ -24,6 +25,37 @@ jobs:
2425
github.actor == 'dependabot[bot]'
2526
2627
steps:
27-
- uses: ridedott/merge-me-action@bb09d7d3c3504d3837816cc4eb821e663dc7ffde
28+
- uses: actions/github-script@v9
2829
with:
29-
GITHUB_TOKEN: ${{ secrets.AWBOT_GH_TOKEN }}
30+
script: |
31+
const pr = context.payload.workflow_run.pull_requests?.[0];
32+
if (!pr) {
33+
core.setFailed("No pull request found in workflow_run payload.");
34+
return;
35+
}
36+
37+
const { data: pull } = await github.rest.pulls.get({
38+
owner: context.repo.owner,
39+
repo: context.repo.repo,
40+
pull_number: pr.number,
41+
});
42+
43+
if (pull.state !== "open") {
44+
core.info(`PR #${pull.number} is already ${pull.state}; nothing to do.`);
45+
return;
46+
}
47+
48+
if (pull.draft) {
49+
core.info(`PR #${pull.number} is a draft; skipping.`);
50+
return;
51+
}
52+
53+
await github.rest.pulls.merge({
54+
owner: context.repo.owner,
55+
repo: context.repo.repo,
56+
pull_number: pull.number,
57+
merge_method: "squash",
58+
sha: context.payload.workflow_run.head_sha,
59+
});
60+
61+
core.info(`Merged Dependabot PR #${pull.number}.`);

0 commit comments

Comments
 (0)