Skip to content

Update Submodules #1118

Update Submodules

Update Submodules #1118

name: Update Submodules
on:
schedule:
# 每6小时执行一次
- cron: '0 */6 * * *'
push:
# 当main分支有新的推送时执行
branches:
- main
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
with:
# 确保拉取所有子模块
submodules: 'recursive'
- name: setup-gh
# You may pin to the exact commit or the version.
# uses: wusatosi/setup-gh@7dae6c8246092454793fe35dd4d5a9e8bf8ed34d
uses: wusatosi/[email protected]
with:
# Repository setting for Github CLI
repository: ${{ github.repository }}
# Authentication token setting for Github CLI
token: ${{ github.token }}
- name: Init Submodules
run: |
git submodule init
- name: Update Submodules
run: |
echo "Update submodule"
git submodule update --remote --recursive
echo "Check if submodule is changed or not"
# Track submodule changes
git status
git diff --submodule
git config --global user.email "[email protected]"
git config --global user.name "czyt"
# First, add any submodule changes.
git add . || true # The '|| true' ensures that even if this command fails, the script will continue.
# Now, check if there are changes to commit. We use git diff-index HEAD -- here to check for changes as compared to the last commit.
if git diff-index --quiet HEAD --; then
# If there are no changes then the --quiet flag will make sure the command exits with 0 and this block will be executed.
echo "No changes in submodules to commit."
else
# If there are changes this block will be executed.
echo "Submodule is changed, creating new branch"
git checkout -b update-submodules-${{ github.run_id }}
git commit -m "Automatically update submodules"
echo "Push the new branch update-submodules-${{ github.run_id }}"
git push --set-upstream origin update-submodules-${{ github.run_id }}
echo "Create a PR"
gh pr create --title "Auto-update submodules" --body "Automated changes to update submodules" --head update-submodules-${{ github.run_id }} --base main
fi