Files
t3code/scripts/lib/android-apk-release.ts
bonzi c44c38f096
Fork Android APK / release (push) Has been cancelled
feat(hermes): add native Hermes workspace
2026-09-19 01:39:31 +00:00

35 lines
1.2 KiB
TypeScript

export const DEFAULT_ANDROID_APK_REPOSITORY_URL = "https://git.molberg.cloud/alex/t3code";
export function parseAndroidApkReleaseTag(tag: string): number {
const match = /^apk-([1-9]\d*)$/.exec(tag);
const versionCode = match ? Number(match[1]) : NaN;
if (!Number.isSafeInteger(versionCode) || versionCode > 2_100_000_000) {
throw new Error("APK release tags must be apk-<versionCode>, from 1 to 2100000000.");
}
return versionCode;
}
export function resolveAndroidApkRepository(repositoryUrl: string) {
const url = new URL(repositoryUrl);
const path = url.pathname.replace(/\/+$/, "").replace(/\.git$/, "");
const parts = path.split("/").filter(Boolean);
if (
url.protocol !== "https:" ||
url.username ||
url.password ||
url.search ||
url.hash ||
parts.length < 2
)
throw new Error(
"APK repository must be an HTTPS repository URL without credentials or query parameters.",
);
const repository = parts.slice(-2).join("/");
const basePath = parts.slice(0, -2).join("/");
const serverUrl = `${url.origin}${basePath ? `/${basePath}` : ""}`;
return {
releasesUrl: `${serverUrl}/${repository}/releases`,
apiUrl: `${serverUrl}/api/v1/repos/${repository}/releases`,
};
}