Skip to content

Commit 06848e0

Browse files
authored
Add dot paths support (#16)
1 parent 7c77d22 commit 06848e0

File tree

8 files changed

+82
-22
lines changed

8 files changed

+82
-22
lines changed

.github/workflows/ci.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
sources: |
9393
**/*.json;!**/*.DEV.json;!**/vars.json => _tmp/*.json
9494
**/*.xml;!**.dev.xml => _tmp/*.xml
95-
**/*.YML => _tmp/*.yml
95+
**/*.YML;!**/*vars.yml => _tmp/*.yml
9696
variables: >
9797
[
9898
${{ toJSON(vars) }},
@@ -107,6 +107,7 @@ jobs:
107107
recursive: true
108108
transforms: true
109109
case-insensitive-paths: true
110+
include-dot-paths: true
110111
env:
111112
ENV_VARS: '{ "var4": "env_value4" }'
112113

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
## v1.2.0
33
- Upgrade package `@qetza/replacetokens` to `1.7.0`.
44
- Add support for case insensitive path matching in _sources_ and _variables_.
5+
- Add support for matching directories and files starting with a dot in _sources_ and _variables_.
56

67
## v1.1.2
78
- Change telemetry provider.

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-action
9898
# Optional. Default: ignore
9999
if-no-files-found: ''
100100

101+
# Include directories and files starting with a dot '.' in glob matching results for sources
102+
# and additionalVariables.
103+
#
104+
# Optional. Default: false
105+
include-dot-paths: ''
106+
101107
# The log level.
102108
#
103109
# Accepted values:

action.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ inputs:
5454
Accepted values:
5555
- auto: detect encoding using js-chardet
5656
- any value supported by iconv-lite
57-
default: auto
57+
default: 'auto'
5858
escape:
5959
description: >
6060
Character escape type to apply on each value.
@@ -71,6 +71,9 @@ inputs:
7171
if-no-files-found:
7272
description: 'The behavior if no files are found: ignore, warn, error.'
7373
default: 'ignore'
74+
include-dot-paths:
75+
description: 'Include directories and files starting with a dot ''.'' in glob matching results for sources and additionalVariables.'
76+
default: 'false'
7477
log-level:
7578
description: >
7679
The log level.

dist/index.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -63665,7 +63665,8 @@ async function run() {
6366563665
recursive: core.getBooleanInput('recursive'),
6366663666
root: core.getInput('root'),
6366763667
sources: {
63668-
caseInsensitive: core.getBooleanInput('case-insensitive-paths')
63668+
caseInsensitive: core.getBooleanInput('case-insensitive-paths'),
63669+
dot: core.getBooleanInput('include-dot-paths')
6366963670
},
6367063671
token: {
6367163672
pattern: getChoiceInput('token-pattern', [
@@ -63717,7 +63718,7 @@ async function run() {
6371763718
};
6371863719
// load variables
6371963720
const separator = core.getInput('separator') || rt.Defaults.Separator;
63720-
const variables = await getVariables(options.root, separator, options.sources.caseInsensitive);
63721+
const variables = await getVariables(options.root, separator, options.sources.caseInsensitive, options.sources.dot);
6372163722
// set telemetry attributes
6372263723
telemetryEvent.setAttributes({
6372363724
sources: sources.length,
@@ -63728,6 +63729,7 @@ async function run() {
6372863729
escape: options.escape.type,
6372963730
'escape-char': options.escape.escapeChar,
6373063731
'if-no-files-found': ifNoFilesFound,
63732+
'include-dot-paths': options.sources.dot,
6373163733
'log-level': logLevelStr,
6373263734
'missing-var-action': options.missing.action,
6373363735
'missing-var-default': options.missing.default,
@@ -63806,12 +63808,13 @@ function getSources() {
6380663808
var variableFilesCount = 0;
6380763809
var variablesEnvCount = 0;
6380863810
var inlineVariablesCount = 0;
63809-
async function getVariables(root, separator, caseInsensitive) {
63811+
async function getVariables(root, separator, caseInsensitive, dot) {
6381063812
const input = core.getInput('variables', { required: true, trimWhitespace: true }) || '';
6381163813
if (!input)
6381263814
return {};
6381363815
return await rt.loadVariables(getVariablesFromJson(input), {
6381463816
caseInsensitive: caseInsensitive,
63817+
dot: dot,
6381563818
normalizeWin32: true,
6381663819
root: root,
6381763820
separator: separator

src/main.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export async function run(): Promise<void> {
6464
recursive: core.getBooleanInput('recursive'),
6565
root: core.getInput('root'),
6666
sources: {
67-
caseInsensitive: core.getBooleanInput('case-insensitive-paths')
67+
caseInsensitive: core.getBooleanInput('case-insensitive-paths'),
68+
dot: core.getBooleanInput('include-dot-paths')
6869
},
6970
token: {
7071
pattern:
@@ -116,7 +117,12 @@ export async function run(): Promise<void> {
116117

117118
// load variables
118119
const separator = core.getInput('separator') || rt.Defaults.Separator;
119-
const variables = await getVariables(options.root, separator, options.sources!.caseInsensitive);
120+
const variables = await getVariables(
121+
options.root,
122+
separator,
123+
options.sources!.caseInsensitive,
124+
options.sources!.dot
125+
);
120126

121127
// set telemetry attributes
122128
telemetryEvent.setAttributes({
@@ -128,6 +134,7 @@ export async function run(): Promise<void> {
128134
escape: options.escape!.type,
129135
'escape-char': options.escape!.escapeChar,
130136
'if-no-files-found': ifNoFilesFound,
137+
'include-dot-paths': options.sources!.dot,
131138
'log-level': logLevelStr,
132139
'missing-var-action': options.missing!.action,
133140
'missing-var-default': options.missing!.default,
@@ -219,13 +226,15 @@ var inlineVariablesCount = 0;
219226
async function getVariables(
220227
root?: string,
221228
separator?: string,
222-
caseInsensitive?: boolean
229+
caseInsensitive?: boolean,
230+
dot?: boolean
223231
): Promise<{ [key: string]: string }> {
224232
const input = core.getInput('variables', { required: true, trimWhitespace: true }) || '';
225233
if (!input) return {};
226234

227235
return await rt.loadVariables(getVariablesFromJson(input), {
228236
caseInsensitive: caseInsensitive,
237+
dot: dot,
229238
normalizeWin32: true,
230239
root: root,
231240
separator: separator
File renamed without changes.

tests/run.test.ts

+51-14
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ describe('run', () => {
205205
recursive: false,
206206
root: '',
207207
sources: {
208-
caseInsensitive: false
208+
caseInsensitive: false,
209+
dot: false
209210
},
210211
token: {
211212
pattern: rt.TokenPatterns.Default,
@@ -247,7 +248,7 @@ describe('run', () => {
247248

248249
expect(debugSpy).toHaveBeenCalledWith(
249250
expect.stringMatching(
250-
/\[\{"eventType":"TokensReplaced","application":"replacetokens-action","version":"1\.\d+\.\d+","account":"c054bf9f6127dc352a184a29403ac9114f6c2a8e27cb467197cdfc1c3df119e4","pipeline":"59830ebc3a4184110566bf1a290d08473dfdcbd492ce498b14cd1a5e2fa2e441","host":"server","os":"Windows","sources":3,"add-bom":false,"case-insensitive-paths":false,"chars-to-escape":"","encoding":"auto","escape":"auto","escape-char":"","if-no-files-found":"ignore","log-level":"info","missing-var-action":"none","missing-var-default":"","missing-var-log":"warn","recusrive":false,"separator":"\.","token-pattern":"default","token-prefix":"","token-suffix":"","transforms":false,"transforms-prefix":"\(","transforms-suffix":"\)","variable-files":0,"variable-envs":0,"inline-variables":0,"output-defaults":1,"output-files":2,"output-replaced":3,"output-tokens":4,"output-transforms":5,"result":"success","duration":\d+(?:\.\d+)?}]/
251+
/\[\{"eventType":"TokensReplaced","application":"replacetokens-action","version":"1\.\d+\.\d+","account":"c054bf9f6127dc352a184a29403ac9114f6c2a8e27cb467197cdfc1c3df119e4","pipeline":"59830ebc3a4184110566bf1a290d08473dfdcbd492ce498b14cd1a5e2fa2e441","host":"server","os":"Windows","sources":3,"add-bom":false,"case-insensitive-paths":false,"chars-to-escape":"","encoding":"auto","escape":"auto","escape-char":"","if-no-files-found":"ignore","include-dot-paths":false,"log-level":"info","missing-var-action":"none","missing-var-default":"","missing-var-log":"warn","recusrive":false,"separator":"\.","token-pattern":"default","token-prefix":"","token-suffix":"","transforms":false,"transforms-prefix":"\(","transforms-suffix":"\)","variable-files":0,"variable-envs":0,"inline-variables":0,"output-defaults":1,"output-files":2,"output-replaced":3,"output-tokens":4,"output-transforms":5,"result":"success","duration":\d+(?:\.\d+)?}]/
251252
)
252253
);
253254
});
@@ -324,7 +325,8 @@ describe('run', () => {
324325
separator: rt.Defaults.Separator,
325326
normalizeWin32: true,
326327
root: '',
327-
caseInsensitive: false
328+
caseInsensitive: false,
329+
dot: false
328330
});
329331

330332
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
@@ -352,7 +354,8 @@ describe('run', () => {
352354
separator: rt.Defaults.Separator,
353355
normalizeWin32: true,
354356
root: '',
355-
caseInsensitive: false
357+
caseInsensitive: false,
358+
dot: false
356359
});
357360

358361
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
@@ -380,7 +383,8 @@ describe('run', () => {
380383
separator: rt.Defaults.Separator,
381384
normalizeWin32: true,
382385
root: '',
383-
caseInsensitive: false
386+
caseInsensitive: false,
387+
dot: false
384388
});
385389

386390
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
@@ -414,7 +418,8 @@ describe('run', () => {
414418
separator: rt.Defaults.Separator,
415419
normalizeWin32: true,
416420
root: '',
417-
caseInsensitive: false
421+
caseInsensitive: false,
422+
dot: false
418423
});
419424

420425
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
@@ -452,7 +457,8 @@ describe('run', () => {
452457
separator: rt.Defaults.Separator,
453458
normalizeWin32: true,
454459
root: '',
455-
caseInsensitive: false
460+
caseInsensitive: false,
461+
dot: false
456462
}
457463
);
458464

@@ -486,7 +492,8 @@ describe('run', () => {
486492
separator: rt.Defaults.Separator,
487493
normalizeWin32: true,
488494
root: '',
489-
caseInsensitive: false
495+
caseInsensitive: false,
496+
dot: false
490497
});
491498

492499
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
@@ -650,6 +657,41 @@ describe('run', () => {
650657
);
651658
});
652659

660+
it('include-dot-paths', async () => {
661+
// arrange
662+
getBooleanInputSpy.mockImplementation(name => {
663+
switch (name) {
664+
case 'include-dot-paths':
665+
return true;
666+
default:
667+
return false;
668+
}
669+
});
670+
671+
getInputSpy.mockImplementation(name => {
672+
switch (name) {
673+
case 'variables':
674+
return '{}';
675+
default:
676+
return '';
677+
}
678+
});
679+
680+
// act
681+
await run();
682+
683+
// assert
684+
expect(setFailedSpy).not.toHaveBeenCalled();
685+
686+
expect(loadVariablesSpy).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ dot: true }));
687+
688+
expect(replaceTokenSpy).toHaveBeenCalledWith(
689+
expect.anything(),
690+
expect.any(Function),
691+
expect.objectContaining({ sources: expect.objectContaining({ dot: true }) })
692+
);
693+
});
694+
653695
it('log-level: debug', async () => {
654696
// arrange
655697
getInputSpy.mockImplementation(name => {
@@ -993,12 +1035,7 @@ describe('run', () => {
9931035
// assert
9941036
expect(setFailedSpy).not.toHaveBeenCalled();
9951037

996-
expect(loadVariablesSpy).toHaveBeenCalledWith(['{}'], {
997-
separator: ':',
998-
normalizeWin32: true,
999-
root: '',
1000-
caseInsensitive: false
1001-
});
1038+
expect(loadVariablesSpy).toHaveBeenCalledWith(['{}'], expect.objectContaining({ separator: ':' }));
10021039

10031040
expect(replaceTokenSpy).toHaveBeenCalledWith(expect.anything(), expect.any(Function), expect.anything());
10041041
});

0 commit comments

Comments
 (0)