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

on:
  push:
    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@v3
      - run: git fetch --unshallow --tags
      - name: Setup pnpm
        uses: pnpm/action-setup@v2.2.4
        with:
          version: 8.6.1
      - name: Setup Node.js environment
        uses: actions/setup-node@v3.7.0
        with:
          node-version: '20.x'
          registry-url: 'https://registry.npmjs.org'
      - name: Install dependencies
        run: pnpm install
      - name: Lint and test before release
        run: pnpm run lint:fix && pnpm run test
      - name: Release
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
        run: |
          pnpm run build
          pnpx auto shipit
