name: pybricks_jedi

on: [push, pull_request]

jobs:
  test:
    if: github.ref_type != 'tag'
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@v3
    - run: pipx install poetry
    - run: poetry install
      working-directory: ./jedi
    - run: poetry run pytest -vv
      working-directory: ./jedi

  publish:
    if: github.ref_type == 'tag' && startsWith(github.ref_name, 'pybricks_jedi/')
    runs-on: ubuntu-22.04
    steps:
    - uses: actions/checkout@v3
    - run: pipx install poetry
    - run: poetry install
      working-directory: ./jedi
    - run: poetry build
      working-directory: ./jedi
    - run: poetry publish
      working-directory: ./jedi
      env:
        POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_PYBRICKS_JEDI_TOKEN }}
