-
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.
Signed-off-by: dblock <[email protected]>
- Loading branch information
Showing
13 changed files
with
286 additions
and
51 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,31 @@ | ||
name: Style | ||
|
||
on: [pull_request, push] | ||
|
||
jobs: | ||
check: | ||
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: Prepare for Vale (spec) | ||
run: npm run style:prepare -- --source spec | ||
|
||
- name: Prepare for Vale (test) | ||
run: npm run style:prepare -- --source tests | ||
|
||
- name: Check Style | ||
uses: errata-ai/[email protected] | ||
Check warning on line 27 in .github/workflows/style.yml GitHub Actions / check
|
||
with: | ||
version: 3.7.1 | ||
vale_flags: --ignore-syntax | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,55 @@ | ||
/* | ||
* 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 fg from 'fast-glob' | ||
import { Logger } from '../Logger' | ||
|
||
/** | ||
* Keeps only description: field values. | ||
*/ | ||
export default class KeepDescriptions { | ||
root_folder: string | ||
logger: Logger | ||
|
||
constructor (root_folder: string, logger: Logger = new Logger()) { | ||
this.logger = logger | ||
this.root_folder = fs.realpathSync(root_folder) | ||
} | ||
|
||
process(): void { | ||
this.root_folder | ||
const files = fg.globSync([`${this.root_folder}/**/*.yaml`]) | ||
files.forEach((path) => { | ||
this.logger.log(path) | ||
this.process_file(path) | ||
}) | ||
} | ||
|
||
process_file(filename: string): void { | ||
const contents = fs.readFileSync(filename, 'utf-8') | ||
var writer = fs.openSync(filename, 'w+') | ||
|
||
var inside_description = false | ||
contents.split(/\r?\n/).forEach((line) => { | ||
if (line.match(/^[\s]+(description: \|)/)) { | ||
inside_description = true | ||
} else if (line.match(/^[\s]+(description:)[\s]+/)) { | ||
fs.writeSync(writer, line.replace("description:", " ")) | ||
} else if (inside_description && line.match(/^[\s]*[\w]*:/)) { | ||
inside_description = false | ||
} else if (inside_description) { | ||
fs.writeSync(writer, line) | ||
} | ||
if (line.length > 0) { | ||
fs.writeSync(writer, "\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 KeepDescriptions from './KeepDescriptions' | ||
|
||
const command = new Command() | ||
.description('Convert YAML files to text.') | ||
.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 keep_descriptions = new KeepDescriptions(opts.source, logger) | ||
logger.log(`Preparing ${opts.source} ...`) | ||
keep_descriptions.process() | ||
logger.log('Done.') |
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,43 @@ | ||
/* | ||
* 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 KeepDescriptions from 'prepare-for-vale/KeepDescriptions' | ||
import fs from 'fs' | ||
import fg from 'fast-glob' | ||
import tmp from 'tmp' | ||
|
||
describe('KeepDescriptions', () => { | ||
var temp: tmp.DirResult | ||
var fixture_path: string = './tools/tests/prepare-for-vale/fixtures' | ||
var fixtures = fg.globSync(`${fixture_path}/**/*.yaml`) | ||
|
||
describe('defaults', () => { | ||
beforeAll(() => { | ||
temp = tmp.dirSync() | ||
fs.cpSync(fixture_path, temp.name, { recursive: true }) | ||
new KeepDescriptions(temp.name).process() | ||
}) | ||
|
||
afterAll(() => { | ||
temp.removeCallback() | ||
}) | ||
|
||
describe('converts files to text in-place', () => { | ||
fixtures.forEach((filename) => { | ||
test(filename, () => { | ||
const processed_yaml = filename.replace(fixture_path, temp.name) | ||
const filename_txt = processed_yaml.replace(".yaml", ".txt") | ||
expect(fs.readFileSync(processed_yaml, 'utf8')).toEqual(fs.readFileSync(filename_txt, 'utf8')) | ||
fs.rmSync(processed_yaml) | ||
fs.rmSync(filename_txt) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.