name: 'Util: Determine current versions'

on:
  workflow_dispatch:
  workflow_call:
    outputs:
      stable:
        description: 'Stable release version'
        value: ${{ jobs.get-versions.outputs.stable }}
      beta:
        description: 'Beta release version'
        value: ${{ jobs.get-versions.outputs.beta }}
      v1:
        description: 'v1 release version'
        value: ${{ jobs.get-versions.outputs.v1 }}

jobs:
  get-versions:
    runs-on: ubuntu-latest
    outputs:
      stable: ${{ steps.get-tags.outputs.stable }}
      beta: ${{ steps.get-tags.outputs.beta }}
      v1: ${{ steps.get-tags.outputs.v1 }}

    steps:
      - name: Checkout
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          fetch-depth: 1
          fetch-tags: true

      - name: Setup Node.js
        uses: ./.github/actions/setup-nodejs
        with:
          build-command: ''
          install-command: pnpm install --frozen-lockfile --dir ./.github/scripts --ignore-workspace
          cache-dependency-path: .github/scripts/pnpm-lock.yaml

      - name: Extract release versions
        id: get-tags
        run: node ./.github/scripts/get-release-versions.mjs

      - name: Print detected versions
        run: |
          echo "Stable: ${{ steps.get-tags.outputs.stable }}"
          echo "Beta:   ${{ steps.get-tags.outputs.beta }}"
          echo "v1: ${{ steps.get-tags.outputs.v1 }}"
