From d2ecfd7a7aba7172d0ecf0b18a46348af61c4b5b Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Wed, 14 Sep 2022 11:27:35 -0500 Subject: [PATCH 1/7] init --- .github/scripts/lint-ecosystem.js | 2 +- docs/Guides/Ecosystem.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/scripts/lint-ecosystem.js b/.github/scripts/lint-ecosystem.js index 395fb97afc..f4af64e5b4 100644 --- a/.github/scripts/lint-ecosystem.js +++ b/.github/scripts/lint-ecosystem.js @@ -34,7 +34,7 @@ module.exports = async function ({ core }) { } const moduleNameTest = moduleNameRegex.exec(line) - + if (moduleNameTest === null) { core.error(`line ${lineNumber}: improper pattern, module name should be enclosed with backticks`) diff --git a/docs/Guides/Ecosystem.md b/docs/Guides/Ecosystem.md index e11aa2e796..c1f551e16e 100644 --- a/docs/Guides/Ecosystem.md +++ b/docs/Guides/Ecosystem.md @@ -16,8 +16,6 @@ section. multiple schemas and decide which one to use to serialize the payload - [`@fastify/auth`](https://github.com/fastify/fastify-auth) Run multiple auth functions in Fastify. -- [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all - plugins in a directory. - [`@fastify/awilix`](https://github.com/fastify/fastify-awilix) Dependency injection support for Fastify, based on [awilix](https://github.com/jeffijoe/awilix). @@ -133,6 +131,8 @@ section. rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify. - [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket support for Fastify. Built upon [ws](https://github.com/websockets/ws). +- [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all + plugins in a directory. #### [Community](#community) From ea87958d68dd46c2e93f783dab25de8a02fcbae4 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Wed, 14 Sep 2022 11:33:06 -0500 Subject: [PATCH 2/7] Update Ecosystem.md --- docs/Guides/Ecosystem.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/Guides/Ecosystem.md b/docs/Guides/Ecosystem.md index c1f551e16e..8816fb4980 100644 --- a/docs/Guides/Ecosystem.md +++ b/docs/Guides/Ecosystem.md @@ -2,6 +2,7 @@ ## Ecosystem + Plugins maintained by the Fastify team are listed under [Core](#core) while plugins maintained by the community are listed in the [Community](#community) section. From d76f52ccb62b96a8d6ed7b95728a4c6d9270b515 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Wed, 14 Sep 2022 11:34:18 -0500 Subject: [PATCH 3/7] Update Ecosystem.md --- docs/Guides/Ecosystem.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/Guides/Ecosystem.md b/docs/Guides/Ecosystem.md index 8816fb4980..c1f551e16e 100644 --- a/docs/Guides/Ecosystem.md +++ b/docs/Guides/Ecosystem.md @@ -2,7 +2,6 @@ ## Ecosystem - Plugins maintained by the Fastify team are listed under [Core](#core) while plugins maintained by the community are listed in the [Community](#community) section. From fd611aa4dda2c54d4a856f83586b52e2541ee325 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Wed, 14 Sep 2022 12:35:35 -0500 Subject: [PATCH 4/7] Add comment --- .github/scripts/lint-ecosystem.js | 11 +++++++++-- .github/workflows/lint-ecosystem-order.yml | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/scripts/lint-ecosystem.js b/.github/scripts/lint-ecosystem.js index f4af64e5b4..c43ae92a81 100644 --- a/.github/scripts/lint-ecosystem.js +++ b/.github/scripts/lint-ecosystem.js @@ -52,13 +52,20 @@ module.exports = async function ({ core }) { modules.push(moduleName) } + const failures = []; if (hasOutOfOrderItem === true) { - core.setFailed('Some ecosystem modules are not in alphabetical order.') + const failure = 'Some ecosystem modules are not in alphabetical order.' + failures.push(failure) + core.setFailed(failure) } if (hasImproperFormat === true) { - core.setFailed('Some ecosystem modules are improperly formatted.') + const failure = 'Some ecosystem modules are improperly formatted.' + failures.push(failure) + core.setFailed(failure) } + + return { failures } } function compare(current, previous) { diff --git a/.github/workflows/lint-ecosystem-order.yml b/.github/workflows/lint-ecosystem-order.yml index e93e37422b..f95e7d6736 100644 --- a/.github/workflows/lint-ecosystem-order.yml +++ b/.github/workflows/lint-ecosystem-order.yml @@ -30,5 +30,19 @@ jobs: with: script: | const script = require('./.github/scripts/lint-ecosystem.js') - await script({ core }) + const result = await script({ core }) + + const output = ` + ## :x: Failed: Lint Ecosystem Order + ${result.failures.map((failure) => '- ' + failure + '\n')} + + [View Details](https://github.com/fastify/fastify/actions/runs/${context.runId}/jobs/${context.job}) + `; + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) From acea73bd197042875bcf2f53911b54f28706dcc3 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Wed, 14 Sep 2022 14:36:31 -0500 Subject: [PATCH 5/7] move inside the script --- .github/scripts/lint-ecosystem.js | 37 +++++++++++++++++----- .github/workflows/lint-ecosystem-order.yml | 18 ++--------- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/scripts/lint-ecosystem.js b/.github/scripts/lint-ecosystem.js index c43ae92a81..7c2c133aa5 100644 --- a/.github/scripts/lint-ecosystem.js +++ b/.github/scripts/lint-ecosystem.js @@ -6,12 +6,12 @@ const readline = require('readline') const ecosystemDocFile = path.join(__dirname, '..', '..', 'docs', 'Guides', 'Ecosystem.md') -module.exports = async function ({ core }) { +module.exports = async function ({ core, github, context }) { const stream = await fs.createReadStream(ecosystemDocFile) const rl = readline.createInterface({ input: stream, crlfDelay: Infinity - }); + }) const moduleNameRegex = /^\- \[\`(.+)\`\]/ let hasOutOfOrderItem = false @@ -35,8 +35,7 @@ module.exports = async function ({ core }) { const moduleNameTest = moduleNameRegex.exec(line) - if (moduleNameTest === null) - { + if (moduleNameTest === null) { core.error(`line ${lineNumber}: improper pattern, module name should be enclosed with backticks`) hasImproperFormat = true continue @@ -52,7 +51,7 @@ module.exports = async function ({ core }) { modules.push(moduleName) } - const failures = []; + const failures = [] if (hasOutOfOrderItem === true) { const failure = 'Some ecosystem modules are not in alphabetical order.' failures.push(failure) @@ -65,13 +64,35 @@ module.exports = async function ({ core }) { core.setFailed(failure) } - return { failures } + handleFailures(failures, { core, github, context }) } -function compare(current, previous) { +function handleFailures (failures, workflow) { + const { github, context, core } = workflow; + + if (failures.length) { + + const output = ` + ## :x: Failed: Lint Ecosystem Order + + ${failures.map((failure) => '- ' + failure + '\n')} + + [View Details](https://github.com/fastify/fastify/actions/runs/${context.runId}/jobs/${context.job}) + ` + + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: output + }) + } +} + +function compare (current, previous) { return previous.localeCompare( current, 'en', - {sensitivity: 'base'} + { sensitivity: 'base' } ) } diff --git a/.github/workflows/lint-ecosystem-order.yml b/.github/workflows/lint-ecosystem-order.yml index f95e7d6736..266c22f843 100644 --- a/.github/workflows/lint-ecosystem-order.yml +++ b/.github/workflows/lint-ecosystem-order.yml @@ -28,21 +28,7 @@ jobs: - name: Lint Doc uses: actions/github-script@v6 with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | const script = require('./.github/scripts/lint-ecosystem.js') - const result = await script({ core }) - - const output = ` - ## :x: Failed: Lint Ecosystem Order - - ${result.failures.map((failure) => '- ' + failure + '\n')} - - [View Details](https://github.com/fastify/fastify/actions/runs/${context.runId}/jobs/${context.job}) - `; - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output - }) + await script({ core, context, github }) From d449d8e0d955697a4efc1d9b97561d7694eba0d5 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Sun, 18 Sep 2022 19:05:36 -0500 Subject: [PATCH 6/7] Fix issues, add annotiotations + summary --- .github/scripts/lint-ecosystem.js | 122 ++++++++++++++------- .github/workflows/lint-ecosystem-order.yml | 8 +- 2 files changed, 83 insertions(+), 47 deletions(-) diff --git a/.github/scripts/lint-ecosystem.js b/.github/scripts/lint-ecosystem.js index 7c2c133aa5..033c5a4c51 100644 --- a/.github/scripts/lint-ecosystem.js +++ b/.github/scripts/lint-ecosystem.js @@ -4,28 +4,41 @@ const path = require('path') const fs = require('fs') const readline = require('readline') -const ecosystemDocFile = path.join(__dirname, '..', '..', 'docs', 'Guides', 'Ecosystem.md') +const basePathEcosystemDocFile = path.join('docs', 'Guides', 'Ecosystem.md') +const ecosystemDocFile = path.join(__dirname, '..', '..', basePathEcosystemDocFile) +const failureTypes = { + improperFormat: 'improperFormat', + outOfOrderItem: 'outOfOrderItem' +} + +module.exports = async function ({ core }) { + const results = await runCheck() + await handleResults({ core }, results) +} -module.exports = async function ({ core, github, context }) { +async function runCheck () { const stream = await fs.createReadStream(ecosystemDocFile) const rl = readline.createInterface({ input: stream, crlfDelay: Infinity }) + const failures = [] + const successes = [] const moduleNameRegex = /^\- \[\`(.+)\`\]/ - let hasOutOfOrderItem = false let lineNumber = 0 let modules = [] - let hasImproperFormat = false + let grouping = 'core' for await (const line of rl) { lineNumber += 1 if (line.startsWith('#### [Community]')) { + grouping = 'community' modules = [] } if (line.startsWith('#### [Community Tools]')) { + grouping = 'community-tools' modules = [] } @@ -36,56 +49,85 @@ module.exports = async function ({ core, github, context }) { const moduleNameTest = moduleNameRegex.exec(line) if (moduleNameTest === null) { - core.error(`line ${lineNumber}: improper pattern, module name should be enclosed with backticks`) - hasImproperFormat = true + failures.push({ + lineNumber, + grouping, + moduleName: 'unknown', + type: failureTypes.improperFormat + }) continue } const moduleName = moduleNameTest[1] if (modules.length > 0) { if (compare(moduleName, modules.at(-1)) > 0) { - core.error(`line ${lineNumber}: ${moduleName} not listed in alphabetical order`) - hasOutOfOrderItem = true + failures.push({ + lineNumber, + moduleName, + grouping, + type: failureTypes.outOfOrderItem + }) + } else { + successes.push({ moduleName, lineNumber, grouping }) } + } else { + // We have to push the first item found or we are missing items from the list + successes.push({ moduleName, lineNumber, grouping }) } modules.push(moduleName) } - const failures = [] - if (hasOutOfOrderItem === true) { - const failure = 'Some ecosystem modules are not in alphabetical order.' - failures.push(failure) - core.setFailed(failure) - } - - if (hasImproperFormat === true) { - const failure = 'Some ecosystem modules are improperly formatted.' - failures.push(failure) - core.setFailed(failure) - } - - handleFailures(failures, { core, github, context }) + return { failures, successes } } -function handleFailures (failures, workflow) { - const { github, context, core } = workflow; - - if (failures.length) { - - const output = ` - ## :x: Failed: Lint Ecosystem Order - - ${failures.map((failure) => '- ' + failure + '\n')} - - [View Details](https://github.com/fastify/fastify/actions/runs/${context.runId}/jobs/${context.job}) - ` - - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: output +async function handleResults (scriptLibs, results) { + const { core } = scriptLibs + const { failures, successes } = results; + const isError = !!failures.length; + + await core.summary + .addHeading(isError ? `❌ Ecosystem.md Lint (${failures.length} error${failures.length === 1 ? '' : 's' })` : '✅ Ecosystem Lint (no errors found)') + .addTable([ + [ + { data: 'Status', header: true }, + { data: 'Section', header: true }, + { data: 'Module', header: true }, + { data: 'Details', header: true }], + ...failures.map((failure) => [ + '❌', + failure.grouping, + failure.moduleName, + `Line Number: ${failure.lineNumber.toString()} - ${failure.type}` + ]), + ...successes.map((success) => [ + '✅', + success.grouping, + success.moduleName, + '-' + ]) + ]) + .write() + + if (isError) { + failures.forEach((failure) => { + if (failure.type === failureTypes.improperFormat) { + core.error('The module name should be enclosed with backticks', { + title: 'Improper format', + file: basePathEcosystemDocFile, + startLine: failure.lineNumber + }) + } else if (failure.type === failureTypes.outOfOrderItem) { + core.error(`${failure.moduleName} not listed in alphabetical order`, { + title: 'Out of Order', + file: basePathEcosystemDocFile, + startLine: failure.lineNumber + }) + } else { + core.error('Unknown error') + } }) + + core.setFailed('Failed when linting Ecosystem.md') } } diff --git a/.github/workflows/lint-ecosystem-order.yml b/.github/workflows/lint-ecosystem-order.yml index 266c22f843..4fdcdb6ea4 100644 --- a/.github/workflows/lint-ecosystem-order.yml +++ b/.github/workflows/lint-ecosystem-order.yml @@ -1,12 +1,6 @@ name: Lint Ecosystem Order on: - push: - branches-ignore: - - master - - main - paths: - - "**/Ecosystem.md" pull_request: branches: - master @@ -31,4 +25,4 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const script = require('./.github/scripts/lint-ecosystem.js') - await script({ core, context, github }) + await script({ core }) From 4ac4b32550d2cee3583db0c56932707db27b4195 Mon Sep 17 00:00:00 2001 From: Zac Rosenbauer Date: Sun, 18 Sep 2022 19:08:57 -0500 Subject: [PATCH 7/7] reset file --- docs/Guides/Ecosystem.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Guides/Ecosystem.md b/docs/Guides/Ecosystem.md index c1f551e16e..e11aa2e796 100644 --- a/docs/Guides/Ecosystem.md +++ b/docs/Guides/Ecosystem.md @@ -16,6 +16,8 @@ section. multiple schemas and decide which one to use to serialize the payload - [`@fastify/auth`](https://github.com/fastify/fastify-auth) Run multiple auth functions in Fastify. +- [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all + plugins in a directory. - [`@fastify/awilix`](https://github.com/fastify/fastify-awilix) Dependency injection support for Fastify, based on [awilix](https://github.com/jeffijoe/awilix). @@ -131,8 +133,6 @@ section. rendering (_ejs, pug, handlebars, marko_) plugin support for Fastify. - [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket support for Fastify. Built upon [ws](https://github.com/websockets/ws). -- [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all - plugins in a directory. #### [Community](#community)