Open History to see the last commit
1const fs = require("node:fs");
2
3const CONFIG_PATH = "apps/mobile/app.config.ts";
4const VERSION_LINE = /^( {2}version: repoEnv\.T3CODE_MOBILE_VERSION \?\? ")[^"]+(".*)$/m;
5
6// Replaces one string literal, so the result needs no formatter.
7function setMobileVersion(source, version) {
8 if (!/^[0-9]+(\.[0-9]+){1,2}$/.test(version)) {
9 throw new Error(
10 `Version override must contain two or three dot-separated integers; received '${version}'.`,
11 );
12 }
13 if (!VERSION_LINE.test(source)) throw new Error("Could not update app version");
14 return source.replace(VERSION_LINE, `$1${version}$2`);
15}
16
17if (require.main === module) {
18 const { GITHUB_REF_TYPE, GITHUB_REF_NAME } = process.env;
19 if (GITHUB_REF_TYPE !== "branch") {
20 throw new Error(
21 `Version overrides require dispatching this workflow from a branch; received ${GITHUB_REF_TYPE} '${GITHUB_REF_NAME}'.`,
22 );
23 }
24 fs.writeFileSync(
25 CONFIG_PATH,
26 setMobileVersion(fs.readFileSync(CONFIG_PATH, "utf8"), process.argv[2] ?? ""),
27 );
28}
29
30module.exports = { setMobileVersion };