name: run_tests
on: [push]
jobs:
  all:
    runs-on: self-hosted
    steps:
      - uses: actions/checkout@v4

      - name: Install Manta from source
        run: |
          # Omitting the following command causes the version of setuptools
          # used by python to get confused, and it doesn't detect the name
          # or version of the package from pyproject.toml - so the following
          # workaround is used:
          # https://github.com/pypa/setuptools/issues/3269#issuecomment-1254507377
          export DEB_PYTHON_INSTALL_LAYOUT=deb_system

          python3 -m venv venv/
          source venv/bin/activate
          python3 -m pip install -U pip
          python3 -m pip install -e ".[dev]"
          python3 -m pip install git+https://github.com/amaranth-lang/amaranth-boards.git

      - name: Run pre-commit against all files
        run: |
          source venv/bin/activate
          pre-commit run --all-files

      - name: Run tests
        run: |
          source ./environment.sh
          source venv/bin/activate
          make test

      - name: Upload coverage reports
        uses: actions/upload-artifact@v4
        with:
          name: coverage_reports
          include-hidden-files: true
          path: |
            .coverage
            coverage.xml

      - name: Show coverage report
        run: |
          source venv/bin/activate
          coverage report

      - name: Upload results to Codecov
        run: |
          source venv/bin/activate
          python3 -m codecov -t ${{ secrets.CODECOV_TOKEN }}
