From f97330e162613fae43c8cd39dddbd27eb0f51bec Mon Sep 17 00:00:00 2001 From: Goldie Date: Tue, 26 Nov 2024 14:11:09 +0000 Subject: [PATCH 1/4] chore: exclude files with empty strings checker --- .github/empty-string-checker.ts | 9 +++++++++ .github/workflows/no-empty-strings.yml | 2 ++ 2 files changed, 11 insertions(+) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index ff94e81..88e10d7 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -6,6 +6,10 @@ const token = process.env.GITHUB_TOKEN; const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/") || []; const pullNumber = process.env.GITHUB_PR_NUMBER || process.env.PULL_REQUEST_NUMBER || "0"; const baseRef = process.env.GITHUB_BASE_REF; +const excludedFiles = (process.env.EXCLUDED_FILES || "") + .split("\n") + .map((file) => file.trim()) + .filter(Boolean); if (!token || !owner || !repo || pullNumber === "0" || !baseRef) { core.setFailed("Missing required environment variables."); @@ -96,6 +100,11 @@ function parseDiffForEmptyStrings(diff: string) { return; } + // Skip files in excludedFiles + if (excludedFiles.includes(currentFile)) { + return; + } + // Only process TypeScript files if (!currentFile?.endsWith(".ts")) { return; diff --git a/.github/workflows/no-empty-strings.yml b/.github/workflows/no-empty-strings.yml index fa688bc..3469ccc 100644 --- a/.github/workflows/no-empty-strings.yml +++ b/.github/workflows/no-empty-strings.yml @@ -34,3 +34,5 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_BASE_REF: ${{ github.base_ref }} + EXCLUDED_FILES: | + .github/empty-string-checker.ts \ No newline at end of file From 9d2754e184d3eeaebb98a75579c6b07cd458a9e0 Mon Sep 17 00:00:00 2001 From: obeys Date: Thu, 12 Dec 2024 15:01:27 +0000 Subject: [PATCH 2/4] chore: remove default values --- .github/empty-string-checker.ts | 13 +++++++++---- .github/workflows/no-empty-strings.yml | 3 +-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index 88e10d7..4e1f106 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -6,10 +6,15 @@ const token = process.env.GITHUB_TOKEN; const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/") || []; const pullNumber = process.env.GITHUB_PR_NUMBER || process.env.PULL_REQUEST_NUMBER || "0"; const baseRef = process.env.GITHUB_BASE_REF; -const excludedFiles = (process.env.EXCLUDED_FILES || "") - .split("\n") - .map((file) => file.trim()) - .filter(Boolean); +const excludedFiles: string[] = []; + +if (process.env.EXCLUDED_FILES) { + excludedFiles.push( + ...process.env.EXCLUDED_FILES.split("\n") + .map((file) => file.trim()) + .filter(Boolean) + ); +} if (!token || !owner || !repo || pullNumber === "0" || !baseRef) { core.setFailed("Missing required environment variables."); diff --git a/.github/workflows/no-empty-strings.yml b/.github/workflows/no-empty-strings.yml index 3469ccc..3f3b459 100644 --- a/.github/workflows/no-empty-strings.yml +++ b/.github/workflows/no-empty-strings.yml @@ -34,5 +34,4 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_BASE_REF: ${{ github.base_ref }} - EXCLUDED_FILES: | - .github/empty-string-checker.ts \ No newline at end of file + EXCLUDED_FILES: From 78c59b5c2731340d1e0f22402cd183382a9b7c0a Mon Sep 17 00:00:00 2001 From: obeys Date: Thu, 12 Dec 2024 15:21:56 +0000 Subject: [PATCH 3/4] chore: fix ci passing when no EXCLUDED_FILES --- .github/empty-string-checker.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index 4e1f106..0d46d28 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -6,21 +6,24 @@ const token = process.env.GITHUB_TOKEN; const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/") || []; const pullNumber = process.env.GITHUB_PR_NUMBER || process.env.PULL_REQUEST_NUMBER || "0"; const baseRef = process.env.GITHUB_BASE_REF; +const excludeEnv = process.env.EXCLUDED_FILES; const excludedFiles: string[] = []; -if (process.env.EXCLUDED_FILES) { +if (!token || !owner || !repo || pullNumber === "0" || !baseRef || excludeEnv === undefined) { + core.setFailed("Missing required environment variables."); + process.exit(1); +} + +// Only process excludeEnv if it has content +if (excludeEnv.length > 0) { excludedFiles.push( - ...process.env.EXCLUDED_FILES.split("\n") + ...excludeEnv + .split("\n") .map((file) => file.trim()) .filter(Boolean) ); } -if (!token || !owner || !repo || pullNumber === "0" || !baseRef) { - core.setFailed("Missing required environment variables."); - process.exit(1); -} - const octokit = new Octokit({ auth: token }); const git = simpleGit(); From 573872fa2b59d5595ea9ffd75587df7d515cab71 Mon Sep 17 00:00:00 2001 From: obeys Date: Fri, 13 Dec 2024 21:29:45 +0000 Subject: [PATCH 4/4] chore: make EXCLUDED_FILES optional and refactor --- .github/empty-string-checker.ts | 19 ++++++------------- .github/workflows/no-empty-strings.yml | 1 - 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index 0d46d28..d553cc8 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -6,24 +6,17 @@ const token = process.env.GITHUB_TOKEN; const [owner, repo] = process.env.GITHUB_REPOSITORY?.split("/") || []; const pullNumber = process.env.GITHUB_PR_NUMBER || process.env.PULL_REQUEST_NUMBER || "0"; const baseRef = process.env.GITHUB_BASE_REF; -const excludeEnv = process.env.EXCLUDED_FILES; -const excludedFiles: string[] = []; +const excludedFiles: string[] = process.env.EXCLUDED_FILES + ? process.env.EXCLUDED_FILES.split("\n") + .map((file) => file.trim()) + .filter(Boolean) + : []; -if (!token || !owner || !repo || pullNumber === "0" || !baseRef || excludeEnv === undefined) { +if (!token || !owner || !repo || pullNumber === "0" || !baseRef) { core.setFailed("Missing required environment variables."); process.exit(1); } -// Only process excludeEnv if it has content -if (excludeEnv.length > 0) { - excludedFiles.push( - ...excludeEnv - .split("\n") - .map((file) => file.trim()) - .filter(Boolean) - ); -} - const octokit = new Octokit({ auth: token }); const git = simpleGit(); diff --git a/.github/workflows/no-empty-strings.yml b/.github/workflows/no-empty-strings.yml index 3f3b459..fa688bc 100644 --- a/.github/workflows/no-empty-strings.yml +++ b/.github/workflows/no-empty-strings.yml @@ -34,4 +34,3 @@ jobs: GITHUB_REPOSITORY: ${{ github.repository }} GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} GITHUB_BASE_REF: ${{ github.base_ref }} - EXCLUDED_FILES: