GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — t3code/scripts/resolve-nightly-release.ts at main · Kahitar/t3code Expand file tree/ Copy pathresolve-nightly-release.tsMore file actions 222 lines (204 loc) · 6.83 KB / Copy pathresolve-nightly-release.tsFile metadata and controls222 lines (204 loc) · 6.83 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 #!/usr/bin/env node import * as NodeRuntime from "@effect/platform-node/NodeRuntime"; import * as NodeServices from "@effect/platform-node/NodeServices"; import * as Console from "effect/Console"; import * as Config from "effect/Config"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; import { Command, Flag } from "effect/unstable/cli"; export interface NightlyReleaseMetadata { readonly baseVersion: string; readonly version: string; readonly tag: string; readonly name: string; readonly shortSha: string; } const DateSchema = Schema.String.check(Schema.isPattern(/^\d{8}$/)); const RunNumberSchema = Schema.FiniteFromString.check( Schema.isInt(), Schema.isGreaterThanOrEqualTo(1), ); const ShaSchema = Schema.String.check(Schema.isPattern(/^[0-9a-f]{7,40}$/i)); const DesktopPackageJsonSchema = Schema.Struct({ version: Schema.NonEmptyString, }); export class InvalidDesktopPackageVersionError extends Schema.TaggedErrorClass<InvalidDesktopPackageVersionError>()( "InvalidDesktopPackageVersionError", { version: Schema.String, }, ) { override get message(): string { return `Invalid desktop package version '${this.version}'.`; } } export class NightlyReleaseDesktopPackageError extends Schema.TaggedErrorClass<NightlyReleaseDesktopPackageError>()( "NightlyReleaseDesktopPackageError", { operation: Schema.Literals(["read", "decode"]), packageJsonPath: Schema.String, cause: Schema.Defect(), }, ) { override get message(): string { return `Failed to ${this.operation} desktop package metadata at ${this.packageJsonPath}.`; } } export class NightlyReleaseGitHubOutputConfigError extends Schema.TaggedErrorClass<NightlyReleaseGitHubOutputConfigError>()( "NightlyReleaseGitHubOutputConfigError", { cause: Schema.Defect(), }, ) { override get message(): string { return "Failed to resolve the GITHUB_OUTPUT path for nightly release metadata."; } } export class NightlyReleaseGitHubOutputAppendError extends Schema.TaggedErrorClass<NightlyReleaseGitHubOutputAppendError>()( "NightlyReleaseGitHubOutputAppendError", { outputPath: Schema.String, cause: Schema.Defect(), }, ) { override get message(): string { return `Failed to append nightly release metadata to ${this.outputPath}.`; } } const RepoRoot = Effect.service(Path.Path).pipe( Effect.flatMap((path) => path.fromFileUrl(new URL("..", import.meta.url))), ); const decodeDesktopPackageJson = Schema.decodeUnknownEffect( Schema.fromJsonString(DesktopPackageJsonSchema), ); export const resolveNightlyBaseVersion = (version: string) => version.replace(/[-+].*$/, ""); export const resolveNightlyTargetVersion = (version: string) => { const stableCore = resolveNightlyBaseVersion(version); const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(stableCore); if (!match) { return Effect.fail(new InvalidDesktopPackageVersionError({ version })); } const [, major, minor, patch] = match; return Effect.succeed(`${major}.${minor}.${Number(patch) + 1}`); }; export const resolveNightlyReleaseMetadata = ( baseVersion: string, date: string, runNumber: number, sha: string, ) => { const shortSha = sha.slice(0, 12); const version = `${baseVersion}-nightly.${date}.${runNumber}`; return { baseVersion, version, tag: `v${version}`, name: `T3 Code Nightly ${version} (${shortSha})`, shortSha, }; }; export const readDesktopBaseVersion = Effect.fn("readDesktopBaseVersion")(function* ( rootDir: string | undefined, ) { const fs = yield* FileSystem.FileSystem; const path = yield* Path.Path; const workspaceRoot = rootDir ? path.resolve(rootDir) : yield* RepoRoot; const packageJsonPath = path.join(workspaceRoot, "apps/desktop/package.json"); const packageJsonSource = yield* fs.readFileString(packageJsonPath).pipe( Effect.mapError( (cause) => new NightlyReleaseDesktopPackageError({ operation: "read", packageJsonPath, cause, }), ), ); const packageJson = yield* decodeDesktopPackageJson(packageJsonSource).pipe( Effect.mapError( (cause) => new NightlyReleaseDesktopPackageError({ operation: "decode", packageJsonPath, cause, }), ), ); return yield* resolveNightlyTargetVersion(packageJson.version); }); export const writeNightlyReleaseOutput = Effect.fn("writeNightlyReleaseOutput")(function* ( metadata: NightlyReleaseMetadata, writeGithubOutput: boolean, ) { const fs = yield* FileSystem.FileSystem; const entries = [ ["base_version", metadata.baseVersion], ["version", metadata.version], ["tag", metadata.tag], ["name", metadata.name], ["short_sha", metadata.shortSha], ] as const; if (writeGithubOutput) { const githubOutputPath = yield* Config.nonEmptyString("GITHUB_OUTPUT").pipe( Effect.mapError( (cause) => new NightlyReleaseGitHubOutputConfigError({ cause, }), ), ); const serialized = entries.map(([key, value]) => `${key}=${value}\n`).join(""); yield* fs.writeFileString(githubOutputPath, serialized, { flag: "a" }).pipe( Effect.mapError( (cause) => new NightlyReleaseGitHubOutputAppendError({ outputPath: githubOutputPath, cause, }), ), ); } else { for (const [key, value] of entries) { yield* Console.log(`${key}=${value}`); } } }); const command = Command.make( "resolve-nightly-release", { date: Flag.string("date").pipe( Flag.withSchema(DateSchema), Flag.withDescription("Nightly build date in YYYYMMDD."), ), runNumber: Flag.string("run-number").pipe( Flag.withSchema(RunNumberSchema), Flag.withDescription("GitHub Actions run number."), ), sha: Flag.string("sha").pipe( Flag.withSchema(ShaSchema), Flag.withDescription("Commit sha for the nightly build."), ), githubOutput: Flag.boolean("github-output").pipe( Flag.withDescription("Write values to GITHUB_OUTPUT instead of stdout."), Flag.withDefault(false), ), root: Flag.string("root").pipe( Flag.withDescription("Workspace root used to resolve apps/desktop/package.json."), Flag.optional, ), }, ({ date, runNumber, sha, githubOutput, root }) => readDesktopBaseVersion(Option.getOrUndefined(root)).pipe( Effect.map((baseVersion) => resolveNightlyReleaseMetadata(baseVersion, date, runNumber, sha)), Effect.flatMap((metadata) => writeNightlyReleaseOutput(metadata, githubOutput)), ), ).pipe(Command.withDescription("Resolve nightly release version metadata.")); if (import.meta.main) { Command.run(command, { version: "0.0.0" }).pipe( Effect.provide(NodeServices.layer), NodeRuntime.runMain, ); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |