name: 'NPM Auth Token'
description: 'Generates an NPM auth token for publishing a specific package'

inputs:
  package-name:
    description: 'The name of the package to publish'
    required: true
  github-token:
    description: 'the github token'
    required: true
  wombat-token-core:
    description: 'The npm token for the cli-core package.'
    required: true
  wombat-token-cli:
    description: 'The npm token for the cli package.'
    required: true
  wombat-token-a2a-server:
    description: 'The npm token for the a2a package.'
    required: true

outputs:
  auth-token:
    description: 'The generated NPM auth token'
    value: '${{ steps.npm_auth_token.outputs.auth-token }}'

runs:
  using: 'composite'
  steps:
    - name: 'Generate NPM Auth Token'
      id: 'npm_auth_token'
      shell: 'bash'
      run: |
        AUTH_TOKEN="${INPUTS_GITHUB_TOKEN}"
        PACKAGE_NAME="${INPUTS_PACKAGE_NAME}"
        PRIVATE_REPO="@google-gemini/"
        if [[ "$PACKAGE_NAME" == "$PRIVATE_REPO"* ]]; then
          AUTH_TOKEN="${INPUTS_GITHUB_TOKEN}"
        elif [[ "$PACKAGE_NAME" == "@google/gemini-cli" ]]; then
          AUTH_TOKEN="${INPUTS_WOMBAT_TOKEN_CLI}"
        elif [[ "$PACKAGE_NAME" == "@google/gemini-cli-core" ]]; then
          AUTH_TOKEN="${INPUTS_WOMBAT_TOKEN_CORE}"
        elif [[ "$PACKAGE_NAME" == "@google/gemini-cli-a2a-server" ]]; then
          AUTH_TOKEN="${INPUTS_WOMBAT_TOKEN_A2A_SERVER}"
        fi
        echo "auth-token=$AUTH_TOKEN" >> $GITHUB_OUTPUT
      env:
        INPUTS_GITHUB_TOKEN: '${{ inputs.github-token }}'
        INPUTS_PACKAGE_NAME: '${{ inputs.package-name }}'
        INPUTS_WOMBAT_TOKEN_CLI: '${{ inputs.wombat-token-cli }}'
        INPUTS_WOMBAT_TOKEN_CORE: '${{ inputs.wombat-token-core }}'
        INPUTS_WOMBAT_TOKEN_A2A_SERVER: '${{ inputs.wombat-token-a2a-server }}'
