name: "Push to main"

on: push

jobs:
  docs:
    # running only on main branch pushes
    if: ${{ github.ref_name == 'main' && github.ref_type == 'branch' }}

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Using Node 16
        uses: actions/setup-node@v2
        with:
          node-version: "16"
      - name: Update npm version
        run: npm install -g npm@7.x # stop showing warnings about the lockfile
      - name: Install dependencies
        run: npm ci
      - name: Generate documentation
        run: npm run docs
      - name: Commit updates
        if: ${{ success() }}
        run: |
          git config --global user.name "${{ github.actor }}" &&
          git config --global user.email "${{ github.actor }}@users.noreply.github.com" &&
          git add docs &&
          git commit -am "regenerated documentation at $( date -I'minutes' )"
          git push
