name: "Release"

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  prepare:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: '14'
          cache: 'yarn'

      - name: Install dependencies
        if: steps.yarn-cache.outputs.cache-hit != 'true'
        run: yarn install

  #buildnpublish:
  #  needs: prepare
  #  runs-on: ubuntu-latest
  #  steps:
  #    - name: Checkout the repository
  #      uses: actions/checkout@v2

  #    - name: Get yarn cache directory path
  #      id: yarn-cache-dir-path
  #      run: echo "::set-output name=dir::$(yarn cache dir)"

  #    - name: Setup Node
  #      uses: actions/setup-node@v2
  #      with:
  #        node-version: '14'

  #    - uses: actions/cache@v2
  #      with:
  #        path: '**/node_modules'
  #        key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

  #    - name: Install dependencies
  #      if: steps.yarn-cache.outputs.cache-hit != 'true'
  #      run: yarn install

  #    - name: Building
  #      run: yarn build

  #    - uses: JS-DevTools/npm-publish@v1
  #      with:
  #        token: ${{ secrets.NPM_TOKEN }}

  docs:
  #  needs: buildnpublish
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repository
        uses: actions/checkout@v2

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - name: Setup Node
        uses: actions/setup-node@v2
        with:
          node-version: '14'

      - uses: actions/cache@v2
        with:
          path: '**/node_modules'
          key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}

      - name: Install dependencies
        if: steps.yarn-cache.outputs.cache-hit != 'true'
        run: yarn install

      - name: Create the docs directory locally in CI
        run: npm run docs

      - name: Deploy 🚀
        uses: JamesIves/github-pages-deploy-action@4.1.4
        with:
        # The Branch here is a reserved branch for github
          branch: gh-pages
          folder: docs
