name: Publish to npm
on:
  release:
    types: [created]
permissions:  # added using https://github.com/step-security/secure-workflows
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@5c7944e73c4c2a096b17a9cb74d65b6c2bbafbde # v2.9.1
        with:
          disable-sudo: true
          egress-policy: block
          allowed-endpoints: >
            github.com:443
            registry.npmjs.org:443
            registry.yarnpkg.com:443
            objects.githubusercontent.com:443

      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
      # Setup .npmrc file to publish to npm
      - uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
        with:
          node-version: "18.x"
          registry-url: "https://registry.npmjs.org"
      - run: yarn install --immutable --immutable-cache --check-cache
      - run: npm publish
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
