name: Weekly cargo-mutants
on:
  schedule:
    - cron: "0 0 * * 0" # runs weekly on Sunday at 00:00
  workflow_dispatch: # allows manual triggering
jobs:
  cargo-mutants:
    runs-on: ubuntu-24.04
    steps:
      - uses: actions/checkout@v4
      - uses: taiki-e/install-action@v2
        with:
          tool: cargo-mutants
      - run: cargo mutants --in-place --no-shuffle
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: mutants.out
          path: mutants.out
      - name: Check for new mutants
        if: always()
        run: |
          if [ -s mutants.out/missed.txt ]; then
            echo "New missed mutants found"
            gh issue create \
            --title "New Mutants Found" \
            --body "$(cat <<EOF
          Displaying up to the first 10 mutants:

          $(head -n 10 mutants.out/missed.txt)

          For the complete list, please check the [mutants.out artifact](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).
          EOF
          )"
            echo "create_issue=true" >> $GITHUB_ENV
          else
            echo "No new mutants found"
            echo "create_issue=false" >> $GITHUB_ENV
          fi
    env:
      GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
