Skip to content

Commit 2d92975

Browse files
Merge remote-tracking branch 'origin/main' into main
2 parents c3fbb69 + a10f841 commit 2d92975

File tree

1 file changed

+43
-23
lines changed

1 file changed

+43
-23
lines changed

.github/workflows/auto_merge.yml

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
11
# https://docs.github.com/en/code-security/dependabot/working-with-dependabot/automating-dependabot-with-github-actions#approve-a-pull-request
2+
# https://nicolasiensen.github.io/2022-07-23-automating-dependency-updates-with-dependabot-github-auto-merge-and-github-actions/
23

34
name: auto_merge
4-
on: # pull_request, push, workflow_dispatch
5+
6+
on: # pull_request, pull_request_target, push, workflow_dispatch
57
pull_request:
8+
pull_request_target:
69
workflow_dispatch:
710
push:
811
release:
912
types: [published]
1013

1114
permissions:
1215
pull-requests: write
16+
contents: write
1317

1418
jobs:
15-
dependabot:
19+
review-dependabot-pr:
1620
runs-on: ubuntu-latest
17-
if: ${{ github.actor == 'dependabot[bot]' }}
21+
if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
1822
steps:
23+
- name: Check rate limit
24+
id: rate-limit
25+
shell: bash
26+
run: |
27+
RATE_LIMIT=$(gh api /rate_limit | jq -r '.resources.core.remaining')
28+
echo "::set-output name=remaining::$RATE_LIMIT"
29+
if [[ "$RATE_LIMIT" -lt 10 ]]; then
30+
RESET_TIME=$(gh api /rate_limit | jq -r '.resources.core.reset')
31+
echo "::set-output name=reset_time::$RESET_TIME"
32+
echo "Rate limit is low ($RATE_LIMIT). Waiting until $RESET_TIME"
33+
sleep $((RESET_TIME - $(date +%s)))
34+
fi
1935
- name: Dependabot metadata
20-
id: metadata
21-
uses: dependabot/fetch-metadata@v1.1.1
22-
with:
23-
github-token: "${{ secrets.GITHUB_TOKEN }}"
24-
- name: Approve a PR
25-
run: gh pr review --approve "$PR_URL"
36+
id: dependabot-metadata
37+
uses: dependabot/fetch-metadata@v1.3.1
38+
- name: Enable auto-merge for Dependabot PRs
39+
run: gh pr merge --auto --merge "$PR_URL"
2640
env:
27-
PR_URL: ${{ github.event.pull_request.html_url }}
28-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
- name: Merge a PR
30-
run: gh pr merge "$PR_URL" --auto --squash
41+
PR_URL: ${{github.event.pull_request.html_url}}
42+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
43+
- name: Approve patch and minor updates
44+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-patch' || steps.dependabot-metadata.outputs.update-type == 'version-update:semver-minor'}}
45+
run: gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a patch or minor update**"
3146
env:
32-
PR_URL: ${{ github.event.pull_request.html_url }}
33-
auto-rebase:
34-
name: rebase dependabot PRs
35-
runs-on: ubuntu-latest
36-
if: github.ref == 'refs/heads/main' || github.event == 'release'
37-
timeout-minutes: 5
38-
steps:
39-
- name: rebase
40-
uses: "bbeesley/gha-auto-dependabot-rebase@main"
47+
PR_URL: ${{github.event.pull_request.html_url}}
48+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
49+
- name: Approve major updates of development dependencies
50+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:development'}}
51+
run: gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a major update of a dependency used only in development**"
52+
env:
53+
PR_URL: ${{github.event.pull_request.html_url}}
54+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
55+
- name: Comment on major updates of non-development dependencies
56+
if: ${{steps.dependabot-metadata.outputs.update-type == 'version-update:semver-major' && steps.dependabot-metadata.outputs.dependency-type == 'direct:production'}}
57+
run: |
58+
gh pr comment $PR_URL --body "I'm **not approving** this PR because **it includes a major update of a dependency used in production**"
59+
gh pr edit $PR_URL --add-label "requires-manual-qa"
4160
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
PR_URL: ${{github.event.pull_request.html_url}}
62+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

0 commit comments

Comments
 (0)