mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-04-03 05:55:54 +00:00
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
144 lines
5.1 KiB
YAML
144 lines
5.1 KiB
YAML
name: 'UI: Tests'
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- 'master'
|
|
- 'v5.*'
|
|
pull_request:
|
|
branches:
|
|
- 'master'
|
|
- 'v5.*'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
env:
|
|
UI_WORKING_DIR: ./ui
|
|
NODE_VERSION: '24.13.0'
|
|
|
|
jobs:
|
|
ui-tests:
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 20
|
|
permissions:
|
|
contents: read
|
|
defaults:
|
|
run:
|
|
working-directory: ./ui
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
# zizmor: ignore[artipacked]
|
|
persist-credentials: true # Required by tj-actions/changed-files to fetch PR branch
|
|
|
|
- name: Check for UI changes
|
|
id: check-changes
|
|
uses: tj-actions/changed-files@7dee1b0c1557f278e5c7dc244927139d78c0e22a # v47.0.4
|
|
with:
|
|
files: |
|
|
ui/**
|
|
.github/workflows/ui-tests.yml
|
|
files_ignore: |
|
|
ui/CHANGELOG.md
|
|
ui/README.md
|
|
ui/AGENTS.md
|
|
|
|
- name: Get changed source files for targeted tests
|
|
id: changed-source
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
uses: tj-actions/changed-files@7dee1b0c1557f278e5c7dc244927139d78c0e22a # v47.0.4
|
|
with:
|
|
files: |
|
|
ui/**/*.ts
|
|
ui/**/*.tsx
|
|
files_ignore: |
|
|
ui/**/*.test.ts
|
|
ui/**/*.test.tsx
|
|
ui/**/*.spec.ts
|
|
ui/**/*.spec.tsx
|
|
ui/vitest.config.ts
|
|
ui/vitest.setup.ts
|
|
|
|
- name: Check for critical path changes (run all tests)
|
|
id: critical-changes
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
uses: tj-actions/changed-files@7dee1b0c1557f278e5c7dc244927139d78c0e22a # v47.0.4
|
|
with:
|
|
files: |
|
|
ui/lib/**
|
|
ui/types/**
|
|
ui/config/**
|
|
ui/middleware.ts
|
|
ui/vitest.config.ts
|
|
ui/vitest.setup.ts
|
|
|
|
- name: Setup Node.js ${{ env.NODE_VERSION }}
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
|
|
with:
|
|
node-version: ${{ env.NODE_VERSION }}
|
|
|
|
- name: Setup pnpm
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4
|
|
with:
|
|
version: 10
|
|
run_install: false
|
|
|
|
- name: Get pnpm store directory
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
shell: bash
|
|
run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
|
|
- name: Setup pnpm and Next.js cache
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
|
|
with:
|
|
path: |
|
|
${{ env.STORE_PATH }}
|
|
${{ env.UI_WORKING_DIR }}/node_modules
|
|
${{ env.UI_WORKING_DIR }}/.next/cache
|
|
key: ${{ runner.os }}-pnpm-nextjs-${{ hashFiles('ui/pnpm-lock.yaml') }}-${{ hashFiles('ui/**/*.ts', 'ui/**/*.tsx', 'ui/**/*.js', 'ui/**/*.jsx') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-nextjs-${{ hashFiles('ui/pnpm-lock.yaml') }}-
|
|
${{ runner.os }}-pnpm-nextjs-
|
|
|
|
- name: Install dependencies
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
run: pnpm install --frozen-lockfile --prefer-offline
|
|
|
|
- name: Run healthcheck
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
run: pnpm run healthcheck
|
|
|
|
- name: Run unit tests (all - critical paths changed)
|
|
if: steps.check-changes.outputs.any_changed == 'true' && steps.critical-changes.outputs.any_changed == 'true'
|
|
run: |
|
|
echo "Critical paths changed - running ALL unit tests"
|
|
pnpm run test:run
|
|
|
|
- name: Run unit tests (related to changes only)
|
|
if: steps.check-changes.outputs.any_changed == 'true' && steps.critical-changes.outputs.any_changed != 'true' && steps.changed-source.outputs.all_changed_files != ''
|
|
run: |
|
|
echo "Running tests related to changed files:"
|
|
echo "${STEPS_CHANGED_SOURCE_OUTPUTS_ALL_CHANGED_FILES}"
|
|
# Convert space-separated to vitest related format (remove ui/ prefix for relative paths)
|
|
CHANGED_FILES=$(echo "${STEPS_CHANGED_SOURCE_OUTPUTS_ALL_CHANGED_FILES}" | tr ' ' '\n' | sed 's|^ui/||' | tr '\n' ' ')
|
|
pnpm exec vitest related $CHANGED_FILES --run
|
|
env:
|
|
STEPS_CHANGED_SOURCE_OUTPUTS_ALL_CHANGED_FILES: ${{ steps.changed-source.outputs.all_changed_files }}
|
|
|
|
- name: Run unit tests (test files only changed)
|
|
if: steps.check-changes.outputs.any_changed == 'true' && steps.critical-changes.outputs.any_changed != 'true' && steps.changed-source.outputs.all_changed_files == ''
|
|
run: |
|
|
echo "Only test files changed - running ALL unit tests"
|
|
pnpm run test:run
|
|
|
|
- name: Build application
|
|
if: steps.check-changes.outputs.any_changed == 'true'
|
|
run: pnpm run build
|