Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) | ||