Skip to content

Commit

Permalink
Merge pull request #76 from digi-trust/dis-88
Browse files Browse the repository at this point in the history
Dis-88. Auto replace version number in config variables
  • Loading branch information
goosemanjack authored Dec 19, 2019
2 parents 11f9b57 + f3dbc54 commit 7e81a69
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 104 deletions.
30 changes: 13 additions & 17 deletions documentation/README_development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 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
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
Expand Down
193 changes: 193 additions & 0 deletions src/config/GeneralConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
'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');

// 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%";

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 (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 {
if (prevVer != null) {
prevVersion = prevVer;
}
else if (BUILD_VERSION_OVERRIDE != null) {
prevVersion = BUILD_VERSION_OVERRIDE;
}
}

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) > -1) {
urlObj[key] = val.replace(variable, 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
}
86 changes: 0 additions & 86 deletions src/config/general.json

This file was deleted.

2 changes: 1 addition & 1 deletion src/modules/ConfigLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions test/jest/configLoader.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const config = require('../../src/modules/ConfigLoader');
const generalConfig = require('../../src/config/GeneralConfig');

beforeEach(() => {
config.reset();
Expand All @@ -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");

});

0 comments on commit 7e81a69

Please sign in to comment.