---
name: CLI Smoke Tests

on:
  workflow_dispatch:
  push:
    branches:
      - main
      - dev_27
  pull_request:
    branches:
      - main

permissions:
  contents: read

jobs:
  cli-smoke-tests:
    name: CLI smoke tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7

      - name: Set up Python
        uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6
        with:
          python-version: '3.12.1'
          cache: 'pip'

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: list_platforms flag
        run: python mscp.py --list_platforms

      - name: baseline list_tags
        run: python mscp.py baseline --list_tags

      - name: baseline generate (macos 800-53r5 moderate)
        run: >
          python mscp.py
          --os_name macos --os_version 27.0
          --output_dir /tmp/mscp-test-output
          baseline --keyword 800-53r5_moderate

      - name: baseline generate (macos cis_lvl1)
        run: >
          python mscp.py
          --os_name macos --os_version 27.0
          --output_dir /tmp/mscp-test-output
          baseline --keyword cis_lvl1

      - name: guidance markdown (macos 800-53r5 moderate)
        run: >
          python mscp.py
          --os_name macos --os_version 27.0
          --output_dir /tmp/mscp-test-output
          guidance --markdown --no-docs
          baselines/macos/800-53r5_moderate_macos_27.0.yaml

      - name: guidance script (macos cis_lvl1)
        run: >
          python mscp.py
          --os_name macos --os_version 27.0
          --output_dir /tmp/mscp-test-output
          guidance --script --no-docs
          baselines/macos/cis_lvl1_macos_27.0.yaml

      - name: scap xccdf (macos 800-53r5 moderate)
        run: >
          python mscp.py
          --os_name macos --os_version 27.0
          --output_dir /tmp/mscp-test-output
          scap --xccdf --baseline 800-53r5_moderate

      - name: admin validate
        run: python mscp.py admin validate

  cli_tests_success:
    needs:
      - cli-smoke-tests
    if: always()
    name: CLI tests successful
    runs-on: ubuntu-latest
    steps:
      - name: Check job status
        if: >-
          ${{
              (
                contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
              )
          }}
        run: exit 1
