Skip to content

Generate Table of Contents files #47

Generate Table of Contents files

Generate Table of Contents files #47

# 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:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
contents: write
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: 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
- uses: stefanzweifel/git-auto-commit-action@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
commit_message: "Autogenerate table of contents files from GitHub action - $(date '+%Y-%m-%d %H:%M:%S')"
file_pattern: 'table-of-contents-files/*'
branch: generate_table_of_contents
create_branch: true