From 37bf7f6e6b90e33d22af4b41f164976eafef09f7 Mon Sep 17 00:00:00 2001 From: Chris Cole Date: Tue, 17 Dec 2019 11:29:03 -0800 Subject: [PATCH 1/3] #DIS-88 Modify usage of general config to auto-manage URL paths based on current version number. --- src/config/GeneralConfig.js | 178 +++++++++++++++++++++++++++++++++ src/config/general.json | 86 ---------------- src/modules/ConfigLoader.js | 2 +- test/jest/configLoader.test.js | 11 ++ 4 files changed, 190 insertions(+), 87 deletions(-) create mode 100644 src/config/GeneralConfig.js delete mode 100644 src/config/general.json diff --git a/src/config/GeneralConfig.js b/src/config/GeneralConfig.js new file mode 100644 index 0000000..3fefd92 --- /dev/null +++ b/src/config/GeneralConfig.js @@ -0,0 +1,178 @@ +'use strict'; + +/** + * GeneralConfig + * @module + * + * @description Configuration settings for various environments. + * Adapted from general.json to avoid errors with manual version number updates. + * @author Chris Cole + * + * */ + +var VERSION = require('../_version.js'); + +var VARIABLE_CURRENT_VERSION = "%CURRENT_VERSION%"; +var VARIABLE_PRIOR_VERSION = "%PRIOR_VERSION%"; + +var configJson = { + "prod": { + "urls": { + "digitrustHostPath": "https://cdn.digitru.st/prod/%CURRENT_VERSION%/", + "digitrustRedirect": "https://cdn.digitru.st/prod/%CURRENT_VERSION%/redirect.html", + "digitrustIframe": "https://cdn.digitru.st/prod/%CURRENT_VERSION%/dt.html", + "digitrustIdService": "https://cdn-cf.digitru.st/id/v1", + "optoutInfo": "http://www.digitru.st/about-this-notice/", + "adblockCheck": "http://stats.aws.rubiconproject.com/" + }, + "redirectInterval": { + "exp": 7 + }, + "cookie": { + "version": 2, + "producer": "1CrsdUNAo6", + "publisher": { + "domainKeyValue": "", + "pathKeyValue": "path=/;", + "maxAgeMiliseconds": 604800000, + "userObjectKey": "DigiTrust.v1.identity" + }, + "digitrust": { + "domainKeyValue": "domain=.digitru.st;", + "pathKeyValue": "path=/;", + "maxAgeMiliseconds": 31536000000, + "userObjectKey": "DigiTrust.v1.identity", + "resetKey": "DeleteEverything", + "challenge": "DTChal", + "optout": "optout", + "optoutUser": { + "id": "", + "privacy": { + "optout": true + } + }, + "errorUser": { + "error": true + } + } + }, + "iframe": { + "timeoutDuration": 10000, + "postMessageOrigin": "https://cdn.digitru.st" + }, + "crypto": { + "serverCryptoRate": 0.0 + }, + "logging": { + "enable": false, + "level": "ERROR" + }, + "gvlVendorId": 64 + }, + "build": { + "urls": { + "digitrustHostPath": "https://cdn.digitru.st/prod/%PRIOR_VERSION%/", + "digitrustRedirect": "https://cdn.digitru.st/prod/%PRIOR_VERSION%/redirect.html", + "digitrustIframe": "https://cdn.digitru.st/prod/%PRIOR_VERSION%/dt.html", + "digitrustIdService": "https://cdn-cf.digitru.st/id/v1", + "optoutInfo": "http://www.digitru.st/about-this-notice/", + "adblockCheck": "http://stats.aws.rubiconproject.com/" + } + }, + "local": { + "urls": { + "digitrustHostPath": "//localhost/dist/", + "digitrustRedirect": "//localhost/dist/redirect.html", + "digitrustIframe": "//local.digitru.st/dist/dt_debug.html", + "digitrustIdService": "http://local.digitru.st/misc/faked_id_service_v1.json", + "optoutInfo": "//localhost/dist/info.html", + "adblockCheck": "//stats.aws.rubiconproject.com/" + }, + "iframe": { + "timeoutDuration": 10000, + "postMessageOrigin": "http://local.digitru.st" + }, + "crypto": { + "serverCryptoRate": 1.0 + }, + "logging": { + "level": "DEBUG" + }, + "gvlVendorId": 64 + } +} + + +// =============================== METHODS TO RETURN SNAPSHOT OF CONFIG ====================== + +/** + * Calculates the current version and previous version for purposes of file paths + * in config. + * @param {String} ver a package version number + * @param {any} prevVer optional override to previous version for build purposes + */ +function computeVersions(ver, prevVer) { + ver = ver || VERSION; + + var result = { + current: null, + prior: null + }; + + var currentVersion, prevVersion; + var verParts = ver.split('.'); + var prevMinor = parseInt(verParts[verParts.length - 1]); + + if (isNaN(prevMinor)) { + prevMinor = 0; + } + else { + prevMinor = prevMinor - 1; + } + + currentVersion = ver; + verParts[verParts.length - 1] = new String(prevMinor); + + prevVersion = verParts.join('.'); + + result.current = currentVersion; + result.prior = prevVersion; + + return result; +} + +function replaceUrlVariables(urlObj, variable, value) { + var key, val; + // Replace known URL values + for (key in urlObj) { + if (urlObj.hasOwnProperty(key)) { + val = urlObj[key]; + if (val.indexOf(VARIABLE_CURRENT_VERSION) > -1) { + urlObj[key] = val.replace(VARIABLE_CURRENT_VERSION, value); + } + } + } +} + +/** + * Returns the full configuration JSON with adjustments applied for version numbering + * @function + * + * */ +function getFullConfig(ver, prevVersion) { + ver = ver || VERSION; + + var versionResult = computeVersions(ver, prevVersion); + + var config = configJson; + replaceUrlVariables(config.prod.urls, VARIABLE_CURRENT_VERSION, versionResult.current); + replaceUrlVariables(config.build.urls, VARIABLE_PRIOR_VERSION, versionResult.prior); + + return config; +} + + +module.exports = { + getFullConfig: getFullConfig, + computeVersions: computeVersions +} diff --git a/src/config/general.json b/src/config/general.json deleted file mode 100644 index 01b89a8..0000000 --- a/src/config/general.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "prod": { - "urls": { - "digitrustHostPath": "https://cdn.digitru.st/prod/1.5.40/", - "digitrustRedirect": "https://cdn.digitru.st/prod/1.5.40/redirect.html", - "digitrustIframe": "https://cdn.digitru.st/prod/1.5.40/dt.html", - "digitrustIdService": "https://cdn-cf.digitru.st/id/v1", - "optoutInfo": "http://www.digitru.st/about-this-notice/", - "adblockCheck": "http://stats.aws.rubiconproject.com/" - }, - "redirectInterval": { - "exp": 7 - }, - "cookie": { - "version": 2, - "producer": "1CrsdUNAo6", - "publisher": { - "domainKeyValue": "", - "pathKeyValue": "path=/;", - "maxAgeMiliseconds": 604800000, - "userObjectKey": "DigiTrust.v1.identity" - }, - "digitrust": { - "domainKeyValue": "domain=.digitru.st;", - "pathKeyValue": "path=/;", - "maxAgeMiliseconds": 31536000000, - "userObjectKey": "DigiTrust.v1.identity", - "resetKey": "DeleteEverything", - "challenge": "DTChal", - "optout": "optout", - "optoutUser": { - "id": "", - "privacy": { - "optout": true - } - }, - "errorUser": { - "error": true - } - } - }, - "iframe": { - "timeoutDuration": 10000, - "postMessageOrigin": "https://cdn.digitru.st" - }, - "crypto": { - "serverCryptoRate": 0.0 - }, - "logging": { - "enable": false, - "level": "ERROR" - }, - "gvlVendorId": 64 - }, - "build": { - "urls": { - "digitrustHostPath": "https://cdn.digitru.st/prod/1.5.36/", - "digitrustRedirect": "https://cdn.digitru.st/prod/1.5.36/redirect.html", - "digitrustIframe": "https://cdn.digitru.st/prod/1.5.36/dt.html", - "digitrustIdService": "https://cdn-cf.digitru.st/id/v1", - "optoutInfo": "http://www.digitru.st/about-this-notice/", - "adblockCheck": "http://stats.aws.rubiconproject.com/" - } - }, - "local": { - "urls": { - "digitrustHostPath": "//localhost/dist/", - "digitrustRedirect": "//localhost/dist/redirect.html", - "digitrustIframe": "//local.digitru.st/dist/dt_debug.html", - "digitrustIdService": "http://local.digitru.st/misc/faked_id_service_v1.json", - "optoutInfo": "//localhost/dist/info.html", - "adblockCheck": "//stats.aws.rubiconproject.com/" - }, - "iframe": { - "timeoutDuration": 10000, - "postMessageOrigin": "http://local.digitru.st" - }, - "crypto": { - "serverCryptoRate": 1.0 - }, - "logging": { - "level": "DEBUG" - }, - "gvlVendorId": 64 - } -} diff --git a/src/modules/ConfigLoader.js b/src/modules/ConfigLoader.js index 0fd33fa..2cfdbb4 100644 --- a/src/modules/ConfigLoader.js +++ b/src/modules/ConfigLoader.js @@ -10,7 +10,7 @@ * */ var buildEnv = require('../config/env.json').current; -var genConfig = require('../config/general.json'); +var genConfig = require('../config/GeneralConfig').getFullConfig(); var activeConfig = genConfig[buildEnv]; var helpers = require('./helpers'); var myConfig; diff --git a/test/jest/configLoader.test.js b/test/jest/configLoader.test.js index 7b520fe..fa5d317 100644 --- a/test/jest/configLoader.test.js +++ b/test/jest/configLoader.test.js @@ -1,4 +1,5 @@ const config = require('../../src/modules/ConfigLoader'); +const generalConfig = require('../../src/config/GeneralConfig'); beforeEach(() => { config.reset(); @@ -25,3 +26,13 @@ test('load-new-config', () => { }); +test('version Calculations with base only', () => { + var baseVersion = "1.5.31"; + + var result = generalConfig.computeVersions(baseVersion); + + expect(result.current).toBe(baseVersion); + expect(result.prior).toBe("1.5.30"); + +}); + From 3fc8ea31306561c4174a08aa5281ef3a4fa9f714 Mon Sep 17 00:00:00 2001 From: Chris Cole Date: Tue, 17 Dec 2019 13:57:49 -0800 Subject: [PATCH 2/3] #DIS-88. Update to readme for build instructions. Variable to allow explicit version for build verification. Fix bug in version variable replacement. --- documentation/README_development.md | 30 +++++++++++-------------- src/config/GeneralConfig.js | 35 ++++++++++++++++++++--------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/documentation/README_development.md b/documentation/README_development.md index 5bd83de..7969402 100644 --- a/documentation/README_development.md +++ b/documentation/README_development.md @@ -57,23 +57,19 @@ To verify the current release version, consult this URL https://cdn.digitru.st/p test page Prebid.js/integrationExamples/gpt/digitrust_Full.html and type `DigiTrust.version` in the debug console. 1. Update `version` in `package.json` -2. Update `digitrustHostPath`, `digitrustRedirect`, and `digitrustIframe` in the `prod` section of `src/config/general.json` - to match the new version number in the URL path. -3. Update `digitrustHostPath`, `digitrustRedirect`, and `digitrustIframe` to the most recent prior - release version in the `build` section of `src/config/general.json` -4. Build with command `yarn build` -5. Commit and push your changes to master branch -6. git checkout candidate -7. git pull -8. git merge --no-ff master -9. git tag candidate-1.5.37 (update to your version number as set in step 1) -10. git push --follow-tags (and then wait to confirm CircleCI build is successful) -11. git push --force origin candidate-1.5.37:release (then wait for successful CircleCI build) -12. git checkout master -13. git tag v1.5.37 -14. git push origin v1.5.37 -15. Go to project site on Github and draft a new release -16. Reflect release notes in the `Release Notes` wiki page at https://github.com/digi-trust/dt-cdn/wiki/Release-Notes +2. Build with command `yarn build` +3. Commit and push your changes to master branch +4. git checkout candidate +5. git pull +6. git merge --no-ff master +7. git tag candidate-1.5.37 (update to your version number as set in step 1) +8. git push --follow-tags (and then wait to confirm CircleCI build is successful) +9. git push --force origin candidate-1.5.37:release (then wait for successful CircleCI build) +10. git checkout master +11. git tag v1.5.37 +12. git push origin v1.5.37 +13. Go to project site on Github and draft a new release +14. Reflect release notes in the `Release Notes` wiki page at https://github.com/digi-trust/dt-cdn/wiki/Release-Notes ## Development Roadmap Notes diff --git a/src/config/GeneralConfig.js b/src/config/GeneralConfig.js index 3fefd92..c5813c4 100644 --- a/src/config/GeneralConfig.js +++ b/src/config/GeneralConfig.js @@ -12,6 +12,11 @@ var VERSION = require('../_version.js'); +// Add an explicit value here to control how builds verify during the build automation testing. +// Normally a build assumes one version prior. This can be used to specify a build number for +// testing purposes in the CircleCI build. Leave null for default behavior +var BUILD_VERSION_OVERRIDE = null; + var VARIABLE_CURRENT_VERSION = "%CURRENT_VERSION%"; var VARIABLE_PRIOR_VERSION = "%PRIOR_VERSION%"; @@ -123,17 +128,27 @@ function computeVersions(ver, prevVer) { var verParts = ver.split('.'); var prevMinor = parseInt(verParts[verParts.length - 1]); - if (isNaN(prevMinor)) { - prevMinor = 0; + if (prevVer == null && BUILD_VERSION_OVERRIDE == null) { + if (isNaN(prevMinor)) { + prevMinor = 0; + } + else { + prevMinor = prevMinor - 1; + } + + currentVersion = ver; + verParts[verParts.length - 1] = new String(prevMinor); + + prevVersion = verParts.join('.'); } else { - prevMinor = prevMinor - 1; + if (prevVer != null) { + prevVersion = prevVer; + } + else if (BUILD_VERSION_OVERRIDE != null) { + prevVersion = BUILD_VERSION_OVERRIDE; + } } - - currentVersion = ver; - verParts[verParts.length - 1] = new String(prevMinor); - - prevVersion = verParts.join('.'); result.current = currentVersion; result.prior = prevVersion; @@ -147,8 +162,8 @@ function replaceUrlVariables(urlObj, variable, value) { for (key in urlObj) { if (urlObj.hasOwnProperty(key)) { val = urlObj[key]; - if (val.indexOf(VARIABLE_CURRENT_VERSION) > -1) { - urlObj[key] = val.replace(VARIABLE_CURRENT_VERSION, value); + if (val.indexOf(variable) > -1) { + urlObj[key] = val.replace(variable, value); } } } From f3dbc544720434b82838ee86ed463f164e6f6ac7 Mon Sep 17 00:00:00 2001 From: Chris Cole Date: Thu, 19 Dec 2019 08:54:45 -0800 Subject: [PATCH 3/3] #DIS-89. Eliminate the "candidate" tag convention and stick with v1.5.xx version tag names. --- documentation/README_development.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/README_development.md b/documentation/README_development.md index 7969402..4b7413d 100644 --- a/documentation/README_development.md +++ b/documentation/README_development.md @@ -62,9 +62,9 @@ test page Prebid.js/integrationExamples/gpt/digitrust_Full.html and type `DigiTr 4. git checkout candidate 5. git pull 6. git merge --no-ff master -7. git tag candidate-1.5.37 (update to your version number as set in step 1) +7. git tag v1.5.39 (update to your version number as set in step 1) 8. git push --follow-tags (and then wait to confirm CircleCI build is successful) -9. git push --force origin candidate-1.5.37:release (then wait for successful CircleCI build) +9. git push --force origin v1.5.39:release (then wait for successful CircleCI build) 10. git checkout master 11. git tag v1.5.37 12. git push origin v1.5.37