Skip to content

Update Submodules

Update Submodules #61

name: Update Submodules
on:
schedule:
# Run every day at midnight EST (00:00 EST / 05:00 UTC)
- cron: '0 5 * * *'
workflow_dispatch:
# Allows manual triggering of the workflow
jobs:
update-submodules:
if: github.repository == 'datacommonsorg/website'
runs-on: ubuntu-latest
permissions:
contents: write # Needed to push changes
pull-requests: write # Needed to create pull requests
issues: write # Needed for label creation
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Use the PAT from your robot account for write permissions
token: ${{ secrets.SUBMOD_UPDATE_TOKEN }}
submodules: recursive # Initialize and update submodules
fetch-depth: 0 # Fetch all history for all branches and tags
- name: Configure Git
run: |
# Set the Git user to your robot account's details
git config user.name "datacommons-robot-author"
git config user.email "datacommons-robot-author@users.noreply.github.com"
- name: Update submodules to latest
id: update_submodules
run: |
# update all submodules
git submodule update --remote --merge
# Check if there are any changes to submodules
if [[ -z $(git status --porcelain) ]]; then
echo "No submodule updates found."
echo "submodules_updated=false" >> "$GITHUB_OUTPUT"
else
echo "Submodules updated. Committing changes."
git add mixer import # Add only the submodules if they are the only changes expected
git commit -m "chore: Update submodules [skip ci]"
echo "submodules_updated=true" >> "$GITHUB_OUTPUT"
fi
- name: Get current date
id: date
run: echo "today=$(date +'%Y-%m-%d')" >> "$GITHUB_OUTPUT"
- name: Create Pull Request
id: cpr
if: steps.update_submodules.outputs.submodules_updated == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.SUBMOD_UPDATE_TOKEN }}
commit-message: "chore: Update submodules [skip ci]"
title: "chore: Update submodules"
body: "This PR automatically updates the `mixer` and `import` submodules to their latest `master` branches."
# Use the date from the previous step
branch: "chore/update-submodules-${{ steps.date.outputs.today }}" # New branch for the PR
base: "master" # Target branch for the PR
labels: automated-pr, dependencies
add-paths: 'mixer,import' # Explicitly add paths to be included in the PR
delete-branch: true # Delete the branch after PR merge
- name: Auto-Merge Pull Request with PAT (Bypassing Reviews)
# This step runs only if a PR was successfully created in the previous step
if: steps.cpr.outputs.pull-request-number != ''
env:
GITHUB_TOKEN: ${{ secrets.SUBMOD_UPDATE_TOKEN }}
run: |
PR_NUMBER=${{ steps.cpr.outputs.pull-request-number }}
echo "Attempting to merge PR #$PR_NUMBER using PAT and --admin flag..."
# The 'gh' (GitHub CLI) is pre-installed on GitHub Actions runners.
# --admin: This flag is crucial. It tells 'gh' to bypass branch protection rules
# (like required reviews or passing status checks).
# --squash: Specifies the merge method (you can also use --merge or --rebase).
# --delete-branch: Deletes the source branch of the PR after merging.
gh pr merge "$PR_NUMBER" --admin --squash --delete-branch
echo "Pull request #$PR_NUMBER merged successfully."