name: build pkg version
run-name: building ${{ inputs.projects }}

on:
  workflow_call:
    inputs:
      projects:
        description: eg. `foo.com=1.2.3 bar.com^2.3.4`
        required: true
        type: string
      complain:
        type: boolean
        default: false
  workflow_dispatch:
    inputs:
      projects:
        description: eg. `foo.com=1.2.3 bar.com^2.3.4`
        required: true
        type: string
      complain:
        type: boolean
        default: false

jobs:
  ingest:
    runs-on: ubuntu-latest
    outputs:
      pkgs: ${{ steps.divide.outputs.pkgs }}
    steps:
      - run: |
          var="$(echo -n ${{ inputs.projects }} | jq -R -s -c 'split(" ")')"
          echo "pkgs=$var" >> $GITHUB_OUTPUT
        id: divide

  pkg:
    needs: ingest
    strategy:
      fail-fast: false
      matrix:
        pkg: ${{ fromJSON(needs.ingest.outputs.pkgs) }}
    uses: ./.github/workflows/pkg.yml
    permissions:
      issues: write
    with:
      pkg: ${{ matrix.pkg }}
      complain: ${{ github.event_name == 'workflow_call' || inputs.complain }}
    secrets: inherit
