Skip to content

Commit d712c39

Browse files
mayastor-borstiagolobocastro
andcommitted
Merge #1918
1918: ci: add workflow for submodule update r=tiagolobocastro a=tiagolobocastro Co-authored-by: Tiago Castro <[email protected]>
2 parents f745fca + b7d781b commit d712c39

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

.github/workflows/mod-update.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Submodule Update
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
submodules:
6+
description: 'Override modules to update via comma-separated list of names'
7+
required: false
8+
default: ''
9+
10+
jobs:
11+
submodule:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
submodules: recursive
21+
22+
- name: Update submodules
23+
run: ./scripts/set-submodule-branches.sh -u -m "${{ github.event.inputs.submodules }}"
24+
25+
- name: Create Pull Request
26+
id: cpr
27+
uses: peter-evans/create-pull-request@v7
28+
with:
29+
commit-message: "chore(ci): update git submodules"
30+
committer: GitHub <[email protected]>
31+
title: "[CI] Update git submodules"
32+
draft: false
33+
signoff: true
34+
delete-branch: true
35+
branch: update-submodules/${{ github.ref_name }}
36+
token: ${{ secrets.ORG_CI_GITHUB }}
37+
38+
- name: Approve Pull Request by CI Bot 1
39+
if: ${{ steps.cpr.outputs.pull-request-number }}
40+
run: |
41+
gh pr review ${{ steps.cpr.outputs.pull-request-number }} --approve
42+
env:
43+
GH_TOKEN: ${{ github.token }}

scripts/set-submodule-branches.sh

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,27 @@ submodule_set_branch_all() {
1414
done
1515
}
1616

17+
submodule_update() {
18+
local modules="$1"
19+
20+
if [ -z "$modules" ]; then
21+
modules=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }')
22+
fi
23+
24+
for mod in $modules; do
25+
echo "Updating submodule $mod ..." >&2
26+
git submodule update --remote "$mod"
27+
pushd "$mod" >/dev/null
28+
git submodule update --init --recursive .
29+
popd >/dev/null
30+
done
31+
}
32+
1733
BRANCH=`git rev-parse --abbrev-ref HEAD`
1834
SET_BRANCH=
1935
CLEAR_BRANCH=
36+
UPDATE=
37+
UPDATE_MODS=
2038
while [ "$#" -gt 0 ]; do
2139
case $1 in
2240
-b|--branch)
@@ -28,20 +46,31 @@ while [ "$#" -gt 0 ]; do
2846
CLEAR_BRANCH=="y"
2947
shift
3048
;;
49+
-u|--update)
50+
UPDATE="y"
51+
shift
52+
;;
53+
-m|--update-modules)
54+
shift
55+
if [ "$1" != " " ]; then
56+
UPDATE_MODS="${1//,/ }"
57+
fi
58+
shift
59+
;;
3160
*)
3261
echo "Unknown option: $1"
3362
exit 1
3463
;;
3564
esac
3665
done
3766

38-
39-
4067
if [ "$BRANCH" == "develop" ] || [ "${BRANCH#release/}" != "${BRANCH}" ]; then
4168
SET_BRANCH="${BRANCH}"
4269
fi
4370

44-
if [ -n "$CLEAR_BRANCH" ]; then
71+
if [ -n "$UPDATE" ]; then
72+
submodule_update "$UPDATE_MODS"
73+
elif [ -n "$CLEAR_BRANCH" ]; then
4574
submodule_set_branch_all ""
4675
elif [ -n "$SET_BRANCH" ]; then
4776
submodule_set_branch_all "$SET_BRANCH"

0 commit comments

Comments
 (0)