# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Publish

on:
  release:
    types:
      - published

jobs:
  test:
    uses: ./.github/workflows/test.yaml
    secrets: inherit

  release:
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read
      packages: write

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up Node.js
        uses: actions/setup-node@v5
        with:
          node-version: latest
          scope: '@laragear'
          registry-url: 'https://registry.npmjs.org'

      - name: Cache NPM dependencies
        uses: actions/cache@v5
        with:
          path: ~/.npm
          key: ${{ runner.OS }}-npm-cache-${{ hashFiles('**/package-lock.json') }}
          restore-keys: |
            ${{ runner.OS }}-npm-cache-

      - name: Install the dependencies
        run: npm ci

      - name: Build the package
        run: npm run build

      - name: Publish package to NPM
        run: npm publish --access public
