name: pypi-release

on:
  release:
    types: [published]

env:
  GITHUB_BRANCH: ${{ github.event.release.tag_name }}

jobs:
  release-prowler-job:
    runs-on: ubuntu-latest
    name: Release Prowler to PyPI
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
        with:
          ref: ${{ env.GITHUB_BRANCH }}
      - name: setup python
        uses: actions/setup-python@v2
        with:
          python-version: 3.9 #install the python needed
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install build toml --upgrade
      - name: Build package
        run: python -m build
      - name: Publish prowler-cloud package to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.PYPI_API_TOKEN }}
      - name: Replicate PyPi Package
        run: |
          rm -rf ./dist && rm -rf ./build && rm -rf prowler_cloud.egg-info
          python util/replicate_pypi_package.py
          python -m build
      - name: Publish prowler package to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
        with:
          password: ${{ secrets.PYPI_API_TOKEN }}
