Skip to content

Commit

Permalink
upgrade @qetza/replacetokens to 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qetza committed Mar 10, 2024
1 parent b163b9a commit 89d4b47
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
Task 6.0.0
- **Breaking changes**: 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
- updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern
- renamed input _targetFiles_ to _sources_
- removed support for comma-separated paths in _targetFiles_
- renamed _encoding_ value `win1252` to `windows1252`
- merged inputs _variableFiles_ and _inlineVariables_ in _additionalVariables_
- renamed input _variableSeparator_ to _separator_
- renamed input _enableRecursion_ to _recursive_
- renamed input _rootDirectory_ to _root_
- renamed _tokenPattern_ value `azpipelines` to `azurepipelines`
- renamed _tokenPattern_ value `rm` to `doubleunderscores`
- renamed input _writeBOM_ to _addBom_
- changed _writeBOM_ default value to `false`
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
This Azure Pipelines task replaces tokens in text based files with variable values.

## What's new
Please refer to the [release page](https://github.com/qetza/replacetokens-task/releases) for the latest release notes.
Please refer to the [release page](https://github.com/qetza/replacetokens-task/releases/latest) for the latest release notes.

## Breaking changes in v6
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
- updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern
- renamed input _targetFiles_ to _sources_
- removed support for comma-separated paths in _targetFiles_
- renamed _encoding_ value `win1252` to `windows1252`
Expand Down Expand Up @@ -287,8 +288,7 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens](
additionalVariables: |
- '@**/vars.(json|yml|yaml)' # read from files
- '$ENV_VARS', # read from env
- # inline key/value pairs
var1: '${{ parameters.var1 }}'
- var1: '${{ parameters.var1 }}' # inline key/value pairs
var2: '${{ parameters.var2 }}'
```

Expand Down
2 changes: 1 addition & 1 deletion tasks/ReplaceTokensV6/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
## 6.0.0
- **Breaking changes**: 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
- updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern
- renamed input _targetFiles_ to _sources_
- removed support for comma-separated paths in _targetFiles_
- renamed _encoding_ value `win1252` to `windows1252`
- merged inputs _variableFiles_ and _inlineVariables_ in _additionalVariables_
- renamed input _variableSeparator_ to _separator_
- renamed input _enableRecursion_ to _recursive_
- renamed input _rootDirectory_ to _root_
- renamed _tokenPattern_ value `azpipelines` to `azurepipelines`
- renamed _tokenPattern_ value `rm` to `doubleunderscores`
- renamed input _writeBOM_ to _addBom_
- changed _writeBOM_ default value to `false`
Expand Down
6 changes: 3 additions & 3 deletions tasks/ReplaceTokensV6/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
This Azure Pipelines task replaces tokens in text based files with variable values.

## What's new
Please refer to the [release page](https://github.com/qetza/replacetokens-task/releases) for the latest release notes.
Please refer to the [release page](https://github.com/qetza/replacetokens-task/releases/latest) for the latest release notes.

## Breaking changes in v6
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
- updated to [fast-glob](https://github.com/mrmlnc/fast-glob) for glob pattern
- renamed input _targetFiles_ to _sources_
- removed support for comma-separated paths in _targetFiles_
- renamed _encoding_ value `win1252` to `windows1252`
Expand Down Expand Up @@ -287,8 +288,7 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens](
additionalVariables: |
- '@**/vars.(json|yml|yaml)' # read from files
- '$ENV_VARS', # read from env
- # inline key/value pairs
var1: '${{ parameters.var1 }}'
- var1: '${{ parameters.var1 }}' # inline key/value pairs
var2: '${{ parameters.var2 }}'
```

Expand Down
28 changes: 14 additions & 14 deletions tasks/ReplaceTokensV6/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ async function run() {
}
};

console.log(tl.getVariables());
const variables = rt.merge(
tl.getVariables().reduce((map, current) => {
map[current.name] = current.value;
return map;
const variables = rt.flattenAndMerge(
options.separator,
tl.getVariables().reduce((result, current) => {
result[current.name] = current.value;
return result;
}, {}),
await parseVariables(tl.getInput('additionalVariables'), options.root)
await parseVariables(tl.getInput('additionalVariables'), options.root, options.separator)
);

const ifNoFilesFound = tl.getInput('ifNoFilesFound') || 'ignore';
Expand Down Expand Up @@ -194,24 +194,24 @@ var getChoiceInput = function (name: string, choices: string[]): string {
throw new Error(`Unsupported value for input: ${name}\nSupport input list: '${choices.join(' | ')}'`);
};

var parseVariables = async function (input: string, root: string): Promise<{ [key: string]: any }> {
var parseVariables = async function (input: string, root: string, separator: string): Promise<{ [key: string]: any }> {
input = input || '';
if (!input) return {};

switch (input[0]) {
case '@': // single string referencing a file
return await loadVariablesFromFile(input.substring(1), root);
return await loadVariablesFromFile(input.substring(1), root, separator);

case '$': // single string referencing environment variable
return loadVariablesFromEnv(input.substring(1));

default: // yaml format
return await loadVariablesFromYaml(input, root);
return await loadVariablesFromYaml(input, root, separator);
}
};

var variableFilesCount = 0;
var loadVariablesFromFile = async function (name: string, root: string): Promise<{ [key: string]: any }> {
var loadVariablesFromFile = async function (name: string, root: string, separator: string): Promise<{ [key: string]: any }> {
var files = await fg.glob(
name.split(';').map(v => v.trim()),
{
Expand Down Expand Up @@ -240,7 +240,7 @@ var loadVariablesFromFile = async function (name: string, root: string): Promise
++variableFilesCount;
}

return rt.merge(...vars);
return rt.flattenAndMerge(separator, ...vars);
};

var variablesEnvCount = 0;
Expand All @@ -253,13 +253,13 @@ var loadVariablesFromEnv = function (name: string): { [key: string]: any } {
};

var inlineVariablesCount = 0;
var loadVariablesFromYaml = async function (input: string, root: string): Promise<{ [key: string]: any }> {
var loadVariablesFromYaml = async function (input: string, root: string, separator: string): Promise<{ [key: string]: any }> {
const variables = yaml.load(input);
const load = async (v: any) => {
if (typeof v === 'string') {
switch (v[0]) {
case '@':
return await loadVariablesFromFile(v.substring(1), root);
return await loadVariablesFromFile(v.substring(1), root, separator);

case '$':
return loadVariablesFromEnv(v.substring(1));
Expand All @@ -281,7 +281,7 @@ var loadVariablesFromYaml = async function (input: string, root: string): Promis
vars.push(await load(v));
}

return rt.merge(...vars);
return rt.flattenAndMerge(separator, ...vars);
}

return await load(variables);
Expand Down
14 changes: 7 additions & 7 deletions tasks/ReplaceTokensV6/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tasks/ReplaceTokensV6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/sdk-trace-base": "^1.22.0",
"@opentelemetry/semantic-conventions": "^1.22.0",
"@qetza/replacetokens": "^1.1.0",
"@qetza/replacetokens": "^1.2.0",
"axios": "^1.6.7",
"azure-pipelines-task-lib": "^4.1.0",
"fast-glob": "^3.3.2",
Expand Down

0 comments on commit 89d4b47

Please sign in to comment.