Skip to content

Update submodule update workflow to use PAT_TOKEN for pushing changes #16

Update submodule update workflow to use PAT_TOKEN for pushing changes

Update submodule update workflow to use PAT_TOKEN for pushing changes #16

name: Update Submodules
on:
push:
branches:
- main
jobs:
update-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository with Submodules
uses: actions/checkout@v3
with:
submodules: recursive
- name: Configure Git User
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
- name: Update Submodules
run: |
# Initialize and update submodules
git submodule update --init --recursive
# Loop through each submodule
git submodule foreach '
# Fetch latest changes
git fetch origin
# Get current branch name
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Try to merge, but if conflicts occur, prefer our changes
git merge -X ours --no-edit origin/$BRANCH || {
# If merge fails, abort and reset to origin
git merge --abort
git reset --hard origin/$BRANCH
}
# Stage any changes
git add -A
'
- name: Commit and Push Updates
run: |
# Stage all changes in the main repo
git add .
# Commit if there are changes
git diff --staged --quiet || git commit -m "Update submodule references [skip ci]"
# Push changes using the GITHUB_TOKEN
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git