-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (83 loc) · 3.49 KB
/
LOCAL-dependabot-approve-and-auto-merge.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
name: Dependabot Pull Request Approve and Merge
on: pull_request_target
permissions:
pull-requests: write
contents: write
jobs:
pull-request-title-change:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v4
- name: 'Fetch Dependabot metadata'
id: dependabot-fetch
uses: dependabot/fetch-metadata@v2
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Split title and update'
id: split-title
if: ${{ ! contains(github.event.pull_request.title, '):' ) && contains(github.event.pull_request.title, ':') && steps.dependabot-fetch.outcome == 'success' }}
env:
TITLE: ${{ github.event.pull_request.title }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{github.event.pull_request.html_url}}
run: |
echo $TITLE
title_pt2="${TITLE##*:}"
title_pt1="${TITLE%%:*}"
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
packagename="${{ steps.dependabot-fetch.outputs.dependency-names }}"
#echo "packagename is $packagename"
#echo "$title_pt1"
#echo "$title_pt2"
parensOpen="("
parensClose="):"
pr_title=$title_pt1$parensOpen$packagename$parensClose$title_pt2
echo "FINAL TITLE: $pr_title"
gh pr edit "$PR_URL" --title "$pr_title"
# Auto merge Dependabot PRs for:
# - patch updates on prod dependencies
# - minor updates on dev dependencies
dependabot-auto-merge:
needs: pull-request-title-change
# Only run for Dependabot PRs
if: ${{ github.actor == 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- name: 'Fetch Dependabot metadata'
id: dependabot
uses: dependabot/fetch-metadata@v2
with:
github-token: '${{ secrets.GITHUB_TOKEN }}'
- name: 'Check auto merge conditions'
id: auto-merge-check
if: |
(
steps.dependabot.outputs.update-type == 'version-update:semver-patch' &&
contains('direct:production,indirect:production', steps.dependabot.outputs.dependency-type)
) || (
contains('version-update:semver-minor,version-update:semver-patch', steps.dependabot.outputs.update-type) &&
contains('direct:development,indirect:development', steps.dependabot.outputs.dependency-type)
)
run: echo "::notice ::auto-merge-check conditions satisfied"
- name: Approve a PR if not already approved
if: ${{ steps.auto-merge-check.conclusion == 'success' }}
run: |
gh pr checkout "$PR_URL" # sets the upstream metadata for `gh pr status`
if [ "$(gh pr status --json reviewDecision -q .currentBranch.reviewDecision)" != "APPROVED" ];
then gh pr review --approve "$PR_URL"
else echo "PR already approved, skipping additional approvals to minimize emails/notification noise.";
fi
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
PR_URL: ${{github.event.pull_request.html_url}}
- name: 'Approve and merge PR'
if: ${{ steps.auto-merge-check.conclusion == 'success' }}
run: |
#gh pr review --approve "$PR_URL"
gh pr merge --auto --squash "$PR_URL"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_URL: ${{ github.event.pull_request.html_url }}