name: ci

on: workflow_dispatch

permissions:
  contents: write
  pull-requests: write

jobs:
  ci:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - uses: actions/setup-node@v4
      with:
        node-version: 20
        registry-url: https://registry.npmjs.org/
        cache: npm
    - name: Install dependencies
      run: npm i
    - name: Build
      run: npm run build
    - name: Publish new release
      run: |
        npm publish --access=public
        PACKAGE=$(node -p "require('./package.json').name")
        VERSION=$(node -p "require('./package.json').version")
        until [ $(npm view $PACKAGE --json | jq --arg version "$VERSION" -r '.versions[] | select (. == $version)') ];
        do
          echo "Waiting for publish to complete"
          sleep 5s
        done
      env:
        NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN }}
