Skip to content

Commit

Permalink
Add ecosystem linting
Browse files Browse the repository at this point in the history
  • Loading branch information
jsumners committed Jun 30, 2022
1 parent 8fccc46 commit 8f6ef1e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
59 changes: 59 additions & 0 deletions .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'}
)
}
34 changes: 34 additions & 0 deletions .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 })

0 comments on commit 8f6ef1e

Please sign in to comment.