diff --git a/CHANGELOG.md b/CHANGELOG.md index b636547..b32065a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 5.0.3 Task 6.0.3 - Fix minimum agent requirement to `2.206.1` ([#13](https://github.com/qetza/replacetokens-task/issues/13)). +- Fix paths in sources incompatible with `fast-glob` syntax on win32 ([#16](https://github.com/qetza/replacetokens-task/issues/16)). ## 5.0.2 Task 6.0.2 diff --git a/README.md b/README.md index 70aa53e..3a72e9e 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,8 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-task/r The task was completely rewritten to use the npm package [@qetza/replacetokens](https://www.npmjs.com/package/@qetza/replacetokens) and be more similar with the new [ReplaceTokens GitHub Actions](https://github.com/marketplace/actions/replacetokens): - support only node 16 (mininum agent version 2.206.1) - updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern - - renamed input _targetFiles_ to _sources_ + - renamed input _targetFiles_ to _sources_ + - migrated to `fast-glob` for glob patterns causing syntax changes (must use forward slash (`/`) for directory separator whatever the OS) - removed support for comma-separated paths in _targetFiles_ - renamed _encoding_ value `win1252` to `windows1252` - renamed _escapeType_ to _escape_ @@ -57,7 +58,8 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens]( # A multiline list of files to replace tokens in. # Each line supports: # - multiple glob patterns separated by a semi-colon ';' using fast-glob syntax - # (you must always use forward slash '/' as a directory separator) + # (you must always use forward slash '/' as a directory separator, on win32 will + # automatically replace backslash with forward slash) # - outputing the result in another file adding the output path after an arrow '=>' # (if the output path is a relative path, it will be relative to the input file) # - wildcard replacement in the output file name using an asterix '*' in the input diff --git a/tasks/ReplaceTokensV6/CHANGELOG.md b/tasks/ReplaceTokensV6/CHANGELOG.md index 245333a..7de3893 100644 --- a/tasks/ReplaceTokensV6/CHANGELOG.md +++ b/tasks/ReplaceTokensV6/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## 6.0.3 - Fix minimum agent requirement to `2.206.1` ([#13](https://github.com/qetza/replacetokens-task/issues/13)). +- Fix paths in sources incompatible with `fast-glob` syntax on win32 ([#16](https://github.com/qetza/replacetokens-task/issues/16)). ## 6.0.2 - Add aliases for renamed inputs to ease upgrade ([#11](https://github.com/qetza/replacetokens-task/issues/11)). diff --git a/tasks/ReplaceTokensV6/README.md b/tasks/ReplaceTokensV6/README.md index 3007a9f..3bddab4 100644 --- a/tasks/ReplaceTokensV6/README.md +++ b/tasks/ReplaceTokensV6/README.md @@ -10,7 +10,8 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-task/r The task was completely rewritten to use the npm package [@qetza/replacetokens](https://www.npmjs.com/package/@qetza/replacetokens) and be more similar with the new [ReplaceTokens GitHub Actions](https://github.com/marketplace/actions/replacetokens): - support only node 16 (mininum agent version 2.206.1) - updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern - - renamed input _targetFiles_ to _sources_ + - renamed input _targetFiles_ to _sources_ + - migrated to `fast-glob` for glob patterns causing syntax changes (must use forward slash (`/`) for directory separator whatever the OS) - removed support for comma-separated paths in _targetFiles_ - renamed _encoding_ value `win1252` to `windows1252` - renamed _escapeType_ to _escape_ @@ -57,7 +58,8 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens]( # A multiline list of files to replace tokens in. # Each line supports: # - multiple glob patterns separated by a semi-colon ';' using fast-glob syntax - # (you must always use forward slash '/' as a directory separator) + # (you must always use forward slash '/' as a directory separator, on win32 will + # automatically replace backslash with forward slash) # - outputing the result in another file adding the output path after an arrow '=>' # (if the output path is a relative path, it will be relative to the input file) # - wildcard replacement in the output file name using an asterix '*' in the input diff --git a/tasks/ReplaceTokensV6/index.ts b/tasks/ReplaceTokensV6/index.ts index 05a9656..2160b54 100644 --- a/tasks/ReplaceTokensV6/index.ts +++ b/tasks/ReplaceTokensV6/index.ts @@ -6,6 +6,7 @@ import * as rt from '@qetza/replacetokens'; import stripJsonComments from './strip-json-comments'; import * as telemetry from './telemetry'; import { SpanStatusCode } from '@opentelemetry/api'; +import * as os from 'os'; async function run() { const _debug = console.debug; @@ -32,9 +33,7 @@ async function run() { try { // read and validate inputs - const sources = tl.getDelimitedInput('targetFiles', /\r?\n/); - if (sources.length === 0) throw new Error('Input required: sources'); - + const sources = getSources(); const options: rt.Options = { addBOM: tl.getBoolInput('writeBOM'), encoding: tl.getInput('encoding') || rt.Encodings.Auto, @@ -189,6 +188,20 @@ async function run() { } } +var getSources = function (): string[] { + const sources = tl.getDelimitedInput('targetFiles', /\r?\n/); + if (sources.length === 0) throw new Error('Input required: sources'); + + // make sources compatible with fast-glob on win32 + if (os.platform() === 'win32') { + for (var i in sources) { + sources[i] = sources[i].replace(/\\/g, '/').replace(/\/\/+/g, '/'); + } + } + + return sources; +}; + var getChoiceInput = function (name: string, choices: string[], alias?: string): string { alias = alias || name; const input = tl.getInput(name)?.trim(); diff --git a/tasks/ReplaceTokensV6/tests/L0.ts b/tasks/ReplaceTokensV6/tests/L0.ts index 71212b8..f4bb01e 100644 --- a/tasks/ReplaceTokensV6/tests/L0.ts +++ b/tasks/ReplaceTokensV6/tests/L0.ts @@ -1,10 +1,10 @@ import * as path from 'path'; import * as ttm from 'azure-pipelines-task-lib/mock-test'; +import * as os from 'os'; require('chai').should(); const data = path.join(__dirname, '..', '..', 'tests', '_data'); -const tmp = path.join(__dirname, '_tmp'); describe('ReplaceTokens v6 L0 suite', function () { this.timeout(10000); @@ -288,6 +288,28 @@ describe('ReplaceTokens v6 L0 suite', function () { } }); + it('sources: normalize', async () => { + // arrange + const tp = path.join(__dirname, 'L0_Run.js'); + const tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp); + + process.env['__sources__'] = 'D:\\a\\1\\s/test.json'; + + // act + await tr.runAsync(); + + // assert + runValidations(() => { + tr.succeeded.should.be.true; + + if (os.platform() === 'win32') { + tr.stdout.should.include('sources: ["D:/a/1/s/test.json"]'); + } else { + tr.stdout.should.include('sources: ["D:\\\\a\\\\1\\\\s/test.json"]'); + } + }, tr); + }); + it('addBOM', async () => { // arrange const tp = path.join(__dirname, 'L0_Run.js');