Skip to content

Add Github action for autogenerating table of contents json files #11

Add Github action for autogenerating table of contents json files

Add Github action for autogenerating table of contents json files #11

# This GitHub Action is used for triggering updates of
# the toc.json files present in any directory that
# needs an automatically generated table of contents.
name: Generate Table of Contents files
env:
# Force the stdout and stderr streams to be unbuffered
PYTHONUNBUFFERED: 1
on:
pull_request:
types:
- synchronize
- reopened
- opened
jobs:
generate_toc_formats:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Check out repository
uses: actions/checkout@v3
# Step 2 - Setup Python
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
# Step 3 - Run scripts to generate TOCs:
- name: Generate TOCs
run: |
./scripts/table-of-contents-generator/toc_gen.py --dir="docs/en/interfaces/formats" --single-toc > log.txt
cat log.txt
rm log.txt # remove as we don't want to commit it later
# Step 4 - Fail the workflow if script returns exit code 1
- name: Check exit code
run: |
if [[ "${{ steps.toc_gen.outcome }}" == "failure" ]]; then
echo "Ran into trouble generating a table of contents. See the logs for details."
exit 1
fi
# Step 5 - Check if anything was actually updated
- name: Check for Changes
id: change_check
run: |
if [[ -n "$(git diff --exit-code)" ]]; then
echo "Changes detected."
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "No changes detected."
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
# Step 6 - Commit and Push generated Table Of Contents files
- name: Commit and Push Changes
if: steps.check_changes.outputs.has_changes == 'true'
run: |
# configure the user
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor}}@users.noreply.github.com"
# standard git flow
git add .
git commit -m "Autogenerate or update table of contents files from GitHub action"
git push