name: Formatter and Pylint jobs
on: [workflow_call]
jobs:

  Formatter:
    runs-on: ubuntu-latest
    steps:
      - name: Check out repository code
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.13' 

      - name: Run black and isort
        run: |
          pip install black isort
          pip install -e .[dev]
          black --check --diff --color .
          isort --check --diff ./
  Pylint:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.13'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install pylint pylint-exit anybadge

      - name: Run Pylint
        run: |
          mkdir -p ./pylint
          set +e
          pylint ./${{ github.event.repository.name }} --output-format=text > ./pylint/pylint.log
          pylint-exit $?
          set -e

      - name: Extract Pylint Score
        id: score
        run: |
          SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./pylint/pylint.log)
          echo "score=$SCORE" >> $GITHUB_OUTPUT

      - name: Create Badge
        run: |
          anybadge --label=Pylint --file=./pylint/pylint.svg --value="${{ steps.score.outputs.score }}" 2=red 4=orange 8=yellow 10=green

      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: pylint-artifacts
          path: |
            # ./pylint/pylint.log # not sure why this isn't working
            ./pylint/pylint.svg