# name of the workflow.
# this is optional.
name: Test Rust Actions

# events that will trigger this workflow.
# here, we only have "push", so the workflow will run
# whenever we push code to the repository.
on: [push]

env:
  CARGO_TERM_COLOR: always

# each workflow must have at least one job.
# jobs run in parallel by default (we can change that).
# each job groups together a series of steps to accomplish a purpose.
jobs:
  # name of the job
  first:
    runs-on: ubuntu-latest

    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: list files
        run: ls

  # name of the job
  check-code:
    runs-on: ubuntu-latest

    steps:
      - name: checkout
        uses: actions/checkout@v4

      # Step 1: Move to minigrep directory and list files to debug
      # - name: Move to minigrep and list files
      #   run: |
      #     cd minigrep/
      #     ls -la  # This will list the contents of the minigrep directory to ensure it's correct

      - name: Check
        run: |
          cd minigrep/  # Make sure we're in the correct directory
          cargo check --verbose

  # name of the job
  test:
    runs-on: ubuntu-latest

    needs: check-code

    steps:
      - name: checkout
        uses: actions/checkout@v4

      - name: Run Tests
        run: |
          cd minigrep/
          cargo test --tests --verbose

  # name of the job
  documentation-check:
    runs-on: ubuntu-latest

    needs: check-code

    steps:
      - name: checkout
        uses: actions/checkout@v4

      - name: Check for Documentation Tests
        run: |
          cd minigrep/
          DOC_TESTS=$(cargo test --doc --verbose)
          if [[ ! "$DOC_TESTS" =~ "running" ]]; then
            echo "No documentation tests were run!" && exit 1
          fi