Skip to content

Commit f891633

Browse files
authored
Fix win32 paths in sources (#11)
1 parent 60659a6 commit f891633

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## v1.1.1
44
- Fix variable case-sensitivity ([#7](https://github.com/qetza/replacetokens-action/issues/7)).
5+
- Fix paths in sources incompatible with `fast-glob` syntax on win32.
56

67
## v1.1.0
78
- Add support for JSON comments in _variables_ and in JSON variable files and environment variables

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-action
1414
# A multiline list of files to replace tokens in.
1515
# Each line supports:
1616
# - multiple glob patterns separated by a semi-colon ';' using fast-glob syntax
17-
# (you must always use forward slash '/' as a directory separator)
17+
# (you must always use forward slash '/' as a directory separator, on win32 will
18+
# automatically replace backslash with forward slash)
1819
# - outputing the result in another file adding the output path after an arrow '=>'
1920
# (if the output path is a relative path, it will be relative to the input file)
2021
# - wildcard replacement in the output file name using an asterix '*' in the input

dist/index.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -63403,6 +63403,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6340363403
exports.run = void 0;
6340463404
const core = __importStar(__nccwpck_require__(42186));
6340563405
const rt = __importStar(__nccwpck_require__(49633));
63406+
const os = __importStar(__nccwpck_require__(22037));
6340663407
const strip_json_comments_1 = __importDefault(__nccwpck_require__(30077));
6340763408
const telemetry_1 = __nccwpck_require__(12417);
6340863409
const api_1 = __nccwpck_require__(65163);
@@ -63470,7 +63471,7 @@ async function run() {
6347063471
suffix: core.getInput('transforms-suffix') || rt.Defaults.TransformSuffix
6347163472
}
6347263473
};
63473-
const sources = core.getMultilineInput('sources', { required: true, trimWhitespace: true });
63474+
const sources = getSources();
6347463475
const ifNoFilesFound = getChoiceInput('if-no-files-found', ['ignore', 'warn', 'error']) || 'ignore';
6347563476
const logLevelStr = getChoiceInput('log-level', ['debug', 'info', 'warn', 'error']) || 'info';
6347663477
// override console logs
@@ -63579,6 +63580,16 @@ function getChoiceInput(name, choices, options) {
6357963580
return input;
6358063581
throw new TypeError(`Unsupported value for input: ${name}\nSupport input list: '${choices.join(' | ')}'`);
6358163582
}
63583+
function getSources() {
63584+
const sources = core.getMultilineInput('sources', { required: true, trimWhitespace: true });
63585+
// make sources compatible with fast-glob on win32
63586+
if (os.platform() === 'win32') {
63587+
for (const i in sources) {
63588+
sources[i] = sources[i].replace(/\\/g, '/');
63589+
}
63590+
}
63591+
return sources;
63592+
}
6358263593
var variableFilesCount = 0;
6358363594
var variablesEnvCount = 0;
6358463595
var inlineVariablesCount = 0;

src/main.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as rt from '@qetza/replacetokens';
3+
import * as os from 'os';
34
import stripJsonComments from './strip-json-comments';
45
import { TelemetryClient } from './telemetry';
56
import { SpanStatusCode } from '@opentelemetry/api';
@@ -84,7 +85,7 @@ export async function run(): Promise<void> {
8485
}
8586
};
8687

87-
const sources = core.getMultilineInput('sources', { required: true, trimWhitespace: true });
88+
const sources = getSources();
8889
const ifNoFilesFound = getChoiceInput('if-no-files-found', ['ignore', 'warn', 'error']) || 'ignore';
8990
const logLevelStr = getChoiceInput('log-level', ['debug', 'info', 'warn', 'error']) || 'info';
9091

@@ -199,6 +200,19 @@ function getChoiceInput(name: string, choices: string[], options?: core.InputOpt
199200
throw new TypeError(`Unsupported value for input: ${name}\nSupport input list: '${choices.join(' | ')}'`);
200201
}
201202

203+
function getSources(): string[] {
204+
const sources = core.getMultilineInput('sources', { required: true, trimWhitespace: true });
205+
206+
// make sources compatible with fast-glob on win32
207+
if (os.platform() === 'win32') {
208+
for (const i in sources) {
209+
sources[i] = sources[i].replace(/\\/g, '/');
210+
}
211+
}
212+
213+
return sources;
214+
}
215+
202216
var variableFilesCount = 0;
203217
var variablesEnvCount = 0;
204218
var inlineVariablesCount = 0;

tests/run.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core';
22
import * as path from 'path';
33
import * as rt from '@qetza/replacetokens';
4+
import * as os from 'os';
45
import axios from 'axios';
56
import { run } from '../src/main';
67

@@ -271,6 +272,31 @@ describe('run', () => {
271272
);
272273
});
273274

275+
it('sources: normalize', async () => {
276+
// arrange
277+
const source = path.join(__dirname, 'data', 'vars.json').replace(/\//g, '\\');
278+
getMultilineInputSpy.mockImplementation(name => {
279+
switch (name) {
280+
case 'sources':
281+
return [source];
282+
default:
283+
return [];
284+
}
285+
});
286+
287+
// act
288+
await run();
289+
290+
// assert
291+
expect(setFailedSpy).not.toHaveBeenCalled();
292+
293+
if (os.platform() === 'win32') {
294+
expect(replaceTokenSpy).toHaveBeenCalledWith([source.replace(/\\/g, '/')], expect.anything(), expect.anything());
295+
} else {
296+
expect(replaceTokenSpy).toHaveBeenCalledWith([source], expect.anything(), expect.anything());
297+
}
298+
});
299+
274300
it('variables: object', async () => {
275301
// arrange
276302
const vars = { var1: 'value1', var2: 'value2', SECRET1: 'secret1' };

0 commit comments

Comments
 (0)