name: RELEASE

on:
  push:
    branches: [ main ]
    paths:
      - aiagents4pharma/**

jobs:
  on-success:
    permissions:
      contents: write
      issues: write
      pull-requests: write
    runs-on: ${{ matrix.os }}

    strategy:
        matrix:
            os: [ubuntu-latest]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v3
      - uses: actions/setup-node@v4
        with:
          node-version: '20.8.1'
      - run: npm ci

      - name: Run semantic-release
        run: npx semantic-release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

      - name: Get release version
        run: |
          RELEASE_VERSION=$(git describe --tags --abbrev=0)
          echo $RELEASE_VERSION > release_version.txt
    
      - name: Build the package
        run: |
          python -m pip install --upgrade pip
          pip install build
          python -m build

      - name: Publish package
        uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
        with:
            user: __token__
            password: ${{ secrets.PYPI_API_TOKEN }}
      
    #   - name: commit files
    #     run: |
    #       git config --local user.email "action@github.com"
    #       git config --local user.name "GitHub Action"
    #       git add -f dist/*
    #       git commit -m "new release"

    #   # push
    #   - name: push changes
    #     uses: ad-m/github-push-action@v0.6.0
    #     with:
    #       github_token: ${{ secrets.GITHUB_TOKEN }}
    #       branch: main