Skip to content

Update update-submodules.yml #13

Update update-submodules.yml

Update update-submodules.yml #13

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 add .
# Conditional commit and push if there are changes
if git diff --cached ; then
echo "Submodule is changed, create 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
else
echo "No changes in submodules to commit."
fi