name: Artifactory Deployment of PyPi and trace-viewer

on:
  workflow_dispatch: {}
  release:
    types: [published]

env:
  ARTIFACTORY_URL: https://alephalpha.jfrog.io
  ARTIFACTORY_PYPI_REPOSITORY: "intelligence-layer"
  ARTIFACTORY_DOCKER_REGISTRY: alephalpha.jfrog.io/intelligence-layer-images

jobs:
  build-and-push-pypi:
    permissions:
      contents: read
      id-token: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install and configure Poetry
        uses: snok/install-poetry@v1
        with:
          virtualenvs-create: true
          virtualenvs-in-project: true
          installer-parallel: true
      - name: Build package and push to Artifactory
        run: |
          poetry build
          poetry config repositories.artifactory $ARTIFACTORY_URL/artifactory/api/pypi/$ARTIFACTORY_PYPI_REPOSITORY
          export POETRY_HTTP_BASIC_ARTIFACTORY_PASSWORD=$(.github/workflows/get_jfrog_access_token.sh)
          export POETRY_HTTP_BASIC_ARTIFACTORY_USERNAME=$(.github/workflows/get_jfrog_access_token_subject.sh $POETRY_HTTP_BASIC_ARTIFACTORY_PASSWORD)
          poetry publish -r artifactory