Skip to content

Commit

Permalink
rework telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
qetza committed Mar 8, 2024
1 parent 1b0ad0f commit bc9fb5f
Show file tree
Hide file tree
Showing 53 changed files with 1,118 additions and 1,961 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
npm --prefix tasks/ReplaceTokensV5 ci
- name: Check code format
run: npm run format-check
run: npm run format:check

- name: Build
run: npm run build
Expand Down
50 changes: 49 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,62 @@
# Changelog

## 4.6.0
## 5.0.0
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
- 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`
- renamed input _verbosity_ to _logLevel_
- renamed _verbosity_ value `detailed` to `debug`
- renamed _verbosity_ value `normal` to `info`
- removed _verbosity_ value `off` (see new supported values for replacement)
- renamed input _actionOnMissing_ to _missingVarLog_
- renamed _actionOnMissing_ value `continue` to `off`
- renamed _actionOnMissing_ value `fail` to `error`
- replaced _keepToken_ with _missingVarAction_ with value `keep`
- renamed input _actionOnNoFiles_ to _ifNoFilesFound_
- renamed _actionOnNoFiles_ value `continue` to `ignore`
- renamed _actionOnNoFiles_ value `fail` to `error`
- renamed input _enableTransforms_ to _transforms_
- renamed transform `noescape` to `raw`
- renamed input _transformPrefix_ to _transformsPrefix_
- renamed input _transformSuffix_ to _transformsSuffix_
- removed input _useLegacyPattern_
- removed input _useLegacyEmptyFeature_
- replaced input _useDefaultValue_ with _missingVarAction_ with value `replace`
- removed input _emptyValue_
- renamed input _defaultValue_ to _missingVarDefault_
- removed input _enableTelemetry_ to _telemetryOptout_ and inverse meaning
- renamed output _tokenReplacedCount_ to _replaced_
- renamed output _tokenFoundCount_ to _tokens_
- renamed output _fileProcessedCount_ to _files_
- renamed output _transformExecutedCount_ to _transforms_
- renamed output _defaultValueCount_ to _defaults_
- Add new token pattern `githubactions`.
- Add new log levels `warn` and `error`.
- Add support in _additionalVariables_ for JSON encoded environment variables.
- Add support for `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable.

