diff --git a/action-src/src/__snapshots__/action.test.ts.snap b/action-src/src/__snapshots__/action.test.ts.snap index c209f991a..25e00e056 100644 --- a/action-src/src/__snapshots__/action.test.ts.snap +++ b/action-src/src/__snapshots__/action.test.ts.snap @@ -103,3 +103,86 @@ Array [ "::set-output name=result::{\\"success\\":false,\\"number_of_issues\\":2,\\"number_of_files_checked\\":2,\\"files_with_issues\\":[\\"../fixtures/sampleCode/samples_with_errors/withErrors.ts\\"]}", ] `; + +exports[`Validate Action check files with issues fixtures/sampleCode/** 5`] = `Array []`; + +exports[`Validate Action check files with issues fixtures/sampleCode/** 6`] = `Array []`; + +exports[`Validate Action check files with issues fixtures/sampleCode/** 7`] = ` +Array [ + Array [ + "::warning::Unable to determine which files have changed, checking files: fixtures/sampleCode/** +", + ], + Array [ + "'fork' +", + ], + Array [ + "Files checked: 1, Issues found: 0 in 0 files. +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=success::true +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_checked::1 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_issues::0 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=number_of_files_with_issues::0 +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=files_with_issues::[] +", + ], + Array [ + " +", + ], + Array [ + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":1,\\"files_with_issues\\":[]} +", + ], +] +`; + +exports[`Validate Action check files with issues fixtures/sampleCode/** 8`] = ` +Array [ + "::warning::Unable to determine which files have changed, checking files: fixtures/sampleCode/**", + "'fork'", + "Files checked: 1, Issues found: 0 in 0 files.", + "::set-output name=success::true", + "::set-output name=number_of_files_checked::1", + "::set-output name=number_of_issues::0", + "::set-output name=number_of_files_with_issues::0", + "::set-output name=files_with_issues::[]", + "::set-output name=result::{\\"success\\":true,\\"number_of_issues\\":0,\\"number_of_files_checked\\":1,\\"files_with_issues\\":[]}", +] +`; diff --git a/action-src/src/action.test.ts b/action-src/src/action.test.ts index 5656f13b0..0e9e87ba9 100644 --- a/action-src/src/action.test.ts +++ b/action-src/src/action.test.ts @@ -37,7 +37,6 @@ describe('Validate Action', () => { ${'missing config'} | ${'bad_params/missing_config.json'} | ${new AppError('Bad Configuration.')} ${'bad inline'} | ${'bad_params/bad_inline.json'} | ${new AppError('Bad Configuration.')} ${'bad_incremental_files_only'} | ${'bad_params/bad_incremental_files_only.json'} | ${new AppError('Bad Configuration.')} - ${'bad_unsupported_event'} | ${'bad_params/bad_unsupported_event.json'} | ${new AppError("Unsupported event: 'fork'")} ${'bad strict'} | ${'bad_params/bad_strict.json'} | ${new AppError('Bad Configuration.')} `( '$test', @@ -94,16 +93,17 @@ describe('Validate Action', () => { ); test.each` - files | expected - ${'fixtures/sampleCode/**'} | ${false} + files | incremental | contextFile | expected + ${'fixtures/sampleCode/**'} | ${false} | ${'pull_request_with_files.json'} | ${false} + ${'fixtures/sampleCode/**'} | ${true} | ${'bad_params/bad_unsupported_event.json'} | ${true} `( 'check files with issues $files', - async ({ files, expected }) => { + async ({ files, incremental, contextFile, expected }) => { const warnings: string[] = []; spyWarn.mockImplementation((msg: string) => warnings.push(msg)); - const context = createContextFromFile('pull_request_with_files.json', { + const context = createContextFromFile(contextFile, { INPUT_FILES: files, - INPUT_INCREMENTAL_FILES_ONLY: 'false', + INPUT_INCREMENTAL_FILES_ONLY: incremental ? 'true' : 'false', }); const octokit = createOctokit(); await expect(action(context, octokit)).resolves.toBe(expected); diff --git a/action-src/src/action.ts b/action-src/src/action.ts index 1d175d5fe..47e84456b 100644 --- a/action-src/src/action.ts +++ b/action-src/src/action.ts @@ -5,7 +5,6 @@ import { RunResult } from 'cspell'; import * as glob from 'cspell-glob'; import * as path from 'path'; import { ActionParams, validateActionParams } from './ActionParams'; -import { AppError } from './error'; import { getActionParams } from './getActionParams'; import { fetchFilesForCommits, getPullRequestFiles } from './github'; import { CSpellReporterForGithubAction } from './reporter'; @@ -19,7 +18,7 @@ interface Context { } type EventNames = 'push' | 'pull_request'; -const supportedEvents = new Set(['push', 'pull_request']); +const supportedIncrementalEvents = new Set(['push', 'pull_request']); async function gatherPullRequestFiles(context: Context): Promise> { const { github, githubContext } = context; @@ -83,7 +82,7 @@ function friendlyEventName(eventName: EventNames | string): string { } function isSupportedEvent(eventName: EventNames | string): eventName is EventNames { - return supportedEvents.has(eventName); + return supportedIncrementalEvents.has(eventName); } async function gatherFilesFromContext(context: Context): Promise> { @@ -132,12 +131,20 @@ function filterFiles(globPattern: string, files: Set): Set { return matchingFiles; } +/** + * Run the action based upon the githubContext. + * @param githubContext + * @param octokit + * @returns a promise that resolves to `true` if no issues were found. + */ export async function action(githubContext: GitHubContext, octokit: Octokit): Promise { const params = getActionParams(); validateActionParams(params, core.error); const eventName = githubContext.eventName; if (params.incremental_files_only === 'true' && !isSupportedEvent(eventName)) { - throw new AppError(`Unsupported event: '${eventName}'`); + params.files = params.files || '**'; + core.warning('Unable to determine which files have changed, checking files: ' + params.files); + params.incremental_files_only = 'false'; } const context: Context = { githubContext, diff --git a/action/lib/action.js b/action/lib/action.js index f2e4cd802..d8c0d91fd 100644 --- a/action/lib/action.js +++ b/action/lib/action.js @@ -28,12 +28,11 @@ const core = __importStar(require("@actions/core")); const glob = __importStar(require("cspell-glob")); const path = __importStar(require("path")); const ActionParams_1 = require("./ActionParams"); -const error_1 = require("./error"); const getActionParams_1 = require("./getActionParams"); const github_1 = require("./github"); const reporter_1 = require("./reporter"); const spell_1 = require("./spell"); -const supportedEvents = new Set(['push', 'pull_request']); +const supportedIncrementalEvents = new Set(['push', 'pull_request']); async function gatherPullRequestFiles(context) { var _a; const { github, githubContext } = context; @@ -82,7 +81,7 @@ function friendlyEventName(eventName) { } } function isSupportedEvent(eventName) { - return supportedEvents.has(eventName); + return supportedIncrementalEvents.has(eventName); } async function gatherFilesFromContext(context) { if (context.useEventFiles) { @@ -121,12 +120,20 @@ function filterFiles(globPattern, files) { } return matchingFiles; } +/** + * Run the action based upon the githubContext. + * @param githubContext + * @param octokit + * @returns a promise that resolves to `true` if no issues were found. + */ async function action(githubContext, octokit) { const params = (0, getActionParams_1.getActionParams)(); (0, ActionParams_1.validateActionParams)(params, core.error); const eventName = githubContext.eventName; if (params.incremental_files_only === 'true' && !isSupportedEvent(eventName)) { - throw new error_1.AppError(`Unsupported event: '${eventName}'`); + params.files = params.files || '**'; + core.warning('Unable to determine which files have changed, checking files: ' + params.files); + params.incremental_files_only = 'false'; } const context = { githubContext,