name: Release (PyPI & Docker)
on:
  workflow_dispatch:
    inputs:
      version:
        type: choice
        required: true
        description: "Version bump type for PyPI package & Git tag"
        options:
          - patch
          - minor
          - major

permissions:
  id-token: write
  checks: write
  contents: write
  packages: write

jobs:
  release:
    uses: SolaceDev/solace-public-workflows/.github/workflows/hatch_release_pypi.yml@main
    with:
      ENVIRONMENT: pypi
      version: ${{ github.event.inputs.version }}
      whitesource_project_name: "solace-agent-mesh"
      whitesource_product_name: "solaceai"
      prisma_check: true
      sonarqube_hotspot_check: true
      npm_package_path: client/webui/frontend
      node_version: 20
      npm_lock_file: package-lock.json
      pypi-project: solace-agent-mesh

    secrets:
      COMMIT_KEY: ${{ secrets.COMMIT_KEY }}
      PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
      PRISMA_DOCKER_IMAGE_TO_CHECK: ${{ secrets.DOCKER_IMAGE_TO_CHECK }}
      PRISMA_ACCESS_KEY: ${{ secrets.PRISMA_ACCESS_KEY_ID }}
      PRISMA_ACCESS_KEY_SECRET: ${{ secrets.PRISMA_SECRET_ACCESS_KEY }}
      SONARQUBE_PROJECT_KEY: ${{ secrets.SONARQUBE_PROJECT_KEY }}
      SONARQUBE_PROJECT_MAIN_BRANCH: "main"
      SONARQUBE_QUERY_TOKEN: ${{ secrets.SONARQUBE_TOKEN }}
      SONARQUBE_HOTSPOTS_API_URL: ${{ secrets.SONARQUBE_HOTSPOTS_API_URL }}
      WHITESOURCE_API_KEY: ${{ secrets.WHITESOURCE_API_KEY }}
      MANIFEST_AWS_ACCESS_KEY_ID: ${{ secrets.SAM_AWS_ACCESS_KEY_ID }}
      MANIFEST_AWS_SECRET_ACCESS_KEY: ${{ secrets.SAM_AWS_SECRET_ACCESS_KEY }}
      MANIFEST_AWS_REGION: ${{ secrets.AWS_DEFAULT_REGION }}

  build_and_push_docker:
    name: Build and Push Docker Image
    needs: release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: ${{ needs.release.outputs.commit_hash }}

      - name: Build and Push Docker Image to DockerHub
        uses: ./.github/actions/push-docker
        with:
          version_tag: ${{ needs.release.outputs.new_version }}
          push_latest: true
          docker_username: ${{ secrets.DOCKER_USERNAME }}
          docker_password: ${{ secrets.DOCKER_PASSWORD }}
