refactor(ios): derive app version from package.json

This commit is contained in:
Nimrod Gutman
2026-03-11 11:38:50 +02:00
parent 908ec22812
commit ccd0a4b751
19 changed files with 159 additions and 188 deletions

View File

@@ -4,13 +4,12 @@ set -euo pipefail
usage() {
cat <<'EOF'
Usage:
scripts/ios-beta-archive.sh --version 2026.3.9-beta.1 [--build-number 7]
scripts/ios-beta-archive.sh [--build-number 7]
Archives and exports a beta-release IPA locally without uploading.
EOF
}
VERSION="${IOS_BETA_VERSION:-}"
BUILD_NUMBER="${IOS_BETA_BUILD_NUMBER:-}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -19,10 +18,6 @@ while [[ $# -gt 0 ]]; do
--)
shift
;;
--version)
VERSION="${2:-}"
shift 2
;;
--build-number)
BUILD_NUMBER="${2:-}"
shift 2
@@ -39,15 +34,7 @@ while [[ $# -gt 0 ]]; do
esac
done
if [[ -z "${VERSION}" ]]; then
echo "Missing required --version (or IOS_BETA_VERSION)." >&2
usage
exit 1
fi
(
cd "${ROOT_DIR}/apps/ios"
IOS_BETA_VERSION="${VERSION}" \
IOS_BETA_BUILD_NUMBER="${BUILD_NUMBER}" \
fastlane ios beta_archive
IOS_BETA_BUILD_NUMBER="${BUILD_NUMBER}" fastlane ios beta_archive
)

View File

@@ -4,10 +4,10 @@ set -euo pipefail
usage() {
cat <<'EOF'
Usage:
scripts/ios-beta-prepare.sh --version 2026.3.9-beta.1 --build-number 7 [--team-id TEAMID]
scripts/ios-beta-prepare.sh --build-number 7 [--team-id TEAMID]
Prepares local beta-release inputs without touching local signing overrides:
- stamps apps/ios/project.yml with the short version + build number
- reads package.json.version and writes apps/ios/build/Version.xcconfig
- writes apps/ios/build/BetaRelease.xcconfig with canonical bundle IDs
- regenerates apps/ios/OpenClaw.xcodeproj via xcodegen
EOF
@@ -17,20 +17,17 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
IOS_DIR="${ROOT_DIR}/apps/ios"
BETA_XCCONFIG="${IOS_DIR}/build/BetaRelease.xcconfig"
TEAM_HELPER="${ROOT_DIR}/scripts/ios-team-id.sh"
VERSION_HELPER="${ROOT_DIR}/scripts/ios-write-version-xcconfig.sh"
VERSION=""
BUILD_NUMBER=""
TEAM_ID="${IOS_DEVELOPMENT_TEAM:-}"
PACKAGE_VERSION="$(cd "${ROOT_DIR}" && node -p "require('./package.json').version" 2>/dev/null || true)"
while [[ $# -gt 0 ]]; do
case "$1" in
--)
shift
;;
--version)
VERSION="${2:-}"
shift 2
;;
--build-number)
BUILD_NUMBER="${2:-}"
shift 2
@@ -51,8 +48,8 @@ while [[ $# -gt 0 ]]; do
esac
done
if [[ -z "${VERSION}" || -z "${BUILD_NUMBER}" ]]; then
echo "Missing required --version or --build-number." >&2
if [[ -z "${BUILD_NUMBER}" ]]; then
echo "Missing required --build-number." >&2
usage
exit 1
fi
@@ -64,10 +61,7 @@ fi
mkdir -p "${IOS_DIR}/build"
(
cd "${ROOT_DIR}"
node --import tsx scripts/ios-sync-version.ts \
--version "${VERSION}" \
--build-number "${BUILD_NUMBER}"
bash "${VERSION_HELPER}" --build-number "${BUILD_NUMBER}"
)
cat >"${BETA_XCCONFIG}" <<EOF
@@ -90,5 +84,5 @@ EOF
xcodegen generate
)
echo "Prepared iOS beta release: version=${VERSION} build=${BUILD_NUMBER} team=${TEAM_ID}"
echo "Prepared iOS beta release: version=${PACKAGE_VERSION} build=${BUILD_NUMBER} team=${TEAM_ID}"
echo "XCODE_XCCONFIG_FILE=${BETA_XCCONFIG}"

View File

@@ -4,13 +4,12 @@ set -euo pipefail
usage() {
cat <<'EOF'
Usage:
scripts/ios-beta-release.sh --version 2026.3.9-beta.1 [--build-number 7]
scripts/ios-beta-release.sh [--build-number 7]
Archives and uploads a beta-release IPA to TestFlight locally.
EOF
}
VERSION="${IOS_BETA_VERSION:-}"
BUILD_NUMBER="${IOS_BETA_BUILD_NUMBER:-}"
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
@@ -19,10 +18,6 @@ while [[ $# -gt 0 ]]; do
--)
shift
;;
--version)
VERSION="${2:-}"
shift 2
;;
--build-number)
BUILD_NUMBER="${2:-}"
shift 2
@@ -39,15 +34,7 @@ while [[ $# -gt 0 ]]; do
esac
done
if [[ -z "${VERSION}" ]]; then
echo "Missing required --version (or IOS_BETA_VERSION)." >&2
usage
exit 1
fi
(
cd "${ROOT_DIR}/apps/ios"
IOS_BETA_VERSION="${VERSION}" \
IOS_BETA_BUILD_NUMBER="${BUILD_NUMBER}" \
fastlane ios beta
IOS_BETA_BUILD_NUMBER="${BUILD_NUMBER}" fastlane ios beta
)

View File

@@ -1,97 +0,0 @@
#!/usr/bin/env -S node --import tsx
import { readFileSync, writeFileSync } from "node:fs";
import { resolve } from "node:path";
type CliOptions = {
buildNumber: string;
version: string;
};
function parseArgs(argv: string[]): CliOptions {
const options = new Map<string, string>();
for (let i = 0; i < argv.length; i += 1) {
const arg = argv[i];
if (!arg.startsWith("--")) {
continue;
}
const key = arg.slice(2);
const value = argv[i + 1];
if (!value || value.startsWith("--")) {
throw new Error(`Missing value for --${key}`);
}
options.set(key, value);
i += 1;
}
const version = options.get("version")?.trim();
const buildNumber = options.get("build-number")?.trim();
if (!version) {
throw new Error("Missing required --version");
}
if (!buildNumber) {
throw new Error("Missing required --build-number");
}
if (!/^[0-9]+$/.test(buildNumber)) {
throw new Error(`Invalid --build-number '${buildNumber}'; expected digits only.`);
}
return { buildNumber, version };
}
function toShortVersion(input: string): string {
const trimmed = input.trim().replace(/^v/, "");
const shortVersion = trimmed.replace(/([.-]?beta[.-]\d+)$/i, "");
if (!/^\d+\.\d+\.\d+$/.test(shortVersion)) {
throw new Error(
`Invalid --version '${input}'; expected CalVer like 2026.3.9 or 2026.3.9-beta.1.`,
);
}
return shortVersion;
}
function replaceAllExact(params: { content: string; pattern: RegExp; replacement: string }) {
const { content, pattern, replacement } = params;
const matches = [...content.matchAll(pattern)];
if (matches.length === 0) {
throw new Error(`Pattern not found: ${pattern}`);
}
return content.replace(pattern, replacement);
}
function main() {
const options = parseArgs(process.argv.slice(2));
const shortVersion = toShortVersion(options.version);
const projectPath = resolve("apps/ios/project.yml");
const original = readFileSync(projectPath, "utf8");
let updated = original;
updated = replaceAllExact({
content: updated,
pattern: /(CFBundleShortVersionString:\s*")[^"]+(")/g,
replacement: `$1${shortVersion}$2`,
});
updated = replaceAllExact({
content: updated,
pattern: /(CFBundleVersion:\s*")[^"]+(")/g,
replacement: `$1${options.buildNumber}$2`,
});
if (updated === original) {
console.log(`iOS version already set: short=${shortVersion} build=${options.buildNumber}`);
return;
}
writeFileSync(projectPath, updated);
console.log(`Updated iOS project version: short=${shortVersion} build=${options.buildNumber}`);
}
try {
main();
} catch (error) {
console.error(`ios-sync-version: ${(error as Error).message}`);
process.exit(1);
}

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
scripts/ios-write-version-xcconfig.sh [--build-number 7]
Writes apps/ios/build/Version.xcconfig from root package.json.version:
- OPENCLAW_GATEWAY_VERSION = exact package.json version
- OPENCLAW_MARKETING_VERSION = short iOS/App Store version
- OPENCLAW_BUILD_VERSION = explicit build number or local numeric fallback
EOF
}
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
IOS_DIR="${ROOT_DIR}/apps/ios"
VERSION_XCCONFIG="${IOS_DIR}/build/Version.xcconfig"
PACKAGE_VERSION="$(cd "${ROOT_DIR}" && node -p "require('./package.json').version" 2>/dev/null || true)"
BUILD_NUMBER=""
while [[ $# -gt 0 ]]; do
case "$1" in
--)
shift
;;
--build-number)
BUILD_NUMBER="${2:-}"
shift 2
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage
exit 1
;;
esac
done
PACKAGE_VERSION="$(printf '%s' "${PACKAGE_VERSION}" | tr -d '\n' | xargs)"
if [[ -z "${PACKAGE_VERSION}" ]]; then
echo "Unable to read package.json.version from ${ROOT_DIR}/package.json." >&2
exit 1
fi
if [[ "${PACKAGE_VERSION}" =~ ^([0-9]{4}\.[0-9]{1,2}\.[0-9]{1,2})([.-]?beta[.-][0-9]+)?$ ]]; then
MARKETING_VERSION="${BASH_REMATCH[1]}"
else
echo "Unsupported package.json.version '${PACKAGE_VERSION}'. Expected 2026.3.9 or 2026.3.9-beta.1." >&2
exit 1
fi
if [[ -z "${BUILD_NUMBER}" ]]; then
BUILD_NUMBER="$(cd "${ROOT_DIR}" && git rev-list --count HEAD 2>/dev/null || printf '0')"
fi
if [[ ! "${BUILD_NUMBER}" =~ ^[0-9]+$ ]]; then
echo "Invalid build number '${BUILD_NUMBER}'. Expected digits only." >&2
exit 1
fi
mkdir -p "${IOS_DIR}/build"
cat >"${VERSION_XCCONFIG}" <<EOF
// Auto-generated by scripts/ios-write-version-xcconfig.sh.
// Local version override; do not commit.
OPENCLAW_GATEWAY_VERSION = ${PACKAGE_VERSION}
OPENCLAW_MARKETING_VERSION = ${MARKETING_VERSION}
OPENCLAW_BUILD_VERSION = ${BUILD_NUMBER}
EOF
echo "Prepared iOS version settings: gateway=${PACKAGE_VERSION} marketing=${MARKETING_VERSION} build=${BUILD_NUMBER}"