Skip to content

Commit

Permalink
feat: Add module version to the /status output (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Mar 29, 2024
1 parent 8e7f17b commit a9603f8
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
40 changes: 40 additions & 0 deletions Scripts/update-wda-version.js
Original file line number Diff line number Diff line change
@@ -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())();
5 changes: 5 additions & 0 deletions WebDriverAgentLib/Commands/FBSessionCommands.m
Original file line number Diff line number Diff line change
Expand Up @@ -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(
@{
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a9603f8

Please sign in to comment.