-
Notifications
You must be signed in to change notification settings - Fork 10
Add AI version update script to assist with automated integration testing #63
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,4 +94,4 @@ | |
| "optional": true | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Unused variable, import, function or class