-
Notifications
You must be signed in to change notification settings - Fork 4
68 lines (55 loc) · 2.25 KB
/
update-submodules.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
name: Update Submodules
on:
schedule:
- cron: '0 0 * * 0' # Every Sunday at midnight
workflow_dispatch:
jobs:
update-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: 'recursive'
- name: Update submodules
id: update
run: |
# Update submodules
git submodule update --init --remote
# Collect commit IDs for each submodule
COMMIT_IDS=$(git submodule foreach --quiet 'echo $path: $(git rev-parse HEAD)' | awk '{printf "%s\\n", $0}' | tr '\n' '\r')
echo "Submodule commits:"
echo "$COMMIT_IDS"
# Check for changes
git status --porcelain
if [ -n "$(git status --porcelain)" ]; then
echo "Submodule updates found"
BRANCH_NAME="update-submodules-branch"
# Delete the remote branch if it exists
if git ls-remote --exit-code --heads origin $BRANCH_NAME; then
echo "Deleting existing remote branch $BRANCH_NAME"
git push origin --delete $BRANCH_NAME
fi
# Delete the local branch if it exists
if git show-ref --verify --quiet refs/heads/$BRANCH_NAME; then
echo "Deleting existing local branch $BRANCH_NAME"
git branch -D $BRANCH_NAME
fi
# Set up Git identity
git config user.name "GitHub Actions"
git config user.email "[email protected]"
# Create a new branch and make changes
git checkout -b $BRANCH_NAME
git add .
git commit -m "Update submodules to latest commits"
git push origin $BRANCH_NAME
# Create a Pull Request with submodule commit IDs in the title
PR_TITLE="Update submodules to latest commits"
PR_BODY="This PR updates all submodules to their latest commits.\n\n${COMMIT_IDS}"
echo -e "$PR_BODY" > pr_body.txt
gh pr create --title "$PR_TITLE" --body "$(cat pr_body.txt)" --base master --head $BRANCH_NAME
else
echo "No submodule updates found"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}