From 8b2b57990ad15196e8083a671eaf75bf7bed4bed Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 27 Apr 2020 10:20:58 +0200 Subject: [PATCH] fix: Have separate Lint checks for push and pull requests --- action.yml | 5 +++ src/config.ts | 2 +- src/index.ts | 101 +++++++++++++++++++++++++++---------------------- src/octokit.ts | 13 ++++--- 4 files changed, 70 insertions(+), 51 deletions(-) diff --git a/action.yml b/action.yml index 4802796..37b6bee 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,11 @@ inputs: [Learn more about `GITHUB_TOKEN`](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#about-the-github_token-secret) default: ${{ github.token }} + event_name: + required: true + description: | + The name of the event that triggered the workflow + default: ${{ github.event_name }} runs: using: docker image: Dockerfile diff --git a/src/config.ts b/src/config.ts index cc8bb81..e559d10 100644 --- a/src/config.ts +++ b/src/config.ts @@ -5,7 +5,7 @@ export const Config = t.strict({ INPUT_REPO_TOKEN: t.string, GITHUB_WORKSPACE: t.string, INPUT_FILE_GLOB: t.string, - GITHUB_ACTION: t.string, + INPUT_EVENT_NAME: t.string, INPUT_SPECTRAL_RULESET: t.string, }); diff --git a/src/index.ts b/src/index.ts index 13e8ce8..751573c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,55 +120,66 @@ const createConfigFromEnv = pipe( const program = pipe( TE.fromIOEither(createConfigFromEnv), - TE.chain(({ GITHUB_EVENT_PATH, INPUT_REPO_TOKEN, GITHUB_WORKSPACE, INPUT_FILE_GLOB, INPUT_SPECTRAL_RULESET }) => - pipe( - getRepositoryInfoFromEvent(GITHUB_EVENT_PATH), - TE.chain(event => - pipe( - createOctokitInstance(INPUT_REPO_TOKEN), - TE.map(octokit => ({ octokit, event })) - ) - ), - TE.chain(({ octokit, event }) => - pipe( - createGithubCheck(octokit, event, CHECK_NAME), - TE.map(check => ({ octokit, event, check })) - ) - ), - TE.chain(({ octokit, event, check }) => - pipe( - readFilesToAnalyze(INPUT_FILE_GLOB, GITHUB_WORKSPACE), - TE.chain(fileContents => createSpectralAnnotations(INPUT_SPECTRAL_RULESET, fileContents, GITHUB_WORKSPACE)), - TE.chain(annotations => - pipe( - updateGithubCheck( - octokit, - CHECK_NAME, - check, - event, - annotations, - annotations.findIndex(f => f.annotation_level === 'failure') === -1 ? 'success' : 'failure' - ), - TE.map(checkResponse => { + TE.chain( + ({ + INPUT_EVENT_NAME, + GITHUB_EVENT_PATH, + INPUT_REPO_TOKEN, + GITHUB_WORKSPACE, + INPUT_FILE_GLOB, + INPUT_SPECTRAL_RULESET, + }) => + pipe( + getRepositoryInfoFromEvent(GITHUB_EVENT_PATH, INPUT_EVENT_NAME), + TE.chain(event => + pipe( + createOctokitInstance(INPUT_REPO_TOKEN), + TE.map(octokit => ({ octokit, event })) + ) + ), + TE.chain(({ octokit, event }) => + pipe( + createGithubCheck(octokit, event, `${CHECK_NAME} (${event.eventName})`), + TE.map(check => ({ octokit, event, check })) + ) + ), + TE.chain(({ octokit, event, check }) => + pipe( + readFilesToAnalyze(INPUT_FILE_GLOB, GITHUB_WORKSPACE), + TE.chain(fileContents => createSpectralAnnotations(INPUT_SPECTRAL_RULESET, fileContents, GITHUB_WORKSPACE)), + TE.chain(annotations => + pipe( + updateGithubCheck( + octokit, + check, + event, + annotations, + annotations.findIndex(f => f.annotation_level === 'failure') === -1 ? 'success' : 'failure' + ), + TE.map(checkResponse => { info( - `Commit ${event.sha} has been annotated (https://github.com/${event.owner}/${event.owner}/commit/${event.sha})` + `Check run '${checkResponse.data.name}' concluded with '${checkResponse.data.conclusion}' (${checkResponse.data.html_url})` ); - const fatalErrors = annotations.filter(a => a.annotation_level === 'failure'); - if (fatalErrors.length > 0) { - setFailed(`${pluralizer(fatalErrors.length, 'fatal issue')} detected. Failing the process.`); - } - - return checkResponse; - }) - ) - ), - TE.orElse(e => { - setFailed(e.message); - return updateGithubCheck(octokit, CHECK_NAME, check, event, [], 'failure', e.message); - }) + info( + `Commit ${event.sha} has been annotated (https://github.com/${event.owner}/${event.repo}/commit/${event.sha})` + ); + + const fatalErrors = annotations.filter(a => a.annotation_level === 'failure'); + if (fatalErrors.length > 0) { + setFailed(`${pluralizer(fatalErrors.length, 'fatal issue')} detected. Failing the process.`); + } + + return checkResponse; + }) + ) + ), + TE.orElse(e => { + setFailed(e.message); + return updateGithubCheck(octokit, check, event, [], 'failure', e.message); + }) + ) ) ) - ) ) ); diff --git a/src/octokit.ts b/src/octokit.ts index 79678dd..5879a31 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -32,10 +32,14 @@ export const createGithubCheck = (octokit: GitHub, event: IRepositoryInfo, name: export interface IRepositoryInfo { owner: string; repo: string; + eventName: string; sha: string; } -export const getRepositoryInfoFromEvent = (eventPath: string): TE.TaskEither => +export const getRepositoryInfoFromEvent = ( + eventPath: string, + eventName: string +): TE.TaskEither => pipe( TE.fromEither(E.tryCatch(() => require(eventPath), E.toError)), TE.map(event => { @@ -44,13 +48,12 @@ export const getRepositoryInfoFromEvent = (eventPath: string): TE.TaskEither, event: IRepositoryInfo, annotations: ChecksUpdateParamsOutputAnnotations[], @@ -62,13 +65,13 @@ export const updateGithubCheck = ( octokit.checks.update({ check_run_id: check.data.id, owner: event.owner, - name: actionName, + name: check.data.name, repo: event.repo, status: 'completed', conclusion, completed_at: new Date().toISOString(), output: { - title: actionName, + title: check.data.name, summary: message ? message : conclusion === 'success'