Skip to content

Commit 7600af2

Browse files
authored
Merge pull request #528 from fjogeleit/no-compat-mode-input
Add input to configure noCompatMode
2 parents 3eb77b1 + 2956f06 commit 7600af2

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ jobs:
9393
|workDir | Relative location of the configured `repository` | . | |
9494
|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` ||
9595
|method | Configures the processing of none existing properties. Possible values: `CreateOrUpdate`, `Update`, `Create` | `CreateOrUpdate` |
96+
|noCompatMode| Removes quotes from reserved words, like Y, N, yes, no, on, etc. | `false` |
9697

9798
#### Methods
9899

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ inputs:
1111
value:
1212
required: true
1313
description: 'New property value'
14+
noCompatMode:
15+
required: false
16+
description: 'Removes quotes from reserved words, like Y, N, yes, no, on, etc.'
1417
format:
1518
required: false
1619
description: 'Supported file formats, possible values are YAML and JSON, will be guessed by file extension if not provided. Falls back to YAML'

src/action.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function run(options: Options, actions: Actions): Promise<void> {
2020
const files: ChangedFile[] = []
2121

2222
for (const [file, values] of Object.entries(options.changes)) {
23-
const changedFile = processFile(file, options.format, values, options.workDir, options.method, actions)
23+
const changedFile = processFile(file, values, options, actions)
2424

2525
if (changedFile) {
2626
writeTo(changedFile.content, changedFile.absolutePath, actions)
@@ -63,7 +63,7 @@ export async function runTest<T extends ContentNode>(options: Options): Promise<
6363
const files: ChangedFile[] = []
6464

6565
for (const [file, values] of Object.entries(options.changes)) {
66-
const changedFile = processFile(file, options.format, values, options.workDir, options.method, new EmptyActions())
66+
const changedFile = processFile(file, values, options, new EmptyActions())
6767
if (changedFile) {
6868
files.push(changedFile)
6969
}
@@ -221,32 +221,25 @@ export const convertValue = (value: string): string | number | boolean => {
221221
return result[0]
222222
}
223223

224-
export function processFile(
225-
file: string,
226-
format: Format,
227-
values: ValueUpdates,
228-
workDir: string,
229-
method: Method,
230-
actions: Actions
231-
): ChangedFile | null {
232-
const filePath = path.join(process.cwd(), workDir, file)
224+
export function processFile(file: string, values: ValueUpdates, options: Options, actions: Actions): ChangedFile | null {
225+
const filePath = path.join(process.cwd(), options.workDir, file)
233226

234-
actions.debug(`FilePath: ${filePath}, Parameter: ${JSON.stringify({cwd: process.cwd(), workDir, valueFile: file})}`)
227+
actions.debug(`FilePath: ${filePath}, Parameter: ${JSON.stringify({cwd: process.cwd(), workDir: options.workDir, valueFile: file})}`)
235228

236-
format = determineFinalFormat(filePath, format, actions) as Format.JSON | Format.YAML
229+
const format = determineFinalFormat(filePath, options.format, actions) as Format.JSON | Format.YAML
237230

238231
const parser = formatParser[format]
239232

240233
let contentNode = parser.convert(filePath)
241-
let contentString = parser.dump(contentNode)
234+
let contentString = parser.dump(contentNode, {noCompatMode: options.noCompatMode})
242235

243236
const initContent = contentString
244237

245238
actions.debug(`Parsed JSON: ${JSON.stringify(contentNode)}`)
246239

247240
for (const [propertyPath, value] of Object.entries(values)) {
248-
contentNode = replace(value, propertyPath, contentNode, method)
249-
contentString = parser.dump(contentNode)
241+
contentNode = replace(value, propertyPath, contentNode, options.method)
242+
contentString = parser.dump(contentNode, {noCompatMode: options.noCompatMode})
250243
}
251244

252245
actions.debug(`Generated updated ${format.toUpperCase()}

src/options.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export interface Options {
2828
changes: Changes
2929
format: Format
3030
method: Method
31+
noCompatMode: boolean
3132
}
3233

3334
export class GitHubOptions implements Options {
@@ -48,11 +49,11 @@ export class GitHubOptions implements Options {
4849
}
4950

5051
get commitChange(): boolean {
51-
return core.getInput('commitChange') === 'true'
52+
return core.getBooleanInput('commitChange')
5253
}
5354

5455
get updateFile(): boolean {
55-
return core.getInput('updateFile') === 'true'
56+
return core.getBooleanInput('updateFile')
5657
}
5758

5859
get targetBranch(): string {
@@ -68,7 +69,11 @@ export class GitHubOptions implements Options {
6869
}
6970

7071
get createPR(): boolean {
71-
return core.getInput('createPR') === 'true'
72+
return core.getBooleanInput('createPR')
73+
}
74+
75+
get noCompatMode(): boolean {
76+
return core.getBooleanInput('noCompatMode')
7277
}
7378

7479
get token(): string {
@@ -223,6 +228,10 @@ export class EnvOptions implements Options {
223228
return process.env.CREATE_PR === 'true'
224229
}
225230

231+
get noCompatMode(): boolean {
232+
return process.env.NO_COMPAT_MODE === 'true'
233+
}
234+
226235
get message(): string {
227236
return process.env.MESSAGE || ''
228237
}

src/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ const YAMLParser = {
3333
convert<T extends ContentNode>(filePath: string): T {
3434
return validateContent<T>(YAML.load(readFile(filePath)) as T, Format.YAML)
3535
},
36-
dump<T extends ContentNode>(content: T): string {
37-
return YAML.dump(content, {lineWidth: -1, noCompatMode: true})
36+
dump<T extends ContentNode>(content: T, options?: {noCompatMode: boolean}): string {
37+
return YAML.dump(content, {lineWidth: -1, noCompatMode: options?.noCompatMode})
3838
}
3939
}
4040

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ export enum Format {
3737

3838
export type FormatParser = {
3939
convert<T extends ContentNode>(filePath: string): T
40-
dump<T extends ContentNode>(content: T): string
40+
dump<T extends ContentNode>(content: T, options?: {[key: string]: string | boolean | number}): string
4141
}

0 commit comments

Comments
 (0)