diff --git a/.github/scripts/run-quality-checks.sh b/.github/scripts/run-quality-checks.sh new file mode 100755 index 0000000..6d96607 --- /dev/null +++ b/.github/scripts/run-quality-checks.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +set -e + +get_changed_ts_files() { + local base_ref="$1" + local head_ref="$2" + + if [ -n "$base_ref" ] && [ -n "$head_ref" ]; then + git diff --name-only "$base_ref" "$head_ref" | grep '\.ts$' || true + else + git diff --name-only HEAD~1 HEAD | grep '\.ts$' || true + fi +} + +run_quality_checks() { + local event_type="$1" + local changed_files_raw + + if [ "$event_type" == "pull_request" ]; then + changed_files_raw=$(get_changed_ts_files "$PR_BASE_SHA" "$PR_HEAD_SHA") + local context_message="changed files in the PR" + else + changed_files_raw=$(get_changed_ts_files) + local context_message="files changed in current commit" + fi + + if [ -n "$changed_files_raw" ]; then + # Convert to array + readarray -t changed_files <<< "$changed_files_raw" + + echo "Running quality checks on $context_message: ${changed_files[*]}" + npm run quality -- "${changed_files[@]}" + else + echo "No TypeScript files changed, skipping quality checks" + fi +} + +run_quality_checks "$GITHUB_EVENT_NAME" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 37919f4..df705c5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + fetch-depth: 2 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 @@ -25,8 +27,12 @@ jobs: - name: Install dependencies run: npm ci - - name: Run linter - run: npm run lint + - name: Run quality checks on changed files + env: + GITHUB_EVENT_NAME: ${{ github.event_name }} + PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: ./.github/scripts/run-quality-checks.sh - name: Run tests run: npm test diff --git a/src/test-ci-quality.ts b/src/test-ci-quality.ts new file mode 100644 index 0000000..59c4c72 --- /dev/null +++ b/src/test-ci-quality.ts @@ -0,0 +1,47 @@ +/** + * Test file to verify CI quality checks work correctly + * This file intentionally contains quality issues to test the workflow + */ + +export class TestCIQuality { + // TODO: This is a comment that should trigger quality checks + // FIXME: Another comment that might be flagged + + /** + * This method has too many parameters to test quality checks + * @param param1 First parameter + * @param param2 Second parameter + * @param param3 Third parameter + * @param param4 Fourth parameter + * @param param5 Fifth parameter - this should trigger "too many parameters" warning + */ + testMethodWithManyParameters( + param1: string, + param2: number, + param3: boolean, + param4: object, + param5: string[] + ): void { + // This method intentionally has many parameters to trigger quality checks + console.log('Testing CI quality workflow with parameters:', + param1, param2, param3, param4, param5); + + // Adding some complexity to potentially trigger complexity warnings + if (param3) { + if (param2 > 10) { + if (param1.length > 5) { + if (param4) { + if (param5.length > 0) { + console.log('Nested conditions to increase complexity'); + } + } + } + } + } + } + + // A method that uses external data heavily (feature envy) + processExternalData(data: { value: number; name: string; active: boolean }): string { + return `${data.name}: ${data.value} (${data.active ? 'active' : 'inactive'})`; + } +} \ No newline at end of file