From 8d0d03556346aacf07fae9771ce53e1490b1e931 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:28:31 +0200 Subject: [PATCH 01/14] chore: add .editorconfig file --- .vscode/extensions.json | 5 +++++ src/.editorconfig | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 src/.editorconfig diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..f96e8e6 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,5 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=827846 + // for the documentation about the extensions.json format + "recommendations": ["editorconfig.editorconfig"] +} diff --git a/src/.editorconfig b/src/.editorconfig new file mode 100644 index 0000000..bdb290a --- /dev/null +++ b/src/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.{ts,yaml,yml,json,md}] +indent_style = space +indent_size = 2 From 74d47a3b0d3806905362c5c792ea58b79d16057e Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:30:01 +0200 Subject: [PATCH 02/14] chore: clean up TypeScript build --- Dockerfile | 25 ++++++++++++++++++------- package.json | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index eb7a937..5d38f2b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,23 +1,34 @@ -FROM node:13 as builder +FROM node:12 as builder -COPY package* ./ +COPY package.json yarn.lock ./ RUN yarn COPY src ./src COPY tsconfig.json tsconfig.json -RUN ./node_modules/.bin/tsc || true +RUN yarn +RUN yarn build || true + +############################################################### -FROM node:13 as installer +FROM node:12 as dependencies ENV NODE_ENV production -COPY package.json package.json +COPY package.json yarn.lock ./ RUN yarn --production -FROM node:13-alpine as runtime +RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash +RUN ./bin/node-prune + +############################################################### + +FROM node:12-alpine as runtime + ENV NODE_ENV production + COPY package.json /action/package.json + COPY --from=builder dist /action/dist -COPY --from=installer node_modules /action/node_modules +COPY --from=dependencies node_modules /action/node_modules ENTRYPOINT ["node", "/action/dist/index.js"] diff --git a/package.json b/package.json index a6739ee..c5333e8 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "src/index.ts", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "node dist/index.js" + "start": "node dist/index.js", + "build": "tsc -p tsconfig.json" }, "repository": { "type": "git", From ab9f09468831014ac97c5b07802f831427ea031f Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:31:05 +0200 Subject: [PATCH 03/14] chore: move dependencies under the proper package.json section --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index c5333e8..560a759 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,6 @@ }, "homepage": "https://github.com/XVincentX/spectral-action#readme", "devDependencies": { - "@octokit/graphql": "^4.3.1", - "@octokit/request": "^5.3.2", - "@octokit/rest": "^16.35.0", "@types/lodash": "^4.14.149", "@types/node": "^13.7.7", "@types/urijs": "^1.19.6", @@ -33,6 +30,9 @@ "dependencies": { "@actions/core": "^1.2.3", "@actions/github": "^2.1.1", + "@octokit/graphql": "^4.3.1", + "@octokit/request": "^5.3.2", + "@octokit/rest": "^16.35.0", "@stoplight/json": "^3.5.1", "@stoplight/spectral": "^5.1.0", "fast-glob": "^3.2.2", From 63c1faab0f8d482fe25b4695eb12d061d8d42410 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:33:00 +0200 Subject: [PATCH 04/14] chore: do not require from the user to pass the GitHub token --- .github/workflows/spectral.yml | 1 - action.yml | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/spectral.yml b/.github/workflows/spectral.yml index 5fc2dfe..6e77b57 100644 --- a/.github/workflows/spectral.yml +++ b/.github/workflows/spectral.yml @@ -12,5 +12,4 @@ jobs: uses: ./ with: file_glob: ./**/*.yml - repo_token: ${{ secrets.GITHUB_TOKEN }} spectral_ruleset: 'spectral:oas' diff --git a/action.yml b/action.yml index 78c73d3..428c75f 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,11 @@ inputs: default: 'spectral:oas' repo_token: required: true - description: Ruleset file to load in Spectral + description: | + The GitHub App installation access token. + + [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 }} runs: using: docker image: Dockerfile From 98edc5ca44c0623d58d48c49f4b6050c4c9b80e4 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:34:00 +0200 Subject: [PATCH 05/14] chore: use fixed version of dependent actions --- .github/workflows/spectral.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/spectral.yml b/.github/workflows/spectral.yml index 6e77b57..3578003 100644 --- a/.github/workflows/spectral.yml +++ b/.github/workflows/spectral.yml @@ -7,7 +7,7 @@ jobs: name: Spectral checks runs-on: ubuntu-latest steps: - - uses: actions/checkout@master + - uses: actions/checkout@v2 - name: Spectral checks uses: ./ with: From e8ae7980abe8ff931a150afd4c8f9c06d39d0d5d Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:37:51 +0200 Subject: [PATCH 06/14] chore: move test file under a fixtures folder --- test.oas.yml => fixtures/test.oas.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test.oas.yml => fixtures/test.oas.yml (100%) diff --git a/test.oas.yml b/fixtures/test.oas.yml similarity index 100% rename from test.oas.yml rename to fixtures/test.oas.yml From 7fa7f6e6ece5eaf3800fb2907dbf0eda768a7643 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:44:25 +0200 Subject: [PATCH 07/14] feat: support custom rulesets --- .github/workflows/spectral.yml | 2 +- .my-custom.spectral.yml | 15 ++++++++++ action.yml | 9 ++++-- package.json | 2 +- src/index.ts | 18 +++++++----- src/spectral.ts | 33 +++++++++++++++++++-- tsconfig.json | 3 +- yarn.lock | 53 ++++++++++++++++++++++------------ 8 files changed, 100 insertions(+), 35 deletions(-) create mode 100644 .my-custom.spectral.yml diff --git a/.github/workflows/spectral.yml b/.github/workflows/spectral.yml index 3578003..e8b78cc 100644 --- a/.github/workflows/spectral.yml +++ b/.github/workflows/spectral.yml @@ -12,4 +12,4 @@ jobs: uses: ./ with: file_glob: ./**/*.yml - spectral_ruleset: 'spectral:oas' + spectral_ruleset: .my-custom.spectral.yml diff --git a/.my-custom.spectral.yml b/.my-custom.spectral.yml new file mode 100644 index 0000000..407d531 --- /dev/null +++ b/.my-custom.spectral.yml @@ -0,0 +1,15 @@ +extends: spectral:oas + +except: + 'fixtures/test.oas.yml#/paths/~1todos/get': + - operation-description + + 'fixtures/non_existent.yml#': + - oas3-api-servers + - openapi-tags + + 'fixtures/non_existent.yml#/info': + - info-contact + + 'fixtures/non_existent.yml#/paths/~1todos/get': + - operation-description diff --git a/action.yml b/action.yml index 428c75f..3fac729 100644 --- a/action.yml +++ b/action.yml @@ -7,9 +7,12 @@ inputs: description: The file path to lint with Spectral default: '*.oas.{json,yml,yaml}' spectral_ruleset: - required: true - description: Ruleset file to load in Spectral - default: 'spectral:oas' + required: false + description: | + Custom ruleset to load in Spectral. + + When unspecified, will try to load the default `.spectral.yaml` ruleset if it exists. + Otherwise, the default built-in Spectral rulesets will be loaded. repo_token: required: true description: | diff --git a/package.json b/package.json index 560a759..48dfc57 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@octokit/request": "^5.3.2", "@octokit/rest": "^16.35.0", "@stoplight/json": "^3.5.1", - "@stoplight/spectral": "^5.1.0", + "@stoplight/spectral": "^5.3.0", "fast-glob": "^3.2.2", "fp-ts": "^2.5.3", "io-ts": "^2.1.2", diff --git a/src/index.ts b/src/index.ts index ae5f24f..e388054 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { promises as fs } from 'fs'; import { array } from 'fp-ts/lib/Array'; import { flatten } from 'lodash'; import { Config } from './config'; -import { runSpectral, createSpectral } from './spectral'; +import { runSpectral, createSpectral, fileWithContent } from './spectral'; import { createGithubCheck, createOctokitInstance, getRepositoryInfoFromEvent, updateGithubCheck } from './octokit'; import glob from 'fast-glob'; import { error, info, setFailed } from '@actions/core'; @@ -23,7 +23,6 @@ import * as path from 'path'; const CHECK_NAME = 'Lint'; const traverseTask = array.traverse(T.task); -type fileWithContent = { file: string; content: string }; const createSpectralAnnotations = (ruleset: string, parsed: fileWithContent[], basePath: string) => pipe( @@ -31,8 +30,11 @@ const createSpectralAnnotations = (ruleset: string, parsed: fileWithContent[], b TE.chain(spectral => { const spectralRuns = parsed.map(v => pipe( - runSpectral(spectral, v.content), - TE.map(rules => ({ path: v.file, rules })) + runSpectral(spectral, v), + TE.map(results => { + + return { path: v.path, results }; + }) ) ); return array.sequence(TE.taskEither)(spectralRuns); @@ -40,7 +42,7 @@ const createSpectralAnnotations = (ruleset: string, parsed: fileWithContent[], b TE.map(results => flatten( results.map(validationResult => { - return validationResult.rules.map(vl => { + return validationResult.results.map(vl => { const annotation_level: ChecksUpdateParamsOutputAnnotations['annotation_level'] = vl.severity === DiagnosticSeverity.Error ? 'failure' @@ -77,10 +79,10 @@ const readFilesToAnalyze = (path: string) => { }), TE.chain(fileList => pipe( - traverseTask(fileList, file => + traverseTask(fileList, path => pipe( - readFile(file), - TE.map(content => ({ file, content })) + readFile(path), + TE.map(content => ({ path, content })) ) ), T.map(e => { diff --git a/src/spectral.ts b/src/spectral.ts index dd73af9..0c32a80 100644 --- a/src/spectral.ts +++ b/src/spectral.ts @@ -1,3 +1,5 @@ +import { getRuleset } from '@stoplight/spectral/dist/cli/services/linter/utils'; +import { isRuleEnabled } from '@stoplight/spectral/dist/runner'; import { httpAndFileResolver } from '@stoplight/spectral/dist/resolvers/http-and-file'; import { Spectral, @@ -14,7 +16,17 @@ import { import { tryCatch } from 'fp-ts/lib/TaskEither'; import { toError } from 'fp-ts/lib/Either'; -export const createSpectral = (ruleset: string) => { +const normalizeRulesetPath = (rulesetPath: string): [string] | undefined => { + if (rulesetPath.length === 0) { + info(`Loading built-in rulesets...`); + return undefined; + } + + info(`Loading ruleset '${rulesetPath}'...`); + return [rulesetPath]; +}; + +export const createSpectral = (rulesetPath: string) => { return tryCatch(async () => { const spectral = new Spectral({ resolver: httpAndFileResolver }); spectral.registerFormat('oas2', isOpenApiv2); @@ -25,9 +37,24 @@ export const createSpectral = (ruleset: string) => { spectral.registerFormat('json-schema-draft6', isJSONSchemaDraft6); spectral.registerFormat('json-schema-draft7', isJSONSchemaDraft7); spectral.registerFormat('json-schema-2019-09', isJSONSchemaDraft2019_09); - await spectral.loadRuleset(ruleset); + + const normRuleSetPath = normalizeRulesetPath(rulesetPath); + const ruleset = await getRuleset(normRuleSetPath); + spectral.setRuleset(ruleset); + return spectral; }, toError); }; -export const runSpectral = (spectral: Spectral, parsed: string) => tryCatch(() => spectral.run(parsed), toError); +export type fileWithContent = { path: string; content: string }; + +export const runSpectral = (spectral: Spectral, fileDescription: fileWithContent) => { + return tryCatch( + () => + spectral.run(fileDescription.content, { + ignoreUnknownFormat: false, + resolve: { documentUri: fileDescription.path }, + }), + toError + ); +}; diff --git a/tsconfig.json b/tsconfig.json index a57d381..bf8a3ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true + "noFallthroughCasesInSwitch": true, + "resolveJsonModule": true } } diff --git a/yarn.lock b/yarn.lock index 77f226e..42746f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -242,7 +242,7 @@ lodash "^4.17.15" safe-stable-stringify "^1.1" -"@stoplight/json@^3.4.0", "@stoplight/json@^3.5.1": +"@stoplight/json@^3.5.1": version "3.5.1" resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.5.1.tgz#afc6ffcbe2ada8f9b16680fd7885688cf9beec7e" integrity sha512-O5WUW2yfAvtrqeq60YrbxpTvk87Ti2IeJ5oVa2XNJ2s+IIxx0CM+j316QoOjSGs+twrRpwb3jT9CFPrq7Ghkzg== @@ -252,22 +252,38 @@ lodash "^4.17.15" safe-stable-stringify "^1.1" +"@stoplight/json@^3.6.0": + version "3.7.1" + resolved "https://registry.yarnpkg.com/@stoplight/json/-/json-3.7.1.tgz#3855478ed3e0baaee6a7627948957ce537e481ad" + integrity sha512-5VUVZxO7Jg+yoyEPa+ymD+fz5Pij96Nv3ei8FpzkzJwZLqY0ycAe8pBTz1mMf9QDUB+7HZZnCrWGCqGtDLYZZA== + dependencies: + "@stoplight/ordered-object-literal" "^1.0.1" + "@stoplight/types" "^11.4.0" + jsonc-parser "~2.2.0" + lodash "^4.17.15" + safe-stable-stringify "^1.1" + +"@stoplight/ordered-object-literal@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@stoplight/ordered-object-literal/-/ordered-object-literal-1.0.1.tgz#01ece81ba5dda199ca3dc5ec7464691efa5d5b76" + integrity sha512-kDcBIKwzAXZTkgzaiPXH2I0JXavBkOb3jFzYNFS5cBuvZS3s/K+knpk2wLVt0n8XrnRQsSffzN6XG9HqUhfq6Q== + "@stoplight/path@^1.3.0": version "1.3.0" resolved "https://registry.yarnpkg.com/@stoplight/path/-/path-1.3.0.tgz#da2282352a4eb23c09d5106b9d1650d30a9ca2ad" integrity sha512-t74/MHMgmFVMQhdQ/2Q766GryNTIW8McH8+vB25oeoBhYKTOrJ/wPDt+OCxIWHPUlcSi2fTWa4FKQ8qgmP2jVA== -"@stoplight/spectral@^5.1.0": - version "5.1.0" - resolved "https://registry.yarnpkg.com/@stoplight/spectral/-/spectral-5.1.0.tgz#1abb3b377f9e17e10950da0e69e4a5acc63042eb" - integrity sha512-Uwm5ZGE5dqsc6lsAMAnA2VKOHw7ey77SLluu52hyCBPfYZN/WmPfO6AaWbM38cR84TnuDnvvwoOjRzLWDOCdBA== +"@stoplight/spectral@^5.3.0": + version "5.3.0" + resolved "https://registry.yarnpkg.com/@stoplight/spectral/-/spectral-5.3.0.tgz#6807233000ec9f1593c343f74aecde8e6d3e04bf" + integrity sha512-8Om4sfyE9XV4obaU6i6qF7PumwA7zYgf/VoAuffQdXNRcwKd1LvXbiWu0eMp7ueue5B91KoXKABiY/PbHKBdIA== dependencies: - "@stoplight/json" "^3.4.0" + "@stoplight/json" "^3.6.0" "@stoplight/json-ref-readers" "^1.1.1" "@stoplight/json-ref-resolver" "^3.0.6" "@stoplight/path" "^1.3.0" "@stoplight/types" "^11.2.0" - "@stoplight/yaml" "^3.5.0" + "@stoplight/yaml" "^3.7.0" abort-controller "^3.0.0" ajv "^6.10" ajv-oai "^1.1.5" @@ -278,7 +294,7 @@ fast-glob "^3.1.0" jsonpath-plus "~2.0" lodash ">=4.17.5" - nanoid "^2.1.6" + nanoid "^2.1.11" node-fetch "^2.6" proxy-agent "^3.1.1" strip-ansi "^6.0" @@ -300,18 +316,19 @@ dependencies: "@types/json-schema" "^7.0.3" -"@stoplight/yaml-ast-parser@0.0.44": - version "0.0.44" - resolved "https://registry.yarnpkg.com/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.44.tgz#ed3c962564283e9983f7895a6effc3994286df5e" - integrity sha512-PdY8p2Ufgtorf4d2DbKMfknILMa8KwuyyMMR/2lgK1mLaU8F5PKWYc+h9hIzC+ar0bh7m9h2rINo32m7ADfVyA== +"@stoplight/yaml-ast-parser@0.0.45": + version "0.0.45" + resolved "https://registry.yarnpkg.com/@stoplight/yaml-ast-parser/-/yaml-ast-parser-0.0.45.tgz#672c0a1511d581843be5a9c55899ca95a30dcadb" + integrity sha512-0MTEvgp3XMdeMUSTCGiNECuC+YlLbzytDEIOJVDHrrmzVZpIR3gGnHI6mmPI4P7saPxUiHxFF2uuoTuCNlKjrw== -"@stoplight/yaml@^3.5.0": - version "3.5.2" - resolved "https://registry.yarnpkg.com/@stoplight/yaml/-/yaml-3.5.2.tgz#6674341ecf08c0024988f6b83d0a6f7a73bfbef1" - integrity sha512-hTxAvQeHn87XgxUVi7BFzIrvBANy/Q2A3O6PHmrzqOTbGoN7p7J3kRliiV35ZPOg/6q50QttMYO3BGFyemRLlw== +"@stoplight/yaml@^3.7.0": + version "3.8.1" + resolved "https://registry.yarnpkg.com/@stoplight/yaml/-/yaml-3.8.1.tgz#2a2accdb8b3b6df5c3f1ba93086ca9deb99be0e4" + integrity sha512-wbhcgo7dTjwjjwFziC/SAcQlwPucYhYq6vjzyOjj8zeOVnnmoa7hzU1i9Kj31473FG/re7xtt6j3LWu2VnYbxg== dependencies: + "@stoplight/ordered-object-literal" "^1.0.1" "@stoplight/types" "^11.1.1" - "@stoplight/yaml-ast-parser" "0.0.44" + "@stoplight/yaml-ast-parser" "0.0.45" lodash "^4.17.15" "@types/color-name@^1.1.1": @@ -1240,7 +1257,7 @@ multimatch@^4.0.0: arrify "^2.0.1" minimatch "^3.0.4" -nanoid@^2.1.6: +nanoid@^2.1.11: version "2.1.11" resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280" integrity sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA== From dafd2dce8f10f44bcb9e7887b923a7cb21f20dc5 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:46:16 +0200 Subject: [PATCH 08/14] chore: enhance documentation --- README.md | 39 +++++++++++++++++++++++++++++++++++---- action.yml | 2 +- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bcd1a66..7b6bd07 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,38 @@ -# Spectral Lint Action +# Spectral Linter Action -![](https://raw.githubusercontent.com/stoplightio/spectral/master/img/spectral-banner.png) - -This action uses [Spectral 4.x](https://github.com/stoplightio/spectral) to lint your OpenAPI files. +This action uses [Spectral](https://github.com/stoplightio/spectral) from [Stoplight](https://stoplight.io/) to lint your OpenAPI documents, or any other JSON/YAML files. ![](./image.png) + +## Usage + +See [action.yml](action.yml) + +```yaml +name: Run Spectral on Pull Requests + +on: + - pull_request + +jobs: + build: + name: Run Spectral + runs-on: ubuntu-latest + steps: + # Check out the repository + - uses: actions/checkout@v2 + + # Run Spectral + - uses: stoplightio/spectral-action@v0.5.5 + with: + file_glob: 'doc/api/*.yaml' +``` + +### Inputs + +- **file_glob:** Pattern describing the set of files to lint. Defaults to `*.oas.{json,yml,yaml}`. (_Note:_ Pattern syntax is documented in the [fast-glob](https://www.npmjs.com/package/fast-glob) package documentation) +- **spectral_ruleset:** Custom ruleset to load in Spectral. When unspecified, will try to load the default `.spectral.yaml` ruleset if it exists; otherwise, the default built-in Spectral rulesets will be loaded. + +## Configuration + +Spectral Action will respect your [Spectral Rulesets](https://stoplight.io/p/docs/gh/stoplightio/spectral/docs/getting-started/rulesets.md), which can be defined, extended, and overriden by placing `.spectral.yml` in the root of your repository. diff --git a/action.yml b/action.yml index 3fac729..4802796 100644 --- a/action.yml +++ b/action.yml @@ -4,7 +4,7 @@ description: Lint your files with Spectral inputs: file_glob: required: true - description: The file path to lint with Spectral + description: The pattern describing the file paths to lint with Spectral default: '*.oas.{json,yml,yaml}' spectral_ruleset: required: false From 78bd149d61b05b2af9fb9a3fa9f0e9106fc0e315 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:51:46 +0200 Subject: [PATCH 09/14] fix: do not create the checkrun with the default 'queued' status --- src/octokit.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octokit.ts b/src/octokit.ts index 1a10bfc..7d2d0f7 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -28,6 +28,7 @@ export const createGithubCheck = ( repo: event.repo, name, head_sha, + status: 'in_progress', }), E.toError ); From 787c73b65204d45dc6dbac24b3342bc70df87bea Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:53:22 +0200 Subject: [PATCH 10/14] chore: enhance logging --- src/index.ts | 19 +++++++--- src/spectral.ts | 96 +++++++++++++++++++++++++++++++++++++------------ 2 files changed, 87 insertions(+), 28 deletions(-) diff --git a/src/index.ts b/src/index.ts index e388054..c9a57ee 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { promises as fs } from 'fs'; import { array } from 'fp-ts/lib/Array'; import { flatten } from 'lodash'; import { Config } from './config'; -import { runSpectral, createSpectral, fileWithContent } from './spectral'; +import { runSpectral, createSpectral, fileWithContent, pluralizer } from './spectral'; import { createGithubCheck, createOctokitInstance, getRepositoryInfoFromEvent, updateGithubCheck } from './octokit'; import glob from 'fast-glob'; import { error, info, setFailed } from '@actions/core'; @@ -32,6 +32,13 @@ const createSpectralAnnotations = (ruleset: string, parsed: fileWithContent[], b pipe( runSpectral(spectral, v), TE.map(results => { + info(`Done linting '${v.path}'`); + + if (results.length === 0) { + info(' No issue detected'); + } else { + info(` /!\\ ${pluralizer(results.length, 'issue')} detected`); + } return { path: v.path, results }; }) @@ -68,13 +75,15 @@ const createSpectralAnnotations = (ruleset: string, parsed: fileWithContent[], b ) ); -const readFilesToAnalyze = (path: string) => { +const readFilesToAnalyze = (pattern: string, workingDir: string) => { + const path = join(workingDir, pattern); + const readFile = (file: string) => TE.tryCatch(() => fs.readFile(file, { encoding: 'utf8' }), E.toError); return pipe( TE.tryCatch(() => glob(path), E.toError), TE.map(fileList => { - info(`Files to check: ${fileList.join(',')}`); + info(`Using glob '${pattern}' under '${workingDir}', found ${pluralizer(fileList.length, 'file')} to lint`); return fileList; }), TE.chain(fileList => @@ -128,7 +137,7 @@ const program = pipe( ), TE.chain(({ octokit, event, check }) => pipe( - readFilesToAnalyze(join(GITHUB_WORKSPACE, INPUT_FILE_GLOB)), + readFilesToAnalyze(INPUT_FILE_GLOB, GITHUB_WORKSPACE), TE.chain(fileContents => createSpectralAnnotations(INPUT_SPECTRAL_RULESET, fileContents, GITHUB_WORKSPACE)), TE.chain(annotations => updateGithubCheck( @@ -155,7 +164,7 @@ program().then(result => result, E.fold( e => error(e.message), - () => info('Worked fine') + () => info('Analysis is complete') ) ) ); diff --git a/src/spectral.ts b/src/spectral.ts index 0c32a80..7f80475 100644 --- a/src/spectral.ts +++ b/src/spectral.ts @@ -1,4 +1,5 @@ import { getRuleset } from '@stoplight/spectral/dist/cli/services/linter/utils'; +import { pluralize } from '@stoplight/spectral/dist/formatters/utils'; import { isRuleEnabled } from '@stoplight/spectral/dist/runner'; import { httpAndFileResolver } from '@stoplight/spectral/dist/resolvers/http-and-file'; import { @@ -13,8 +14,32 @@ import { isOpenApiv3, } from '@stoplight/spectral'; -import { tryCatch } from 'fp-ts/lib/TaskEither'; -import { toError } from 'fp-ts/lib/Either'; +import * as IOEither from 'fp-ts/lib/IOEither'; +import * as TE from 'fp-ts/lib/TaskEither'; +import * as E from 'fp-ts/lib/Either'; +import { pipe } from 'fp-ts/lib/pipeable'; + +import { info } from '@actions/core'; + +export const pluralizer = (howMany: number, word: string) => { + return `${howMany} ${pluralize(word, howMany)}`; +}; + +const evaluateNumberOfExceptions = (exceptions: Record) => { + const reduced = Object.keys(exceptions).reduce( + (acc, cur) => { + acc.uniqueFilePaths.add(cur.split('#')[0]); + acc.numberOfExceptions += exceptions[cur].length; + return acc; + }, + { numberOfExceptions: 0, uniqueFilePaths: new Set() } + ); + + return { + numberOfExceptions: reduced.numberOfExceptions, + numberOfFiles: reduced.uniqueFilePaths.size, + }; +}; const normalizeRulesetPath = (rulesetPath: string): [string] | undefined => { if (rulesetPath.length === 0) { @@ -26,35 +51,60 @@ const normalizeRulesetPath = (rulesetPath: string): [string] | undefined => { return [rulesetPath]; }; -export const createSpectral = (rulesetPath: string) => { - return tryCatch(async () => { - const spectral = new Spectral({ resolver: httpAndFileResolver }); - spectral.registerFormat('oas2', isOpenApiv2); - spectral.registerFormat('oas3', isOpenApiv3); - spectral.registerFormat('json-schema', isJSONSchema); - spectral.registerFormat('json-schema-loose', isJSONSchemaLoose); - spectral.registerFormat('json-schema-draft4', isJSONSchemaDraft4); - spectral.registerFormat('json-schema-draft6', isJSONSchemaDraft6); - spectral.registerFormat('json-schema-draft7', isJSONSchemaDraft7); - spectral.registerFormat('json-schema-2019-09', isJSONSchemaDraft2019_09); - - const normRuleSetPath = normalizeRulesetPath(rulesetPath); - const ruleset = await getRuleset(normRuleSetPath); - spectral.setRuleset(ruleset); - - return spectral; - }, toError); -}; +const retrieveSpectralPackageVersion = (): IOEither.IOEither => + IOEither.tryCatch(() => { + const x = require('../node_modules/@stoplight/spectral/package.json'); + return String(x.version); + }, E.toError); + +export const createSpectral = (rulesetPath: string) => + pipe( + TE.fromIOEither(retrieveSpectralPackageVersion()), + TE.chain(spectralPackageVersion => + TE.tryCatch(async () => { + info(`Running Spectral v${spectralPackageVersion}`); + + const spectral = new Spectral({ resolver: httpAndFileResolver }); + spectral.registerFormat('oas2', isOpenApiv2); + spectral.registerFormat('oas3', isOpenApiv3); + spectral.registerFormat('json-schema', isJSONSchema); + spectral.registerFormat('json-schema-loose', isJSONSchemaLoose); + spectral.registerFormat('json-schema-draft4', isJSONSchemaDraft4); + spectral.registerFormat('json-schema-draft6', isJSONSchemaDraft6); + spectral.registerFormat('json-schema-draft7', isJSONSchemaDraft7); + spectral.registerFormat('json-schema-2019-09', isJSONSchemaDraft2019_09); + + const normRuleSetPath = normalizeRulesetPath(rulesetPath); + const ruleset = await getRuleset(normRuleSetPath); + info(`Loading ruleset '${rulesetPath}'...`); + info(`Loading built-in rulesets...`); + spectral.setRuleset(ruleset); + + const loadedRules = Object.values(spectral.rules); + info(` - ${pluralizer(loadedRules.length, 'rule')} (${loadedRules.filter(isRuleEnabled).length} enabled)`); + + const exceptionsStats = evaluateNumberOfExceptions(ruleset.exceptions); + info( + ` - ${pluralizer(exceptionsStats.numberOfExceptions, 'exception')} (spanning ${pluralizer( + exceptionsStats.numberOfFiles, + 'file' + )})` + ); + + return spectral; + }, E.toError) + ) + ); export type fileWithContent = { path: string; content: string }; export const runSpectral = (spectral: Spectral, fileDescription: fileWithContent) => { - return tryCatch( + return TE.tryCatch( () => spectral.run(fileDescription.content, { ignoreUnknownFormat: false, resolve: { documentUri: fileDescription.path }, }), - toError + E.toError ); }; From 4bfd7352ea1277521ac2c2beef8d87f42d57a5a9 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 09:54:03 +0200 Subject: [PATCH 11/14] chore: track a potential future enhancement --- src/octokit.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/octokit.ts b/src/octokit.ts index 7d2d0f7..6e28ac0 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -72,6 +72,11 @@ export const updateGithubCheck = ( : conclusion === 'success' ? 'Lint completed successfully' : 'Lint completed with some errors', + + // TODO: Split calls when annotations.length > 50 + // From https://octokit.github.io/rest.js/v17#checks-update + // => "The Checks API limits the number of annotations to a maximum of 50 per API request. + // To create more than 50 annotations, you have to make multiple requests to the Update a check run endpoint." annotations, }, }), From a0b1317c773236d337837b44bbbf449bc4e27cde Mon Sep 17 00:00:00 2001 From: nulltoken Date: Sun, 26 Apr 2020 10:32:29 +0200 Subject: [PATCH 12/14] chore: fail the main action on fatal linting errors --- src/index.ts | 27 +++++++++++++++++++-------- src/spectral.ts | 6 +----- src/utils.ts | 5 +++++ 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 src/utils.ts diff --git a/src/index.ts b/src/index.ts index c9a57ee..d8202db 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,8 @@ import { promises as fs } from 'fs'; import { array } from 'fp-ts/lib/Array'; import { flatten } from 'lodash'; import { Config } from './config'; -import { runSpectral, createSpectral, fileWithContent, pluralizer } from './spectral'; +import { runSpectral, createSpectral, fileWithContent } from './spectral'; +import { pluralizer } from './utils'; import { createGithubCheck, createOctokitInstance, getRepositoryInfoFromEvent, updateGithubCheck } from './octokit'; import glob from 'fast-glob'; import { error, info, setFailed } from '@actions/core'; @@ -140,13 +141,23 @@ const program = pipe( readFilesToAnalyze(INPUT_FILE_GLOB, GITHUB_WORKSPACE), TE.chain(fileContents => createSpectralAnnotations(INPUT_SPECTRAL_RULESET, fileContents, GITHUB_WORKSPACE)), TE.chain(annotations => - updateGithubCheck( - octokit, - CHECK_NAME, - check, - event, - annotations, - annotations.findIndex(f => f.annotation_level === 'failure') === -1 ? 'success' : 'failure' + pipe( + updateGithubCheck( + octokit, + CHECK_NAME, + check, + event, + annotations, + annotations.findIndex(f => f.annotation_level === 'failure') === -1 ? 'success' : 'failure' + ), + TE.map(checkResponse => { + 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 => { diff --git a/src/spectral.ts b/src/spectral.ts index 7f80475..1ec4ebe 100644 --- a/src/spectral.ts +++ b/src/spectral.ts @@ -1,5 +1,4 @@ import { getRuleset } from '@stoplight/spectral/dist/cli/services/linter/utils'; -import { pluralize } from '@stoplight/spectral/dist/formatters/utils'; import { isRuleEnabled } from '@stoplight/spectral/dist/runner'; import { httpAndFileResolver } from '@stoplight/spectral/dist/resolvers/http-and-file'; import { @@ -20,10 +19,7 @@ import * as E from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import { info } from '@actions/core'; - -export const pluralizer = (howMany: number, word: string) => { - return `${howMany} ${pluralize(word, howMany)}`; -}; +import { pluralizer } from './utils'; const evaluateNumberOfExceptions = (exceptions: Record) => { const reduced = Object.keys(exceptions).reduce( diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..791e2bd --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,5 @@ +import { pluralize } from '@stoplight/spectral/dist/formatters/utils'; + +export const pluralizer = (howMany: number, word: string) => { + return `${howMany} ${pluralize(word, howMany)}`; +}; From b277ed15e4f572d35cc20baae3cf20d4448cf2a5 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 27 Apr 2020 09:57:45 +0200 Subject: [PATCH 13/14] fix: tie annotations to proper commit --- src/config.ts | 1 - src/index.ts | 90 ++++++++++++++++++++++++++------------------------ src/octokit.ts | 24 ++++++++------ 3 files changed, 59 insertions(+), 56 deletions(-) diff --git a/src/config.ts b/src/config.ts index cbe8fd2..cc8bb81 100644 --- a/src/config.ts +++ b/src/config.ts @@ -3,7 +3,6 @@ import * as t from 'io-ts'; export const Config = t.strict({ GITHUB_EVENT_PATH: t.string, INPUT_REPO_TOKEN: t.string, - GITHUB_SHA: t.string, GITHUB_WORKSPACE: t.string, INPUT_FILE_GLOB: t.string, GITHUB_ACTION: t.string, diff --git a/src/index.ts b/src/index.ts index d8202db..13e8ce8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -120,53 +120,55 @@ const createConfigFromEnv = pipe( const program = pipe( TE.fromIOEither(createConfigFromEnv), - TE.chain( - ({ GITHUB_EVENT_PATH, INPUT_REPO_TOKEN, GITHUB_SHA, 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, GITHUB_SHA), - 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 => { - const fatalErrors = annotations.filter(a => a.annotation_level === 'failure'); - if (fatalErrors.length > 0) { - setFailed(`${pluralizer(fatalErrors.length, 'fatal issue')} detected. Failing the process.`); - } + 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 => { + info( + `Commit ${event.sha} has been annotated (https://github.com/${event.owner}/${event.owner}/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_NAME, check, event, [], 'failure', e.message); - }) - ) + return checkResponse; + }) + ) + ), + TE.orElse(e => { + setFailed(e.message); + return updateGithubCheck(octokit, CHECK_NAME, check, event, [], 'failure', e.message); + }) ) ) + ) ) ); diff --git a/src/octokit.ts b/src/octokit.ts index 6e28ac0..79678dd 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -5,6 +5,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { ChecksCreateResponse, ChecksUpdateParamsOutputAnnotations, ChecksUpdateParams, Response } from '@octokit/rest'; type Event = { + after: string; repository: { name: string; owner: { @@ -15,34 +16,35 @@ type Event = { export const createOctokitInstance = (token: string) => TE.fromEither(E.tryCatch(() => new GitHub(token), E.toError)); -export const createGithubCheck = ( - octokit: GitHub, - event: { owner: string; repo: string }, - name: string, - head_sha: string -) => +export const createGithubCheck = (octokit: GitHub, event: IRepositoryInfo, name: string) => TE.tryCatch( () => octokit.checks.create({ owner: event.owner, repo: event.repo, name, - head_sha, + head_sha: event.sha, status: 'in_progress', }), E.toError ); -export const getRepositoryInfoFromEvent = (eventPath: string) => +export interface IRepositoryInfo { + owner: string; + repo: string; + sha: string; +} + +export const getRepositoryInfoFromEvent = (eventPath: string): TE.TaskEither => pipe( TE.fromEither(E.tryCatch(() => require(eventPath), E.toError)), TE.map(event => { - const { repository } = event; + const { repository, after } = event; const { owner: { login: owner }, } = repository; const { name: repo } = repository; - return { owner, repo }; + return { owner, repo, sha: after }; }) ); @@ -50,7 +52,7 @@ export const updateGithubCheck = ( octokit: GitHub, actionName: string, check: Response, - event: { owner: string; repo: string }, + event: IRepositoryInfo, annotations: ChecksUpdateParamsOutputAnnotations[], conclusion: ChecksUpdateParams['conclusion'], message?: string From 13042a4bc8944de0e579ce394f7b283aab21a56a Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 27 Apr 2020 10:20:58 +0200 Subject: [PATCH 14/14] 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'