# name of the workflow.
# this is optional.
name: Test Gitea 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:
    # the platform or OS that the workflow will run on.
    runs-on: ubuntu-latest

    # series of steps to finish the job.
    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: list files
        run: ls

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

    # series of steps to finish the job.
    steps:
      - name: checkout
        uses: actions/checkout@v4

      # Step 1: Move to minigrep directory and run cargo check
      - name: move to minigrep
        run: cd minigrep/

      - name: Check
        run: cargo check --verbose

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

    # Ensures this job runs only if check-code succeeds
    needs: check-code

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

      # Step 2: Move to minigrep directory and run cargo tests
      - name: move to minigrep
        run: cd minigrep/

      - name: Run Tests
        run: cargo test --tests --verbose

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

    # Ensures this job runs only if check-code succeeds
    needs: check-code

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

      # Step 3: Move to minigrep directory
      - name: move to minigrep
        run: cd minigrep/

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