# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages

name: Node.js Package

on:
  push:
    branches:
      - main
    tags:
      - 'v*.*.*'

jobs:
  publish-npm:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      id-token: write
    steps:
      - name: Checkout code
        uses: actions/checkout@v7
      - name: Setup Node.js
        uses: actions/setup-node@v6
        with:
          node-version: '22.x'
          registry-url: 'https://registry.npmjs.org'
      - name: Configure Git
        run: |
          git config user.email "webmaster@exploratorium.edu"
          git config user.name "the Exploratorium"
      - name: Install latest npm
        run: npm install -g npm@latest   # trusted publishing needs npm CLI 11.5.1+
      - name: Install dependencies
        run: npm ci
      - name: Build
        run: npm run build
      - name: Increment version
        run: |
          npm version patch
          git push --follow-tags
      - name: Publish to NPM
        run: npm publish