name: CCW Post-Deploy Spot Check

on:
  workflow_dispatch:
  workflow_call:

concurrency:
  group: ccw-post-deploy-${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  post-deploy-spot-check:
    timeout-minutes: 30
    runs-on:
      - self-hosted
      - windows
      - ccw

    defaults:
      run:
        shell: powershell

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

      - name: Run post-deploy spot check
        env:
          CCW_BASE_URL: ${{ vars.CCW_BASE_URL || 'http://127.0.0.1/CCW' }}
          CCW_SMOKE_USERNAME: ${{ secrets.CCW_SMOKE_USERNAME || 'admin' }}
          CCW_SMOKE_PASSWORD: ${{ secrets.CCW_SMOKE_PASSWORD || 'admin123' }}
          CCW_RESTRICTED_SMOKE_USERNAME: ${{ secrets.CCW_RESTRICTED_SMOKE_USERNAME || '' }}
          CCW_RESTRICTED_SMOKE_PASSWORD: ${{ secrets.CCW_RESTRICTED_SMOKE_PASSWORD || '' }}
          CCW_RESTRICTED_ALLOWED_BRANCHES: ${{ vars.CCW_RESTRICTED_ALLOWED_BRANCHES || '' }}
          CCW_CI_ARTIFACT_DIR: ${{ runner.temp }}\ccw-post-deploy-spot-check
        run: .\scripts\ci_post_deploy_spot_check.ps1

      - name: Append spot check summary
        if: always()
        run: |
          $summaryPath = Join-Path $env:RUNNER_TEMP 'ccw-post-deploy-spot-check\ci-post-deploy-spot-check-summary.txt'
          if (Test-Path -LiteralPath $summaryPath) {
            Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value '## CCW Post-Deploy Spot Check'
            Get-Content -LiteralPath $summaryPath | Add-Content -Path $env:GITHUB_STEP_SUMMARY
          }

      - name: Upload spot check logs
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: ccw-post-deploy-spot-check-logs
          path: ${{ runner.temp }}\ccw-post-deploy-spot-check
          if-no-files-found: warn
          retention-days: 14
