Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodule Update - GitHub Action #24

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions .github/workflows/submodule-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update Submodule on Dev Branch

on:
workflow_dispatch:

jobs:
update-submodule:
runs-on: ubuntu-latest

steps:
# Checkout the 'dev' branch of the repository and its submodules
- name: Checkout dev branch
uses: actions/checkout@v3
with:
ref: dev # Ensure we are on the 'dev' branch
submodules: true # Initialize submodules
fetch-depth: 0 # Fetch full history to ensure we can compare commits

# Set up Git user identity for commits
- name: Configure Git user
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"

# Fetch the latest changes from the remote submodule
- name: Fetch latest changes from submodule
run: |
echo "Fetching latest changes from wormhole-docs submodule..."
cd wormhole-docs
git fetch origin main
cd ..

# Compare the submodule's local HEAD to the remote HEAD
- name: Check if submodule is up-to-date
id: check_submodule
run: |
cd wormhole-docs
LOCAL_COMMIT=$(git rev-parse HEAD)
REMOTE_COMMIT=$(git rev-parse origin/main)
echo "Local commit: $LOCAL_COMMIT"
echo "Remote commit: $REMOTE_COMMIT"
if [ "$LOCAL_COMMIT" != "$REMOTE_COMMIT" ]; then
echo "Submodule is out of date."
echo "::set-output name=update_needed::true"
else
echo "Submodule is up-to-date."
echo "::set-output name=update_needed::false"
fi
cd ..

# Update the submodule if it is outdated
- name: Update submodule if necessary
if: steps.check_submodule.outputs.update_needed == 'true'
run: |
echo "Updating the submodule to the latest commit..."
cd wormhole-docs
git pull origin main
cd ..
git add wormhole-docs
git commit -m "Update wormhole-docs submodule to the latest commit"

# Push the updated submodule to the 'dev' branch
- name: Push changes to dev branch
if: steps.check_submodule.outputs.update_needed == 'true'
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # Use PAT instead of default GITHUB_TOKEN
run: |
echo "Pushing changes to the dev branch..."
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/papermoonio/wormhole-mkdocs.git dev || echo "No changes to push."