-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
59 lines (52 loc) · 1.75 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
name: 'Update Submodule'
description: 'This action creates a pull request in a parent repository to update one of its submodules.'
inputs:
github-token:
required: true
submodule-path:
required: true
parent-repository:
required: true
parent-branch:
required: true
runs:
using: 'composite'
steps:
- name: Checkout parent repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ inputs.parent-branch }}
repository: ${{ inputs.parent-repository }}
submodules: true
token: ${{ inputs.github-token }}
- name: Update submodule and create pull request if needed
env:
GH_TOKEN: ${{ inputs.github-token }}
shell: bash
run: |
submodule_path=${{ inputs.submodule-path }}
branch_name=sync/${submodule_path##*/}
git config user.name 'vtisweden-bot[bot]'
git config user.email 'vtisweden-bot[bot]@users.noreply.github.com'
if gh pr list | cut -f 3 -d $'\t' | grep -q "^$branch_name$"
then
git checkout $branch_name
create_pr=false
else
git checkout -b $branch_name
create_pr=true
fi
git submodule update --remote -- ${{ inputs.submodule-path }}
git add -- ${{ inputs.submodule-path }}
if git status | grep -q "Changes to be committed"
then
git commit ${{ inputs.submodule-path }} -m"Update submodule ${{ inputs.submodule-path }}"
git push --set-upstream origin $branch_name
else
create_pr=false
fi
if $create_pr
then
gh pr create --title "Update submodule ${{ inputs.submodule-path }}" --body "" --base "${{ inputs.parent-branch }}" --head "$branch_name"
fi