Skip to content

Commit 1f2d9ca

Browse files
Setup Auto Merge Forward Dependabot Commits Workflows
Issue gh-2865
1 parent e136d13 commit 1f2d9ca

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Auto Merge Forward Dependabot Commits
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
concurrency:
10+
group: dependabot-auto-merge-forward
11+
12+
jobs:
13+
get-supported-branches:
14+
uses: spring-io/spring-security-release-tools/.github/workflows/retrieve-spring-supported-versions.yml@actions-v1
15+
with:
16+
project: spring-session
17+
type: oss
18+
repository_name: spring-projects/spring-session
19+
20+
auto-merge-forward-dependabot:
21+
name: Auto Merge Forward Dependabot Commits
22+
runs-on: ubuntu-latest
23+
needs: [get-supported-branches]
24+
permissions:
25+
contents: write
26+
steps:
27+
- name: Checkout
28+
id: checkout
29+
uses: actions/checkout@v4
30+
with:
31+
token: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
32+
- name: Setup GitHub User
33+
id: setup-gh-user
34+
run: |
35+
git config user.name 'github-actions[bot]'
36+
git config user.email 'github-actions[bot]@users.noreply.github.com'
37+
- name: Run Auto Merge Forward
38+
id: run-auto-merge-forward
39+
uses: spring-io/spring-security-release-tools/.github/actions/auto-merge-forward@actions-v1
40+
with:
41+
branches: ${{ needs.get-supported-branches.outputs.supported_versions }},main
42+
from-author: dependabot[bot]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Merge Dependabot PR
2+
3+
on: pull_request_target
4+
5+
run-name: Merge Dependabot PR ${{ github.ref_name }}
6+
7+
permissions: write-all
8+
9+
jobs:
10+
merge-dependabot-pr:
11+
runs-on: ubuntu-latest
12+
if: github.actor == 'dependabot[bot]'
13+
steps:
14+
15+
- uses: actions/checkout@v4
16+
with:
17+
show-progress: false
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
20+
- uses: actions/setup-java@v4
21+
with:
22+
distribution: temurin
23+
java-version: 17
24+
25+
- name: Set Milestone to Dependabot Pull Request
26+
id: set-milestone
27+
run: |
28+
if test -f pom.xml
29+
then
30+
CURRENT_VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout)
31+
else
32+
CURRENT_VERSION=$(cat gradle.properties | sed -n '/^version=/ { s/^version=//;p }')
33+
fi
34+
export CANDIDATE_VERSION=${CURRENT_VERSION/-SNAPSHOT}
35+
MILESTONE=$(gh api repos/$GITHUB_REPOSITORY/milestones --jq 'map(select(.due_on != null and (.title | startswith(env.CANDIDATE_VERSION)))) | .[0] | .title')
36+
37+
if [ -z $MILESTONE ]
38+
then
39+
gh run cancel ${{ github.run_id }}
40+
echo "::warning title=Cannot merge::No scheduled milestone for $CURRENT_VERSION version"
41+
else
42+
gh pr edit ${{ github.event.pull_request.number }} --milestone $MILESTONE
43+
echo mergeEnabled=true >> $GITHUB_OUTPUT
44+
fi
45+
env:
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47+
48+
- name: Merge Dependabot pull request
49+
if: steps.set-milestone.outputs.mergeEnabled
50+
run: gh pr merge ${{ github.event.pull_request.number }} --auto --rebase
51+
env:
52+
GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Trigger Dependabot Auto Merge Forward
2+
3+
on:
4+
push:
5+
branches:
6+
- '*.x'
7+
8+
permissions: read-all
9+
10+
jobs:
11+
trigger-worflow:
12+
name: Trigger Workflow
13+
runs-on: ubuntu-latest
14+
if: ${{ github.event.commits[0].author.username == 'dependabot[bot]' && github.repository == 'spring-projects/spring-session' }}
15+
steps:
16+
- name: Checkout
17+
id: checkout
18+
uses: actions/checkout@v4
19+
- id: trigger
20+
env:
21+
GH_TOKEN: ${{ secrets.GH_ACTIONS_REPO_TOKEN }}
22+
run: gh workflow run dependabot-auto-merge-forward.yml -r main

0 commit comments

Comments
 (0)