name: "Publish packages"

on:
  release:
    types:
      - created
    tags:
      - "v[0-9]+(\\.[0-9]+)*"

jobs:
  configure:
    runs-on: ubuntu-latest
    outputs:
      datetime: ${{ steps.get-datetime.outputs.datetime }}
    steps:
      - id: get-datetime
        run: echo "::set-output name=datetime::$(date +'%Y%m%d%H%M%S')"

  publish_npm_package:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3
        with:
          submodules: true
      - name: Install node
        uses: actions/setup-node@v3
        with:
          node-version: '22'
          registry-url: "https://registry.npmjs.org/"
          scope: "@blooo"
      - run: npm install
      - run: npm run build
      - name: Get latest release version number
        id: get_version
        uses: battila7/get-version-action@v2
      - name: Update tag
        run: |
          echo Publishing as ${{ steps.get_version.outputs.version }}
          npm --allow-same-version --no-git-tag-version version ${{ steps.get_version.outputs.version }}
      - name: Publish package
        env:
          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH_AUTO_GLOBAL }}
        run: |
          npm publish
