Update Submodules #33
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
# Capture the last commit ID of the submodule | |
SUBMODULE_COMMIT=$(git -C build rev-parse HEAD) | |
echo "Submodule commit: $SUBMODULE_COMMIT" | |
# 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 ID in the title | |
PR_TITLE="Update submodules to latest commits (submodule commit: $SUBMODULE_COMMIT)" | |
gh pr create --title "$PR_TITLE" --body "This PR updates all submodules to their latest commits." --base master --head $BRANCH_NAME | |
else | |
echo "No submodule updates found" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |