on:
  pull_request:
    branches: [ main ]
    types:
      - labeled
      - synchronize

jobs:
  ci-train-pos:
    runs-on: ubuntu-latest
    steps:
      - name: Get PR Labels
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          PR_LABELS=$(gh pr view https://github.com/${{ github.repository }}/pull/${{ github.event.pull_request.number }} --json labels --jq '[.labels[].name]')
          echo "$PR_LABELS"
          echo "PR_LABELS=$PR_LABELS" >> $GITHUB_ENV
      - name: Checkout
        if: contains(env.PR_LABELS, 'ci-train-pos')
        uses: actions/checkout@v4
      - name: Set up Python 3.10
        if: contains(env.PR_LABELS, 'ci-train-pos')
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
      - name: Install dependencies
        if: contains(env.PR_LABELS, 'ci-train-pos')
        run: |
          python -m pip install --upgrade pip
          pip install pytest tox
      - name: Run Test
        if: contains(env.PR_LABELS, 'ci-train-pos')
        run: |
          tox -e train-pos
