Skip to content

Pull Submodules & Repackage #959

Pull Submodules & Repackage

Pull Submodules & Repackage #959

Workflow file for this run

name: Pull Submodules & Repackage
on:
schedule:
- cron: '58 18 * * *' # adjust as needed
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout repo w/ submodules
uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.CUSTOM_PAT || secrets.GITHUB_TOKEN }}
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Pull main repo updates
run: git pull origin $(git branch --show-current)
- name: Update submodules
run: |
git submodule update --init --recursive --depth=1
git submodule foreach --recursive '
git fetch origin \
&& git reset --hard origin/$(git rev-parse --abbrev-ref HEAD) \
|| echo "Failed to reset submodule"'
- name: Restore sparse checkout configuration
run: |
SPARSE_CONFIG=".config/sparse-checkout-config"
if [[ -f "$SPARSE_CONFIG" ]]; then
echo "Restoring sparse checkout configuration..."
while IFS=':' read -r sm_path paths; do
[[ -z "$sm_path" || "${sm_path:0:1}" == "#" ]] && continue
if [[ -d "$sm_path" ]]; then
echo " → Configuring sparse checkout for $sm_path: $paths"
pushd "$sm_path" > /dev/null
IFS=',' read -ra path_array <<< "$paths"
prefixed=()
for p in "${path_array[@]}"; do
[[ "$p" != /* ]] && p="/$p"
prefixed+=("$p")
done
git sparse-checkout init --no-cone
git sparse-checkout set "${prefixed[@]}"
popd > /dev/null
fi
done < "$SPARSE_CONFIG"
echo "✔ Sparse checkout configuration restored"
else
echo "No sparse checkout configuration found (full repo sync for all)"
fi
- name: Commit changes in submodules
run: |
git submodule foreach --recursive '
if [ -n "$(git status --porcelain)" ]; then
git add -A
git commit -m "chore: auto-commit submodule changes in $(basename $PWD)"
git push --force-with-lease || echo "Push failed in submodule $(basename $PWD)"
else
echo "No changes in submodule $(basename $PWD)"
fi
'
- name: Update README submodule status table
run: |
TABLE="| Repository | Path | Last Updated |\n|:-----------|:-----|:-------------|"
# Build rows: origin repo name, local path, last commit date
while IFS= read -r line; do
sm_path="$(echo "$line" | awk '{print $2}')"
sm_url="$(git config -f .gitmodules --get "submodule.${sm_path}.url" 2>/dev/null || echo "")"
[[ -z "$sm_url" ]] && continue
# Get user/repo name and build GitHub link
repo_name="$(echo "${sm_url%.git}" | sed 's|.*github\.com/||')"
repo_link="[${repo_name}](${sm_url%.git})"
# Get last commit date from the submodule
last_updated="$(git -C "$sm_path" log -1 --format='%ai' 2>/dev/null | cut -d' ' -f1)"
[[ -z "$last_updated" ]] && last_updated="unknown"
TABLE="${TABLE}\n| ${repo_link} | \`${sm_path}\` | ${last_updated} |"
done < <(git submodule status | sort -t'|' -k4 -r)
# Sort rows by date (descending), keeping header
HEADER="$(echo -e "$TABLE" | head -2)"
ROWS="$(echo -e "$TABLE" | tail -n +3 | sort -t'|' -k4 -r)"
SORTED_TABLE="${HEADER}\n${ROWS}"
# Replace content between markers in README
awk -v table="$(echo -e "$SORTED_TABLE")" '
/<!-- SUBMODULE-STATUS:START -->/ { print; print table; skip=1; next }
/<!-- SUBMODULE-STATUS:END -->/ { skip=0 }
!skip { print }
' README.md > README.md.tmp && mv README.md.tmp README.md
- name: Commit & push updates
run: |
git add .
if ! git diff --staged --quiet; then
git commit -m "chore: update submodule pointers"
git push
else
echo "No updates to commit."
fi