name: release

on:
  push:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Setup Node
        uses: actions/setup-node@v3
        with:
          node-version: "^18.4.0"
          cache: 'yarn'
      - name: Install dependencies
        run: yarn install --frozen-lockfile # same as 'npm ci'
      - run: yarn lint
      - run: yarn prettier -- --check
      - run: yarn test
      - run: yarn build
  
  publish-npm:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version:  "^18.4.0"
          registry-url: https://registry.npmjs.org/
      - run: yarn install --frozen-lockfile # same as 'npm ci'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.NPM_PUBLISH}}

  publish-gpr:
    needs: publish-npm
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version:  "^18.4.0"
          registry-url: https://npm.pkg.github.com/
      - run: yarn install --frozen-lockfile # same as 'npm ci'
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}