Skip to content

Update Submodules Periodically #35

Update Submodules Periodically

Update Submodules Periodically #35

Workflow file for this run

name: Update Submodules Periodically
on:
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
jobs:
update-submodules:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: 'recursive'
- name: Update submodules
run: |
git submodule update --remote --recursive
- name: Configure Git
run: |
git config --global user.email "[email protected]"
git config --global user.name "sscottgvit"
- name: Generate submodule info for README.md
run: |
echo "# Gotham Security Aggregate Repository - Submodule Information" > README.md
#git submodule foreach 'echo "- **${name}**: Version: $(git describe --tags --always --dirty), Description: $(git log -1 --pretty=format:"%s")" >> "$GITHUB_WORKSPACE/submodule_info.md"'
#git submodule foreach 'echo "Processing $name"; git fetch; echo "- **${name}**: Version: $(git describe --tags --always --dirty), Description: $(git log -1 --pretty=format:"%s")" >> "$GITHUB_WORKSPACE/submodule_info.md"'
while read -r line; do
if [[ "$line" =~ \[submodule\ \"(.*)\"\] ]]; then
module="${BASH_REMATCH[1]}"
echo "- **$module**" >> $GITHUB_WORKSPACE/submodule_info.md
elif [[ "$line" =~ url\ =\ (.*) ]]; then
url="${BASH_REMATCH[1]}"
# Convert git URL or SSH format to HTTPS format
url=$(echo $url | sed -e 's,[email protected]:,https://github.com/,' -e 's,\.git,,g')
echo " - URL: $url" >> $GITHUB_WORKSPACE/submodule_info.md
response=$(curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -s -w "%{http_code}" -o response.json https://api.github.com/repos/${url#https://github.com/})
if [ "$(tail -n 1 <<< "$response")" == "200" ]; then
description=$(jq -r '.description' response.json)
echo " - Description: $description" >> $GITHUB_WORKSPACE/submodule_info.md
else
echo " - Description: Failed to fetch description" >> $GITHUB_WORKSPACE/submodule_info.md
fi
rm response.json
fi
done < .gitmodules
- name: Append submodule info to README.md
run: |
if [ -f "$GITHUB_WORKSPACE/submodule_info.md" ]; then
cat "$GITHUB_WORKSPACE/submodule_info.md" >> README.md
rm "$GITHUB_WORKSPACE/submodule_info.md"
else
echo "No submodule information file found."
fi
shell: /usr/bin/bash -e {0}
- name: Commit and push if changes
run: |
git add -A
git diff-index --quiet HEAD || git commit -m "Update submodules"
git push