name: Publish Package

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:

permissions: {}

jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      id-token: write # Required for OIDC provenance authentication
      contents: read  # Required for repository checkout
    steps:
      - name: git checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
        with:
          persist-credentials: false

      - name: Setup Node
        uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
        with:
          node-version: lts/*
          package-manager-cache: false

      - name: Install dependencies
        run: yarn --frozen-lockfile

      - name: Install xvfb
        run: sudo apt-get install -y xvfb

      - name: Build
        run: yarn build

      - name: Test
        run: xvfb-run --auto-servernum yarn test

      - name: Publish to npm
        run: npm publish --provenance --access public --registry https://registry.npmjs.org/
