-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
56 lines (48 loc) · 1.87 KB
/
action.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
name: 'PR Up to Date'
description: 'Check if branches are up to date and merge the base branch into the pull request branch if necessary.'
inputs:
baseBranch:
required: true
description: 'The base branch to compare and merge.'
runs:
using: 'composite'
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: fregante/setup-git-user@v2
- name: Fetch branches and update working directory
shell: bash
run: |
git fetch origin ${{ github.event.pull_request.head.ref }}
git fetch origin ${{ github.event.pull_request.base.ref }}
- name: Check if branches are up to date
shell: bash
id: checkBranches
run: |
git checkout ${{ github.event.pull_request.head.ref }}
BASE=$(git merge-base origin/${{ github.event.pull_request.base.ref }} HEAD)
if [ $BASE = $(git rev-parse origin/${{ github.event.pull_request.base.ref }}) ]; then
echo "Branches are up to date, skipping merge."
echo "::set-output name=mergeRequired::false"
else
echo "Branches are not up to date, merge is required."
echo "::set-output name=mergeRequired::true"
fi
- name: Merge base branch into PR branch
shell: bash
if: steps.checkBranches.outputs.mergeRequired == 'true'
run: |
git merge --no-edit --no-commit origin/${{ github.event.pull_request.base.ref }}
if [ $? -ne 0 ]; then
echo "Merge conflict detected. Please resolve conflicts before merging."
exit 1
fi
git commit -m "Merge ${{ github.event.pull_request.base.ref }} into ${{ github.event.pull_request.head.ref }}"
- name: Push changes
shell: bash
if: steps.checkBranches.outputs.mergeRequired == 'true'
run: |
git push origin ${{ github.event.pull_request.head.ref }}
branding:
icon: 'git-pull-request'
color: 'blue'