-
Notifications
You must be signed in to change notification settings - Fork 38
83 lines (72 loc) · 3.6 KB
/
auto-merge-dependabot.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
name: Auto Merge Dependabot PRs
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
evaluate-auto-merge-conditions:
runs-on: ubuntu-latest
outputs:
should_auto_merge: ${{ steps.determine-eligibility.outputs.should_auto_merge }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }} # This is necessary for this job to be able to get the correct commit message from `git log`
- name: Evaluate auto-merge eligibility
id: determine-eligibility
run: |
IS_DEPENDABOT_ACTOR="${{ github.actor == 'dependabot[bot]' }}"
IS_LASTMJS_ACTOR="${{ github.actor == 'lastmjs' }}"
HAS_DEPENDENCIES_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'dependencies') }}"
COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s")
IS_TEMPLATE_UPDATE_COMMIT="false"
if [[ "$COMMIT_MESSAGE" == "chore: update templates for dependency changes" ]]; then
IS_TEMPLATE_UPDATE_COMMIT="true"
fi
IS_STANDARD_DEPENDABOT_PR="false"
if [[ "$HAS_DEPENDENCIES_LABEL" == "true" && "$IS_DEPENDABOT_ACTOR" == "true" ]]; then
IS_STANDARD_DEPENDABOT_PR="true"
fi
HAS_TEMPLATE_UPDATE="false"
if [[ "$HAS_DEPENDENCIES_LABEL" == "true" && "$IS_LASTMJS_ACTOR" == "true" && "$IS_TEMPLATE_UPDATE_COMMIT" == "true" ]]; then
HAS_TEMPLATE_UPDATE="true"
fi
SHOULD_AUTO_MERGE="false"
if [[ $IS_STANDARD_DEPENDABOT_PR == "true" || $HAS_TEMPLATE_UPDATE == "true" ]]; then
SHOULD_AUTO_MERGE="true"
fi
# Add logging here where variables are in scope
echo "Commit message: $COMMIT_MESSAGE"
echo "Actor: ${{ github.actor }}"
echo "Is template update commit: $IS_TEMPLATE_UPDATE_COMMIT"
echo "Has dependencies label: $HAS_DEPENDENCIES_LABEL"
echo "Is lastmjs actor: $IS_LASTMJS_ACTOR"
echo "Is dependabot actor: $IS_DEPENDABOT_ACTOR"
echo "Is standard dependabot PR: $IS_STANDARD_DEPENDABOT_PR"
echo "Has template update: $HAS_TEMPLATE_UPDATE"
echo "Should auto merge: $SHOULD_AUTO_MERGE"
echo "should_auto_merge=$SHOULD_AUTO_MERGE" >> $GITHUB_OUTPUT
perform-auto-merge:
needs: evaluate-auto-merge-conditions
if: ${{ needs.evaluate-auto-merge-conditions.outputs.should_auto_merge == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
token: ${{ secrets.LASTMJS_GITHUB_TOKEN }}
- name: Approve dependency update PR
run: gh pr review --approve "$PR_NUMBER"
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.LASTMJS_GITHUB_TOKEN }}
- name: Merge dependency update PR
run: |
gh pr merge "$PR_NUMBER" \
--merge \
--auto
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
GITHUB_TOKEN: ${{ secrets.LASTMJS_GITHUB_TOKEN }}