diff --git a/.github/scripts/lint-ecosystem.js b/.github/scripts/lint-ecosystem.js new file mode 100644 index 00000000000..f81546e9b77 --- /dev/null +++ b/.github/scripts/lint-ecosystem.js @@ -0,0 +1,59 @@ +'use strict' + +const path = require('path') +const fs = require('fs') +const readline = require('readline') + +const ecosystemDocFile = path.join(__dirname, '..', '..', 'docs', 'Guides', 'Ecosystem.md') + +module.exports = async function ({ core }) { + const stream = await fs.createReadStream(ecosystemDocFile) + const rl = readline.createInterface({ + input: stream, + crlfDelay: Infinity + }); + + const moduleNameRegex = /^\- \[\`(.+)\`\]/ + let hasOutOfOrderItem = false + let lineNumber = 0 + let inCommmunitySection = false + let modules = [] + + for await (const line of rl) { + lineNumber += 1 + if (line.startsWith('#### [Community]')) { + inCommmunitySection = true + } + if (line.startsWith('#### [Community Tools]')) { + inCommmunitySection = false + } + if (inCommmunitySection === false) { + continue + } + + if (line.startsWith('- [`') !== true) { + continue + } + + const moduleName = moduleNameRegex.exec(line)[1] + if (modules.length > 0) { + if (compare(moduleName, modules.at(-1)) > 0) { + core.error(`line ${lineNumber}: ${moduleName} not listed in alphabetical order`) + hasOutOfOrderItem = true + } + } + modules.push(moduleName) + } + + if (hasOutOfOrderItem === true) { + core.setFailed('Some ecosystem modules are not in alphabetical order.') + } +} + +function compare(current, previous) { + return previous.localeCompare( + current, + 'en', + {sensitivity: 'base'} + ) +} diff --git a/.github/workflows/lint-ecosystem-order.yml b/.github/workflows/lint-ecosystem-order.yml new file mode 100644 index 00000000000..6a00f1aa7c8 --- /dev/null +++ b/.github/workflows/lint-ecosystem-order.yml @@ -0,0 +1,34 @@ +name: Lint Ecosystem Order + +on: + push: + branches-ignore: + - master + - main + # paths: + # - "**/Ecosystem.md" + pull_request: + branches: + - master + - main + # paths: + # - "**/Ecosystem.md" + +jobs: + build: + name: Lint Ecosystem Order + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + persist-credentials: false + + - name: Lint Doc + uses: actions/github-script@v6 + with: + script: | + const script = require('./.github/scripts/lint-ecosystem.js') + await script({ core }) +