Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AI version update script to assist with automated integration testing #63

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion applicationinsights-react-native/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@
"optional": true
}
}
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"rupdate": "node common/scripts/install-run-rush.js update --recheck --purge --full",
"serve": "grunt serve",
"setVersion": "node ./tools/release-tools/setVersion.js",
"setAiVersion": "node ./tools/release-tools/setAiVersion.js",
"purge": "node common/scripts/install-run-rush.js purge",
"fullClean": "git clean -xdf && npm install && rush update --recheck --full",
"fullCleanBuild": "npm run fullClean && npm run rebuild",
Expand Down
48 changes: 24 additions & 24 deletions sample/package.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "applicationinsights-reactnative-sample",
"version": "1.1.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@expo/webpack-config": "^18.0.1",
"@microsoft/applicationinsights-react-native": "^4.3.4",
"@microsoft/applicationinsights-web": "^3.3.4",
"expo": "~48.0.18",
"expo-status-bar": "~1.4.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.71.8",
"react-native-web": "~0.18.10"
},
"devDependencies": {
"@babel/core": "^7.20.0"
},
"private": true
"name": "applicationinsights-reactnative-sample",
"version": "1.1.1",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@expo/webpack-config": "^18.0.1",
"@microsoft/applicationinsights-react-native": "^4.3.4",
"@microsoft/applicationinsights-web": "^3.3.4",
"expo": "~48.0.18",
"expo-status-bar": "~1.4.4",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.71.8",
"react-native-web": "~0.18.10"
},
"devDependencies": {
"@babel/core": "^7.20.0"
},
"private": true
}
10 changes: 5 additions & 5 deletions tools/release-tools/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "applicationinsights-js-release-tools",
"version": "3.1.3-dev",
"author": "Javascript Telemetry SDKs <[email protected]>",
"description": "1DS Web SDK",
"homepage": "https://1dsdocs.azurewebsites.net/sdk.html",
"version": "3.1.3",
"author": "Microsoft Application Insights Team",
"description": "Microsoft Application Insights React Native release tools",
"homepage": "https://github.com/microsoft/applicationinsights-react-native#readme",
"sideEffects": false,
"scripts": {
"update": "rush update",
Expand All @@ -19,7 +19,7 @@
],
"repository": {
"type": "git",
"url": "https://msasg.visualstudio.com/DefaultCollection/Shared%20Data/_git/1DS.JavaScript"
"url": "https://github.com/microsoft/applicationinsights-react-native"
},
"devDependencies": {
"grunt": "^1.5.3",
Expand Down
175 changes: 175 additions & 0 deletions tools/release-tools/setAiVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
const fs = require("fs");
const globby = require("globby");

let newAiVer = null;
let testOnly = null;

const theVersion = require(process.cwd() + "/version.json");

function showHelp() {
var scriptParts;
var scriptName = process.argv[1];
if (scriptName.indexOf("\\") !== -1) {
scriptParts = scriptName.split("\\");
scriptName = scriptParts[scriptParts.length - 1];
} else if (scriptName.indexOf("/") !== -1) {
scriptParts = scriptName.split("/");
scriptName = scriptParts[scriptParts.length - 1];
}

console.log("");
console.log(scriptName + " [<newAiVersion> [-test]");
console.log("--------------------------");
console.log(" <newAiVersion> - Identifies the application insights version to set for all packages");
console.log(" -test - Scan all of the package.json files and log the changes, but DON'T update the files");
}

function parseArgs() {
if (process.argv.length < 2) {
console.error("!!! Invalid number of arguments -- " + process.argv.length);
return false;
}

let idx = 2;
while(idx < process.argv.length) {
let theArg = process.argv[idx];
if (theArg === "-test") {
testOnly = true;
} else if (!newAiVer) {
newAiVer = theArg;
} else {
console.error("!!! Invalid Argument [" + theArg + "] detected");
return false;
}

idx ++;
}

// If no version,
if (!newAiVer) {
return false;
}

return true;
}

function shouldProcess(name) {
if (name.indexOf("node_modules/") !== -1) {
return false;
}

if (name.indexOf("common/temp") !== -1) {
return false;
}

if (name.indexOf("examples/") !== -1) {
return true;
}

if (name.indexOf("sample/") !== -1) {
return true;
}

if (name.indexOf("applicationinsights-react-native") !== -1) {
return true;
}

if (name === "package.json") {
return true;
}

return false;
}

function shouldUpdateDependency(name) {
if (name.indexOf("@microsoft/applicationinsights-") === -1) {
return false;
}

if (name.indexOf("applicationinsights-shims") !== -1) {
return false;
}

if (name.indexOf("applicationinsights-rollup") !== -1) {
return false;
}

if (name.indexOf("applicationinsights-react-native") !== -1) {
// Don't update references to this package
return false;
}

return true;
}

function updateDependencies(target, newVersion) {
let changed = false;
if (target) {
let isDigit = /^\d/.test(newVersion);
Object.keys(target).forEach((value) => {
if (shouldUpdateDependency(value)) {
let version = target[value];
if (version.startsWith("^") && isDigit) {
if (version !== "^" + newVersion) {
target[value] = "^" + newVersion;
}
} else if (version.startsWith("~") && isDigit) {
if (version !== "~" + newVersion) {
target[value] = "~" + newVersion;
}
} else if (version !== newVersion) {
target[value] = newVersion;
}

if (version != target[value]) {
console.log(" Updated: " + value + " \"" + version + "\" => \"" + target[value] + "\"");
changed = true;
} else {
console.log(" Skipped: " + value + " \"" + version + "\"");
}
}
});
}

return changed;
}

const setPackageJsonRelease = () => {
const files = globby.sync(["./**/package.json", "!**/node_modules/**"]);
let changed = false;
files.map(packageFile => {
// Don't update node_modules
if (shouldProcess(packageFile)) {
console.log("Loading - " + packageFile);

let theFilename = packageFile;
const package = require(process.cwd() + "\\" + theFilename);
console.log(" Name - " + package.name);

let updated = false;
updated |= updateDependencies(package.dependencies, newAiVer);
updated |= updateDependencies(package.peerDependencies, newAiVer);
updated |= updateDependencies(package.devDependencies, newAiVer);

if (updated && !testOnly) {
// Rewrite the file
const newContent = JSON.stringify(package, null, 4) + "\n";
fs.writeFileSync(theFilename, newContent);
changed = true;
}
console.log(" -------------------------------------------------------------------------------------");
}
});

return changed;
};

if (parseArgs()) {
if (setPackageJsonRelease()) {
console.log("Version updated, now run 'npm run rupdate'");
} else {
console.log("Nothing Changed");
}
} else {
showHelp();
}
Loading