name: Deploy API Documentation

on:
  release:
    types: [published]

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - uses: actions/setup-node@v3
        with:
          node-version: '14'

      - name: restore lock files
        uses: actions/cache@master # must use unreleased master to cache multiple paths
        id: cache
        with:
          # must be done before bootstrap to not include node_modules files in the cache paths
          path: |
            package-lock.json
            packages/*/package-lock.json
            backwards-compatability/*/package-lock.json
            metapackages/*/package-lock.json
            packages/*/package-lock.json
            integration-tests/*/package-lock.json
          key: ${{ runner.os }}-unit_test-${{ matrix.node_version }}-${{ hashFiles('**/package.json') }}
      - name: Install and Build (cache miss) 🔧
        if: steps.cache.outputs.cache-hit != 'true'
        run: |
          npm install --ignore-scripts
          npx lerna bootstrap --no-ci --hoist --nohoist='zone.js'
          npm run compile

      - name: Install and Build (cache hit) 🔧
        if: steps.cache.outputs.cache-hit == 'true'
        run: |
          npm ci --ignore-scripts
          npx lerna bootstrap --hoist --nohoist='zone.js'
          npm run compile

      - name: Build Docs
        run: npm run docs

      - name: Deploy Documentation 🚀
        uses: JamesIves/github-pages-deploy-action@releases/v3
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages # The branch the action should deploy to.
          FOLDER: docs # The folder the action should deploy.
