name: Release
on:
  # Triggers the workflow on push or pull request events but only for the master branch
  push:
    branches:
      - master
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  release:
    name: Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
        #with:
        #  fetch-depth: 0
        #  persist-credentials: false

      - name: Setup Node.js
        uses: actions/setup-node@v2
        with:
          node-version: 14
          registry-url: 'https://registry.npmjs.org'
          scope: '@octocat'

      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"

      - uses: actions/cache@v2
        name: Yarn Cache
        id: yarn-cache
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ runner.os }}-yarn-${{ hashFiles('**/package.json') }}
          restore-keys: |
            ${{ runner.os }}-yarn-

      - name: Install dependencies
        run: |
          yarn install --cwd example --frozen-lockfile
          yarn install --frozen-lockfile

      - name: Build
        run: yarn prepare

      - name: git config
        run: |
          git config user.name "${GITHUB_ACTOR}"
          git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: yarn release

      - run: yarn publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