Task 5.3.0
- Add support for `indent` transformation with indent size and indent first line parameters ([326](https://github.com/qetza/vsts-replacetokens-task/issues/326)).
- Add support for `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable.

Task 4.4.0
- Add support for `indent` transformation with indent size and indent first line parameters ([326](https://github.com/qetza/vsts-replacetokens-task/issues/326)).
- Add support for `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable.

Task 3.12.0
- Add support for `indent` transformation with indent size and indent first line parameters ([326](https://github.com/qetza/vsts-replacetokens-task/issues/326)).
- Add support for `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable.

## 4.5.0
Task 5.2.0
Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens](
- replaced input _useDefaultValue_ with _missingVarAction_ with value `replace`
- removed input _emptyValue_
- renamed input _defaultValue_ to _missingVarDefault_
- removed input _enableTelemetry_ to _telemetry_
- removed input _enableTelemetry_ to _telemetryOptout_ and inverse meaning
- renamed output _tokenReplacedCount_ to _replaced_
- renamed output _tokenFoundCount_ to _tokens_
- renamed output _fileProcessedCount_ to _files_
Expand Down Expand Up @@ -199,10 +199,12 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens](
# Optional. Default: .
separator: ''

# Enable sending anonymous usage data for analytics.
# Opt out of the anonymous telemetry feature.
# You can also set the REPLACETOKENS_TELEMETRY_OPTOUT environment variable to '1' or
# 'true'.
#
# Optional. Default: true
telemetry: ''
# Optional. Default: false
telemetryOptout: ''

# The token pattern to use.
# Use 'custom' to provide your own prefix and suffix.
Expand Down Expand Up @@ -283,9 +285,9 @@ The task was completely rewritten to use the npm package [@qetza/replacetokens](
inputs:
sources: '**/*.json'
additionalVariables: |
- '@**/vars.(json|yml|yaml)'
- '$ENV_VARS',
-
- '@**/vars.(json|yml|yaml)' # read from files
- '$ENV_VARS', # read from env
- # inline key/value pairs
var1: '${{ parameters.var1 }}'
var2: '${{ parameters.var2 }}'
```
Expand All @@ -306,13 +308,12 @@ steps:
```

## Data/Telemetry
The Replace Tokens task for Azure Pipelines collects **anonymous** usage data and sends them by default to its author to help improve the product. If you don't wish to send usage data, you can change your telemetry settings through _telemetry_ parameter or by setting a variable or environment variable `REPLACETOKENS_DISABLE_TELEMETRY` to `true`.
The Replace Tokens task for Azure Pipelines collects **anonymous** usage data and sends them by default to its author to help improve the product. If you don't wish to send usage data, you can change your telemetry settings through the _telemetryOptout_ parameter or by setting the `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable to `1` or `true`.

The following **anonymous** data is send:
- the **hash** of your organization name/collection id
- the **hash** of your collection id
- the **hash** of your project id and pipeline definition id
- the pipeline type (`build` or `release`)
- the hosting (`server` or `services`)
- the hosting (`server` or `cloud`)
- the inputs values for
- _addBOM_
- _charsToEscape_
Expand All @@ -336,7 +337,7 @@ The following **anonymous** data is send:
- the **number of** _additionalVariables_ entries referencing file
- the **number of** _additionalVariables_ entries referencing environment variables
- the **number of** _additionalVariables_ inline entries
- the task result (`succeeded` or `failed`)
- the task result (`succeed` or `failed`)
- the task execution duration
- the outputs (defaults, files, replaced, tokens and transforms)

Expand Down
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@
"url": "git+https://github.com/qetza/replacetokens-task.git"
},
"scripts": {
"build": "npm run build-v3 && npm run build-v4 && npm run build-v5 && npm run build-v6",
"build-v3": "tsc --project tasks/ReplaceTokensV3/tsconfig.json",
"build-v4": "tsc --project tasks/ReplaceTokensV4/tsconfig.json",
"build-v5": "tsc --project tasks/ReplaceTokensV5/tsconfig.json",
"build-v6": "tsc --project tasks/ReplaceTokensV6/tsconfig.json",
"build": "npm run build:v3 && npm run build:v4 && npm run build:v5 && npm run build:v6",
"build:v3": "tsc --project tasks/ReplaceTokensV3/tsconfig.json",
"build:v4": "tsc --project tasks/ReplaceTokensV4/tsconfig.json",
"build:v5": "tsc --project tasks/ReplaceTokensV5/tsconfig.json",
"build:v6": "tsc --project tasks/ReplaceTokensV6/tsconfig.json",
"test": "mocha tasks/**/tests/L0.js",
"test-v3": "mocha tasks/ReplaceTokensV3/dist/tests/L0.js",
"test-v4": "mocha tasks/ReplaceTokensV4/dist/tests/L0.js",
"test-v5": "mocha tasks/ReplaceTokensV5/dist/tests/L0.js",
"test-v6": "mocha tasks/ReplaceTokensV6/dist/tests/L0.js",
"test:v3": "mocha tasks/ReplaceTokensV3/dist/tests/L0.js",
"test:v4": "mocha tasks/ReplaceTokensV4/dist/tests/L0.js",
"test:v5": "mocha tasks/ReplaceTokensV5/dist/tests/L0.js",
"test:v6": "mocha tasks/ReplaceTokensV6/dist/tests/L0.js",
"package": "node scripts/package.js",
"package-public": "node scripts/package.js --public",
"format": "npm run format-v3 && npm run format-v4 && npm run format-v5 && npm run format-v6",
"format-v3": "prettier --write tasks/ReplaceTokensV3/**/*.ts",
"format-v4": "prettier --write tasks/ReplaceTokensV4/**/*.ts",
"format-v5": "prettier --write tasks/ReplaceTokensV5/**/*.ts",
"format-v6": "prettier --write tasks/ReplaceTokensV6/**/*.ts",
"format-check": "prettier --check **/*.ts"
"format": "npm run format:v3 && npm run format:v4 && npm run format:v5 && npm run format:v6",
"format:v3": "prettier --write tasks/ReplaceTokensV3/**/*.ts",
"format:v4": "prettier --write tasks/ReplaceTokensV4/**/*.ts",
"format:v5": "prettier --write tasks/ReplaceTokensV5/**/*.ts",
"format:v6": "prettier --write tasks/ReplaceTokensV6/**/*.ts",
"format:check": "prettier --check **/*.ts"
},
"devDependencies": {
"@types/node": "^10.17.0",
Expand Down
8 changes: 4 additions & 4 deletions scripts/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ cp('-Rf', path.join(__dirname, '..', 'images', 'screenshot*.png'), `${packageIma
// update metadata
var public = process.argv.includes('--public');
var taskId = public ? undefined : '0664FF86-F509-4392-A33C-B2D9239B9AE5';
var instrumentationKey = public ? undefined : '6c5a849a-a333-4eee-9fd0-fa4597251c5c';
var application = public ? undefined : 'replacetokens-task-dev';

versions.forEach(version => {
console.log();
Expand Down Expand Up @@ -176,10 +176,10 @@ versions.forEach(version => {
fs.writeFileSync(path.join(packageTaskDir, 'task.json'), JSON.stringify(manifest, null, 2));

var script = fs.readFileSync(path.join(packageTaskDir, 'index.js'), { encoding: 'utf8' });
if (instrumentationKey) {
script = script.replace(/const\s+instrumentationKey\s*=\s*'[^']*'\s*;/, `const instrumentationKey = '${instrumentationKey}';`);
if (application) {
script = script.replace(/const\s+application\s*=\s*'[^']*'\s*;/, `const application = '${application}';`);

console.log(`> instrumentationKey: ${instrumentationKey}`);
console.log(`> application: ${application}`);
}

script = script.replace(/const\s+version\s*=\s*'[^']*'\s*;/, `const version = '${taskVersion}';`);
Expand Down
1 change: 1 addition & 0 deletions tasks/ReplaceTokensV3/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 3.12.0
- Add support for `indent` transformation with indent size and indent first line parameters ([326](https://github.com/qetza/vsts-replacetokens-task/issues/326)).
- Add support for `REPLACETOKENS_TELEMETRY_OPTOUT` environment variable.

## 3.11.0
- Fix recursion cycle detection ([#308](https://github.com/qetza/vsts-replacetokens-task/issues/308)) (contributed by Chad Smith).
Expand Down
4 changes: 2 additions & 2 deletions tasks/ReplaceTokensV3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Please refer to the [release page](https://github.com/qetza/replacetokens-task/r
```
## Data/Telemetry
The Replace Tokens task for Azure Pipelines collects **anonymous** usage data and sends them by default to its author to help improve the product. If you don't wish to send usage data, you can change your telemetry settings through _enableTelemetry_ parameter or by setting a variable or environment variable `REPLACETOKENS_DISABLE_TELEMETRY` to `true`.
The Replace Tokens task for Azure Pipelines collects **anonymous** usage data and sends them by default to its author to help improve the product. If you don't wish to send usage data, you can change your telemetry settings through the _enableTelemetry_ parameter or by setting a variable or environment variable `REPLACETOKENS_DISABLE_TELEMETRY` to `true`.

The following **anonymous** data is send:
- the task version
Expand Down Expand Up @@ -268,7 +268,7 @@ The following **anonymous** data is send:
- the **number of** _targetFiles_ entries having an output pattern
- the **number of** _variableFiles_ entries
- the **number of** _inlineVariables_ entries
- the task result (`succeeded` or `failed`)
- the task result (`succeed` or `failed`)
- the task execution duration
- the **number of** tokens replaced with the default value
- the **number of** files parsed
Expand Down
10 changes: 6 additions & 4 deletions tasks/ReplaceTokensV3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,17 @@ async function run() {
try {
const startTime: Date = new Date();
const serverType = tl.getVariable('System.ServerType');
telemetryEnabled = tl.getBoolInput('enableTelemetry', false) && tl.getVariable('REPLACETOKENS_DISABLE_TELEMETRY') !== 'true';
telemetryEnabled =
tl.getBoolInput('enableTelemetry', false) &&
['true', '1'].indexOf(process.env['REPLACETOKENS_TELEMETRY_OPTOUT'] || process.env['REPLACETOKENS_DISABLE_TELEMETRY']) === -1;

telemetryEvent.account = crypto.createHash('sha256').update(tl.getVariable('system.collectionid')).digest('hex');
telemetryEvent.pipeline = crypto
.createHash('sha256')
.update(tl.getVariable('system.teamprojectid') + tl.getVariable('system.definitionid'))
.digest('hex');
telemetryEvent.pipelineType = tl.getVariable('release.releaseid') ? 'release' : 'build';
telemetryEvent.serverType = !serverType || serverType.toLowerCase() !== 'hosted' ? 'server' : 'services';
telemetryEvent.serverType = !serverType || serverType.toLowerCase() !== 'hosted' ? 'server' : 'cloud';

// load inputs
const root: string = tl.getPathInput('rootDirectory', false, true);
Expand Down Expand Up @@ -678,7 +680,7 @@ async function run() {
telemetryEvent.escapeType = options.escapeType;
telemetryEvent.keepToken = options.keepToken;
telemetryEvent.pattern = regex.source;
telemetryEvent.result = 'succeeded';
telemetryEvent.result = 'succeed';
telemetryEvent.rules = rules.length;
telemetryEvent.rulesWithInputWildcard = ruleUsingInputWildcardCount;
telemetryEvent.rulesWithNegativePattern = ruleUsingNegativeInputPattern;
Expand Down Expand Up @@ -769,7 +771,7 @@ async function run() {
} finally {
if (telemetryEnabled) {
const trackedData = trackEvent(telemetryEvent, proxyUrl);
tl.debug('sent usage telemetry: ' + JSON.stringify(trackedData));
tl.debug('sent usage telemetry: ' + trackedData);
}
}
}
Expand Down
Loading

0 comments on commit bc9fb5f

Please sign in to comment.