-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prune YAML files before sending them to vale.
Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
5 changed files
with
105 additions
and
6 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 |
---|---|---|
|
@@ -31,9 +31,3 @@ jobs: | |
|
||
- name: Lint | ||
run: npm run lint | ||
|
||
- name: Check Style | ||
uses: errata-ai/[email protected] | ||
with: | ||
version: 3.7.1 | ||
files: '["spec","tests"]' |
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,28 @@ | ||
name: Lint | ||
|
||
on: [pull_request,push] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '20' | ||
|
||
- name: Install Dependencies | ||
run: npm ci | ||
|
||
- name: Lint | ||
run: npm run vale -- --source spec | ||
run: npm run vale -- --source tests | ||
|
||
- name: Check Style | ||
uses: errata-ai/[email protected] | ||
with: | ||
version: 3.7.1 | ||
files: '["spec","tests"]' |
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
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,49 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import fs from 'fs' | ||
import globby from 'globby' | ||
import _ from 'lodash' | ||
import { Logger } from '../Logger' | ||
|
||
export default class OpenApiValer { | ||
root_folder: string | ||
logger: Logger | ||
|
||
constructor (root_folder: string, logger: Logger = new Logger()) { | ||
this.logger = logger | ||
this.root_folder = fs.realpathSync(root_folder) | ||
} | ||
|
||
async vale(): Promise<undefined> { | ||
const files = await globby([this.root_folder]) | ||
files.forEach((path) => { | ||
this.process(path) | ||
}) | ||
} | ||
|
||
process(filename: string): void { | ||
const contents = fs.readFileSync(filename, 'utf-8') | ||
var writer = fs.createWriteStream(filename, { flags: 'w+' }) | ||
|
||
var inside_description = false | ||
contents.split(/\r?\n/).forEach((line) => { | ||
if (line.includes('description: |')) { | ||
inside_description = true | ||
} else if (line.includes('description: ')) { | ||
writer.write(line.replace("description: ", " ")) | ||
} else if (inside_description && line.includes(": ")) { | ||
inside_description = false | ||
} else if (inside_description) { | ||
writer.write(line) | ||
} | ||
writer.write("\n") | ||
}) | ||
} | ||
} |
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,27 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
import { Command, Option } from '@commander-js/extra-typings' | ||
import { Logger, LogLevel } from '../Logger' | ||
import { resolve } from 'path' | ||
import OpenApiValer from './OpenApiValer' | ||
|
||
const command = new Command() | ||
.description('Prepares YAML files for Vale.') | ||
.addOption(new Option('-s, --source <path>', 'path to the root folder of the multi-file spec').default(resolve(__dirname, '../../../spec'))) | ||
.addOption(new Option('--verbose', 'show merge details').default(false)) | ||
.allowExcessArguments(false) | ||
.parse() | ||
|
||
const opts = command.opts() | ||
const logger = new Logger(opts.verbose ? LogLevel.info : LogLevel.warn) | ||
const valer = new OpenApiValer(opts.source, logger) | ||
Check failure on line 24 in tools/src/vale/vale.ts GitHub Actions / lint
|
||
logger.log(`Pruning ${opts.source} ...`) | ||
valer.vale() | ||
Check failure on line 26 in tools/src/vale/vale.ts GitHub Actions / lint
|
||
logger.log('Done.') |