name: Generate Table of Contents

on:
  push:
    branches:
      - master
    paths:
      - 'README.md'

jobs:
  generateTOC:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
        with:
          ssh-key: ${{ secrets.DEPLOY_KEY }}
      - run: sudo npm i --global doctoc
      - run: doctoc --all --notitle README.md
      - name: setup git user
        run: |
          git config --global user.name "${{ github.actor }}"
          git config --global user.email "${{ github.actor }}@users.noreply.github.com"
      - run: |
          git add .
          git commit -m "docs: update toc" || true
          git push
