-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
95 lines (86 loc) · 3.18 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
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
92
93
94
95
name: Sync Branches
description: GitHub Action to sync GitHub branch with the changes from another branch.
author: Unai Abrisketa <uabrisketa@epages.com>, Andres Bernardi <abernardi@epages.com>
inputs:
base:
description: Base branch
required: true
head:
description: Head branch
default: ${{ github.event.repository.default_branch }}
title:
description: Pull request title
body:
description: Pull request body
labels:
description: Labels to add to the pull request
admin:
description: Use administrator privileges to merge a pull request that does not meet requirements
auto:
description: Automatically merge only after necessary requirements are met
delete_branch:
description: Delete the local and remote branch after merge
merge:
description: Merge method (merge, squash, rebase) if
default: false
github_token:
description: GitHub token
default: ${{ github.token }}
outputs:
pull_request_url:
description: Pull Request URL
value: ${{ steps.find_or_create_pull_request.outputs.pull_request_url }}
runs:
using: composite
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set Pull Request title and body
id: set_pull_request_inputs
shell: bash
run: |-
pull_request_title=${{ toJSON(inputs.title) }}
if [ "$pull_request_title" == '' ]; then
pull_request_title="Sync \`${{ inputs.base }}\` branch"
fi
echo "pull_request_title=$pull_request_title" >> $GITHUB_OUTPUT
pull_request_body=${{ toJSON(inputs.body) }}
if [ "$pull_request_body" == '' ]; then
pull_request_body="Sync \`${{ inputs.base }}\` branch with the latest changes on \`${{ inputs.head }}\`."
fi
echo "pull_request_body=$pull_request_body" >> $GITHUB_OUTPUT
- name: Find or create Pull Request
id: find_or_create_pull_request
shell: bash
run: |-
pull_request_url=$(
gh pr list \
--head ${{ inputs.head }} \
--base ${{ inputs.base }} \
--json url \
--jq '.[0].url // ""'
)
if [ "$pull_request_url" == '' ]; then
pull_request_url=$(
gh pr create \
--base ${{ inputs.base }} \
--head ${{ inputs.head }} \
--title '${{ steps.set_pull_request_inputs.outputs.pull_request_title }}' \
--body '${{ steps.set_pull_request_inputs.outputs.pull_request_body }}' \
--label '${{ inputs.labels }}'
)
fi
echo "pull_request_url=$pull_request_url" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
- name: Merge pull request
if: inputs.merge != 'false' && steps.find_or_create_pull_request.outputs.pull_request_url != ''
shell: bash
run: >-
gh pr merge ${{ steps.find_or_create_pull_request.outputs.pull_request_url }}
${{ inputs.admin == 'true' && '--admin' || '' }}
${{ inputs.auto == 'true' && '--auto' || '' }}
${{ inputs.delete_branch == 'true' && '--delete-branch' || '' }}
${{ format('--{0}', inputs.merge) }}
env:
GITHUB_TOKEN: ${{ inputs.github_token }}