name: Publish

on:
  release:
    types: [created]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        with:
          node-version: 16
          registry-url: 'https://registry.npmjs.org'

      - name: Build
        run: |
          npm ci
          npx cypress install

          # update version before build
          npm --no-git-tag-version version ${{ github.event.release.tag_name }}
          npm run build

      - name: Test
        uses: cypress-io/github-action@v2
        with:
          browser: chrome
          spec: tests/integration/basic_spec.js

      - name: Publish
        run: |
          npm publish

        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
