name: gh-pages

on:
  workflow_run:
    workflows:
      - "stacks-blockchain-api"
    branches:
      - master
    types:
      - completed
  workflow_dispatch:

jobs:
  gh-pages:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Use Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '14'
          check-latest: true

      - name: Install client deps
        run: npm install
        working-directory: client

      - name: Generate client docs
        run: npm run generate:docs
        working-directory: client

      - name: Generate git info
        run: npm run git-info

      - name: Install deps
        run: npm install
        working-directory: docs

      - name: Generate docs
        run: npm run generate:resolved-spec && npm run generate:types && npm run generate:docs && npm run generate:postman
        working-directory: docs

      - name: Deploy gh-pages
        uses: JamesIves/github-pages-deploy-action@4.0.0
        with:
          branch: gh-pages
          folder: docs/.tmp
