diff --git a/action.yml b/action.yml index 6984ca8..5393684 100644 --- a/action.yml +++ b/action.yml @@ -8,6 +8,10 @@ inputs: spectral_ruleset: required: true description: Ruleset file to load in Spectral + default: spectral.yml + repo_token: + required: true + description: Repository token to create the checks runs: using: docker image: Dockerfile diff --git a/package.json b/package.json index bb073e1..d4972d1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "@octokit/graphql": "^4.3.1", "@octokit/request": "^5.3.1", "@octokit/rest": "^16.35.0", - "@types/node": "^12.12.12", + "@types/node": "^12.12.14", "@types/urijs": "^1.19.4", "husky": "^3.1.0", "prettier": "^1.19.1", diff --git a/src/index.ts b/src/index.ts index 10f839e..06fc30e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { Config } from './config'; import { runSpectral, createSpectral } from './spectral'; import { createGithubCheck, createOctokitInstance, getRepositoryInfoFromEvent, updateGithubCheck } from './octokit'; -import { error, info, setFailed } from '@actions/core'; +import { info, setFailed } from '@actions/core'; import * as IOEither from 'fp-ts/lib/IOEither'; import * as IO from 'fp-ts/lib/IO'; import * as TaskEither from 'fp-ts/lib/TaskEither'; @@ -92,16 +92,15 @@ const program = pipe( pipe( readFileToAnalyze(join(GITHUB_WORKSPACE, INPUT_FILE_PATH)), TaskEither.chain(content => createSpectralAnnotations(INPUT_FILE_PATH, INPUT_SPECTRAL_RULESET, content)), - TaskEither.chain(annotations => - updateGithubCheck( - octokit, - GITHUB_ACTION, - check, - event, - annotations, - annotations.findIndex(f => f.annotation_level === 'failure') === -1 ? 'success' : 'failure' - ) - ), + TaskEither.chain(annotations => { + info(`${annotations.length} annotations found on ${INPUT_FILE_PATH}`); + const failures = annotations.filter(f => f.annotation_level === 'failure'); + const conclusion = failures.length === 0 ? 'success' : 'failure'; + + if (conclusion === 'failure') setFailed(`Failed due to ${failures.length} failures`); + + return updateGithubCheck(octokit, GITHUB_ACTION, check, event, annotations, conclusion); + }), TaskEither.orElse(e => { setFailed(e.message); return updateGithubCheck(octokit, GITHUB_ACTION, check, event, [], 'failure', e.message); @@ -116,8 +115,8 @@ program().then(result => pipe( result, Either.fold( - e => error(e.message), - () => info('Worked fine') + e => setFailed(e.message), + res => info(`Linting completed with: ${JSON.stringify(res.data, undefined, 2)}`) ) ) ); diff --git a/yarn.lock b/yarn.lock index 210aebb..7099a7e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -222,10 +222,10 @@ resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== -"@types/node@>= 8", "@types/node@^12.12.12": - version "12.12.12" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.12.tgz#529bc3e73dbb35dd9e90b0a1c83606a9d3264bdb" - integrity sha512-MGuvYJrPU0HUwqF7LqvIj50RZUX23Z+m583KBygKYUZLlZ88n6w28XRNJRJgsHukLEnLz6w6SvxZoLgbr5wLqQ== +"@types/node@>= 8", "@types/node@^12.12.14": + version "12.12.14" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.14.tgz#1c1d6e3c75dba466e0326948d56e8bd72a1903d2" + integrity sha512-u/SJDyXwuihpwjXy7hOOghagLEV1KdAST6syfnOk6QZAMzZuWZqXy5aYYZbh8Jdpd4escVFP0MvftHNDb9pruA== "@types/normalize-package-data@^2.4.0": version "2.4.0"