diff --git a/README.md b/README.md index 9baca24..3c986b2 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ jobs: |workDir | Relative location of the configured `repository` | . | | |format | Specify the used format parser of your file. WIll be guessed by file extension if not provided and uses YAML as fallback. Supports `YAML` and `JSON` || |method | Configures the processing of none existing properties. Possible values: `CreateOrUpdate`, `Update`, `Create` | `CreateOrUpdate` | +|noCompatMode| Removes quotes from reserved words, like Y, N, yes, no, on, etc. | `false` | #### Methods diff --git a/action.yml b/action.yml index 3ce5a6b..8a71d4d 100644 --- a/action.yml +++ b/action.yml @@ -11,6 +11,9 @@ inputs: value: required: true description: 'New property value' + noCompatMode: + required: false + description: 'Removes quotes from reserved words, like Y, N, yes, no, on, etc.' format: required: false description: 'Supported file formats, possible values are YAML and JSON, will be guessed by file extension if not provided. Falls back to YAML' diff --git a/src/action.ts b/src/action.ts index 62f87c2..c616db0 100644 --- a/src/action.ts +++ b/src/action.ts @@ -20,7 +20,7 @@ export async function run(options: Options, actions: Actions): Promise { const files: ChangedFile[] = [] for (const [file, values] of Object.entries(options.changes)) { - const changedFile = processFile(file, options.format, values, options.workDir, options.method, actions) + const changedFile = processFile(file, values, options, actions) if (changedFile) { writeTo(changedFile.content, changedFile.absolutePath, actions) @@ -63,7 +63,7 @@ export async function runTest(options: Options): Promise< const files: ChangedFile[] = [] for (const [file, values] of Object.entries(options.changes)) { - const changedFile = processFile(file, options.format, values, options.workDir, options.method, new EmptyActions()) + const changedFile = processFile(file, values, options, new EmptyActions()) if (changedFile) { files.push(changedFile) } @@ -221,32 +221,25 @@ export const convertValue = (value: string): string | number | boolean => { return result[0] } -export function processFile( - file: string, - format: Format, - values: ValueUpdates, - workDir: string, - method: Method, - actions: Actions -): ChangedFile | null { - const filePath = path.join(process.cwd(), workDir, file) +export function processFile(file: string, values: ValueUpdates, options: Options, actions: Actions): ChangedFile | null { + const filePath = path.join(process.cwd(), options.workDir, file) - actions.debug(`FilePath: ${filePath}, Parameter: ${JSON.stringify({cwd: process.cwd(), workDir, valueFile: file})}`) + actions.debug(`FilePath: ${filePath}, Parameter: ${JSON.stringify({cwd: process.cwd(), workDir: options.workDir, valueFile: file})}`) - format = determineFinalFormat(filePath, format, actions) as Format.JSON | Format.YAML + const format = determineFinalFormat(filePath, options.format, actions) as Format.JSON | Format.YAML const parser = formatParser[format] let contentNode = parser.convert(filePath) - let contentString = parser.dump(contentNode) + let contentString = parser.dump(contentNode, {noCompatMode: options.noCompatMode}) const initContent = contentString actions.debug(`Parsed JSON: ${JSON.stringify(contentNode)}`) for (const [propertyPath, value] of Object.entries(values)) { - contentNode = replace(value, propertyPath, contentNode, method) - contentString = parser.dump(contentNode) + contentNode = replace(value, propertyPath, contentNode, options.method) + contentString = parser.dump(contentNode, {noCompatMode: options.noCompatMode}) } actions.debug(`Generated updated ${format.toUpperCase()} diff --git a/src/options.ts b/src/options.ts index 42b8af3..17b00c7 100644 --- a/src/options.ts +++ b/src/options.ts @@ -28,6 +28,7 @@ export interface Options { changes: Changes format: Format method: Method + noCompatMode: boolean } export class GitHubOptions implements Options { @@ -48,11 +49,11 @@ export class GitHubOptions implements Options { } get commitChange(): boolean { - return core.getInput('commitChange') === 'true' + return core.getBooleanInput('commitChange') } get updateFile(): boolean { - return core.getInput('updateFile') === 'true' + return core.getBooleanInput('updateFile') } get targetBranch(): string { @@ -68,7 +69,11 @@ export class GitHubOptions implements Options { } get createPR(): boolean { - return core.getInput('createPR') === 'true' + return core.getBooleanInput('createPR') + } + + get noCompatMode(): boolean { + return core.getBooleanInput('noCompatMode') } get token(): string { @@ -223,6 +228,10 @@ export class EnvOptions implements Options { return process.env.CREATE_PR === 'true' } + get noCompatMode(): boolean { + return process.env.NO_COMPAT_MODE === 'true' + } + get message(): string { return process.env.MESSAGE || '' } diff --git a/src/parser.ts b/src/parser.ts index cb47969..9c18689 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -33,8 +33,8 @@ const YAMLParser = { convert(filePath: string): T { return validateContent(YAML.load(readFile(filePath)) as T, Format.YAML) }, - dump(content: T): string { - return YAML.dump(content, {lineWidth: -1, noCompatMode: true}) + dump(content: T, options?: {noCompatMode: boolean}): string { + return YAML.dump(content, {lineWidth: -1, noCompatMode: options?.noCompatMode}) } } diff --git a/src/types.ts b/src/types.ts index 622a354..38132fa 100644 --- a/src/types.ts +++ b/src/types.ts @@ -37,5 +37,5 @@ export enum Format { export type FormatParser = { convert(filePath: string): T - dump(content: T): string + dump(content: T, options?: {[key: string]: string | boolean | number}): string }