name: Publish to NPM for each push to master and pull request (canary)

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master

jobs:
  publish:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
    steps:
      - name: Checkout to repository
        uses: actions/checkout@v2
      - run: git fetch --unshallow --tags
      - name: Setup node
        uses: actions/setup-node@v1
        with:
          node-version: '12.x'
          registry-url: 'https://registry.npmjs.org'
      - name: Install dependencies
        run: npm ci
      - name: Lint and test before release
        run: npm run test
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          npm ci
          npm run build
          npx auto shipit

