Skip to content

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

Add Github action for autogenerating table of contents json files

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

# 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
with:
ref: update_table_of_contents # branch to push changes to
# Step 2 - Setup Python
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
# Step 3: Install Python dependencies
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r 'scripts/table-of-contents-generator/requirements.txt'
# Step 4 - Pull main repo docs, run script to generate TOCs:
- name: Generate TOCs
run: |
yarn prep-from-master
python -u ./scripts/table-of-contents-generator/toc_gen.py --dir="docs/en/interfaces/formats" --single-toc --out="table-of-contents-files" --ignore "_snippets"
# Step 5 - 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 6 - Check if anything was actually updated
- name: Check for Changes
id: check_changes
run: |
git status -u
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 7 - 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 table-of-contents-files/*
git commit -m "Autogenerate or update table of contents files from GitHub action"
git push