on:
  push:
    branches:
      - release

name: Publish

jobs:
  test:
    runs-on: ubuntu-latest
    if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"

    strategy:
      matrix:
        node-version: [10.x, 12.x, 14.x]

    steps:
      - uses: actions/checkout@v2
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: ${{ matrix.node-version }}-yarn-${{ hashFiles('**/yarn.lock') }}
      - run: yarn install
      - run: yarn lint
      - run: yarn type-check
      - run: yarn test

  publish:
    needs: test
    runs-on: ubuntu-latest
    if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"

    steps:
      - uses: actions/checkout@v2
        with:
          ssh-key: ${{secrets.SSH_PRIVATE_KEY}}
      - uses: actions/setup-node@v1
        with:
          node-version: 14
      - name: Get yarn cache directory path
        id: yarn-cache-dir-path
        run: echo "::set-output name=dir::$(yarn cache dir)"
      - uses: actions/cache@v2
        id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
        with:
          path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
          key: 14.x-yarn-${{ hashFiles('**/yarn.lock') }}
      - run: yarn install
      - name: Deploy
        run: |
          yarn deploy
        env:
          NPM_TOKEN: ${{secrets.NPM_TOKEN}}
          SLACK_WEBHOOK: ${{secrets.NPM_SLACK_WEBHOOK}}
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
