Update Submodules #27
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' # Jede Woche, z.B. Sonntags um Mitternacht | |
workflow_dispatch: | |
jobs: | |
update-submodules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
submodules: 'recursive' | |
- name: Update submodules | |
run: | | |
git submodule update --remote --merge | |
git status --porcelain | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Submodule updates found" | |
# Create a new branch for the changes | |
BRANCH_NAME="update-submodules-branch" | |
# Check if branch already exists on the remote | |
if git ls-remote --exit-code --heads origin $BRANCH_NAME; then | |
echo "Branch $BRANCH_NAME already exists. Exiting." | |
exit 1 | |
fi | |
git checkout -b $BRANCH_NAME | |
git add . | |
git commit -m "Update submodules to latest commits" | |
git push origin $BRANCH_NAME | |
# Create a Pull Request | |
gh pr create --title "Update submodules" --body "This PR updates all submodules to their latest commits." --base main --head $BRANCH_NAME | |
else | |
echo "No submodule updates found" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Cleanup branches (Optional) | |
run: | | |
# Clean up local branches that are no longer on the remote | |
git fetch --prune | |
git branch -vv | awk '/: gone]/ {print $1}' | xargs git branch -d |