-
Notifications
You must be signed in to change notification settings - Fork 156
86 lines (79 loc) · 3.07 KB
/
submodule-update.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
name: Submodule Updates
on:
push:
branches: [develop]
schedule:
- cron: '0 12 * * *'
jobs:
check_submodules:
name: Pull Request for updated submodules
runs-on: ubuntu-latest
env:
PARENT_REPOSITORY: 'EDCD/EDMarketConnector'
CHECKOUT_BRANCH: 'develop'
PR_AGAINST_BRANCH: 'develop'
OWNER: 'EDCD'
steps:
- uses: actions/checkout@v3
with:
ref: '${{ env.CHECKOUT_BRANCH }}'
submodules: true
- name: Update submodules
shell: bash
run: |
git config user.name github-actions
git config user.email [email protected]
git submodule update --remote
- name: Check for changes
id: check_for_changes
continue-on-error: true
run: |
changes=$(git status --porcelain)
git status --porcelain
if [ -n "${changes}" ];
then
echo 'changes=true' >> $GITHUB_OUTPUT
echo "changes_text=${changes}" >> $GITHUB_OUTPUT
else
echo 'changes=false' >> $GITHUB_OUTPUT
fi
exit 0
- name: Create or Update submodules changes branch
if: steps.check_for_changes.outputs.changes == 'true'
run: |
git fetch origin "submodule-change/$GITHUB_RUN_ID" || git checkout -b "submodule-change/$GITHUB_RUN_ID" $CHECKOUT_BRANCH
git commit -am "updating submodules"
git push --set-upstream origin "submodule-change/$GITHUB_RUN_ID"
- name: Create or Update pull request against target branch
if: steps.check_for_changes.outputs.changes == 'true'
uses: actions/github-script@v6
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const { data: pulls } = await github.rest.pulls.list({
owner: '${{ github.repository_owner }}',
repo: '${{ github.repository }}'.split('/')[1].trim(),
head: 'submodule-change/${{ github.run_id }}',
base: '${{ env.PR_AGAINST_BRANCH }}',
state: 'open',
});
if (pulls.length > 0) {
// If an open pull request exists, update it
const pull_number = pulls[0].number;
await github.rest.pulls.update({
owner: '${{ github.repository_owner }}',
repo: '${{ github.repository }}'.split('/')[1].trim(),
pull_number,
body: '${{ steps.check_for_changes.outputs.changes_text }}',
});
} else {
// If no open pull request exists, create a new one
await github.rest.pulls.create({
owner: '${{ github.repository_owner }}',
repo: '${{ github.repository }}'.split('/')[1].trim(),
head: 'submodule-change/${{ github.run_id }}',
base: '${{ env.PR_AGAINST_BRANCH }}',
title: `[Auto-generated] Submodule Updates ${process.env.GITHUB_RUN_ID}`,
body: '${{ steps.check_for_changes.outputs.changes_text }}',
});
}