diff --git a/Scripts/update-wda-version.js b/Scripts/update-wda-version.js new file mode 100644 index 000000000..37102345a --- /dev/null +++ b/Scripts/update-wda-version.js @@ -0,0 +1,40 @@ +const {plist} = require('@appium/support'); +const path = require('node:path'); +const semver = require('semver'); +const log = require('fancy-log'); + +/** + * @param {string} argName + * @returns {string|null} + */ +function parseArgValue (argName) { + const argNamePattern = new RegExp(`^--${argName}\\b`); + for (let i = 1; i < process.argv.length; ++i) { + const arg = process.argv[i]; + if (argNamePattern.test(arg)) { + return arg.includes('=') ? arg.split('=')[1] : process.argv[i + 1]; + } + } + return null; +} + +async function updateWdaVersion() { + const newVersion = parseArgValue('package-version'); + if (!newVersion) { + throw new Error('No package version argument (use `--package-version=xxx`)'); + } + if (!semver.valid(newVersion)) { + throw new Error( + `Invalid version specified '${newVersion}'. Version should be in the form '1.2.3'` + ); + } + + const libManifest = path.resolve('WebDriverAgentLib', 'Info.plist'); + log.info(`Updating the WebDriverAgent manifest at '${libManifest}' to version '${newVersion}'`); + await plist.updatePlistFile(libManifest, { + CFBundleShortVersionString: newVersion, + CFBundleVersion: newVersion, + }, false); +} + +(async () => await updateWdaVersion())(); diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 380dfcc79..cd6a28a90 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -279,6 +279,11 @@ + (NSArray *)routes if (nil != upgradeTimestamp && upgradeTimestamp.length > 0) { [buildInfo setObject:upgradeTimestamp forKey:@"upgradedAt"]; } + NSDictionary *infoDict = [[NSBundle bundleForClass:self.class] infoDictionary]; + NSString *version = [infoDict objectForKey:@"CFBundleShortVersionString"]; + if (nil != version) { + [buildInfo setObject:version forKey:@"version"]; + } return FBResponseWithObject( @{ diff --git a/package.json b/package.json index 0ce67cfc9..1d0466a30 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,14 @@ "format": "prettier -w ./lib", "lint:fix": "npm run lint -- --fix", "prepare": "npm run build", + "version": "npm run sync-wda-version", "test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"", "e2e-test": "mocha --exit --timeout 10m \"./test/functional/**/*-specs.js\"", "bundle": "npm run bundle:ios && npm run bundle:tv", "bundle:ios": "TARGET=runner SDK=sim node ./Scripts/build-webdriveragent.js", "bundle:tv": "TARGET=tv_runner SDK=tv_sim node ./Scripts/build-webdriveragent.js", - "fetch-prebuilt-wda": "node ./Scripts/fetch-prebuilt-wda.js" + "fetch-prebuilt-wda": "node ./Scripts/fetch-prebuilt-wda.js", + "sync-wda-version": "node ./scripts/update-wda-version.js --package-version=${npm_package_version} && git add WebDriverAgentLib/Info.plist" }, "engines": { "node": ">=14", @@ -73,10 +75,12 @@ "eslint-plugin-import": "^2.28.0", "eslint-plugin-mocha": "^10.1.0", "eslint-plugin-promise": "^6.1.1", + "fancy-log": "^2.0.0", "node-simctl": "^7.0.1", "mocha": "^10.0.0", "prettier": "^3.0.0", "semantic-release": "^23.0.0", + "semver": "^7.3.7", "sinon": "^17.0.0", "ts-node": "^10.9.1", "typescript": "^5.4.2"