-
Notifications
You must be signed in to change notification settings - Fork 1
91 lines (79 loc) · 3.33 KB
/
spring-merge-dependabot-pr.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
88
89
90
91
name: Edit & Merge Dependabot PR
on:
workflow_call:
inputs:
developmentGroup:
description: 'The Dependabot update group for development dependencies'
default: 'development-dependencies'
required: false
type: string
developmentLabel:
description: 'The issue label for this development dependencies pull request'
default: 'type: task'
required: false
type: string
dependenciesLabel:
description: 'The issue label for regular dependency upgrade pull request'
default: 'type: dependency-upgrade'
required: false
type: string
autoMergeSnapshots:
description: 'Whether upgrades to SNAPSHOTs (usually after release against Milestone) are going to be merged automatically'
default: false
required: false
type: boolean
mergeArguments:
description: 'The arguments to pass to the gh pr merge command'
required: false
type: string
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
merge-dependabot-pr:
runs-on: ubuntu-latest
if: github.event.pull_request.user.login == 'dependabot[bot]'
steps:
- uses: actions/checkout@v4
with:
show-progress: false
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: ${{ env.GH_TOKEN }}
- name: Add a label for development dependencies pull request
if: ${{ steps.metadata.outputs.dependency-group == inputs.developmentGroup || endsWith(steps.metadata.outputs.new-version, '-SNAPSHOT') }}
run: |
gh pr edit ${{ github.event.pull_request.number }} --add-label "${{ inputs.developmentLabel }}"
gh pr edit ${{ github.event.pull_request.number }} --remove-label "${{ inputs.dependenciesLabel }}"
- name: Set Milestone to Dependabot pull request or upgrade to SNAPSHOT
id: set-milestone
run: |
if [[ '${{ inputs.autoMergeSnapshots }}' == 'true' && '${{ steps.metadata.outputs.new-version }}' == *-SNAPSHOT ]]
then
echo mergeEnabled=true >> $GITHUB_OUTPUT
exit 0
fi
if test -f pom.xml
then
CURRENT_VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)
else
CURRENT_VERSION=$(cat gradle.properties | sed -n '/^version=/ { s/^version=//;p }')
fi
export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
MILESTONE=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.due_on != null and (.title | startswith(env.CANDIDATE_VERSION)))) | .[0] | .title')
if [ -z $MILESTONE ]
then
gh run cancel ${{ github.run_id }}
echo "::warning title=Cannot merge::No scheduled milestone for $CURRENT_VERSION version"
else
gh pr edit ${{ github.event.pull_request.number }} --milestone $MILESTONE
echo mergeEnabled=true >> $GITHUB_OUTPUT
fi
- name: Merge Dependabot pull request
if: steps.set-milestone.outputs.mergeEnabled
run: gh pr merge ${{ github.event.pull_request.number }} ${{ inputs.mergeArguments }}