deno: update update script to changed deno

+113 -118
+12 -22
pkgs/development/web/deno/update/common.ts
··· 3 3 } 4 4 5 5 const decode = (buffer: Uint8Array) => new TextDecoder("utf-8").decode(buffer); 6 - const run = async (command: string, args: string[]) => { 7 - const cmd = Deno.run( 8 - { cmd: [command, ...args], stdout: "piped", stderr: "piped" }, 9 - ); 6 + const decodeTrim = (b: Uint8Array) => decode(b).trimEnd(); 7 + export const run = async (command: string, args: string[]) => { 8 + const cmd = Deno.run({ 9 + cmd: [command, ...args], 10 + stdout: "piped", 11 + stderr: "piped", 12 + }); 10 13 if (!(await cmd.status()).success) { 11 - const error = await cmd.stderrOutput().then((b) => decode(b).trimEnd()); 14 + const error = await cmd.stderrOutput().then(decodeTrim); 12 15 // Known error we can ignore 13 16 if (error.includes("'allow-unsafe-native-code-during-evaluation'")) { 14 17 // Extract the target sha256 out of the error ··· 23 26 } 24 27 throw new Error(error); 25 28 } 26 - return cmd.output().then((b) => decode(b).trimEnd()); 29 + return cmd.output().then(decodeTrim); 27 30 }; 28 31 29 32 // Exports 30 33 export const versionRegExp = /\d+\.\d+\.\d+/; 31 - export const sha256RegExp = /[a-z0-9]{52}/; 32 - 33 - export async function commit( 34 - name: string, 35 - oldVer: string, 36 - newVer: string, 37 - files: string[], 38 - ) { 39 - await run("git", ["add", ...files]); 40 - await run("git", ["commit", "-m", `${name}: ${oldVer} -> ${newVer}`]); 41 - } 34 + export const sha256RegExp = /[a-z0-9]{52}|sha256-.{44}/; 42 35 43 36 export const getExistingVersion = async (filePath: string) => 44 - read(filePath).then((s) => 45 - s.match(genValueRegExp("version", versionRegExp))?.shift() || "" 37 + read(filePath).then( 38 + (s) => s.match(genValueRegExp("version", versionRegExp))?.shift() || "", 46 39 ); 47 40 48 41 export const getLatestVersion = (owner: string, repo: string) => ··· 57 50 58 51 export const logger = (name: string) => 59 52 (...a: any) => console.log(`[${name}]`, ...a); 60 - 61 - export const nixPrefetch = (args: string[]) => run("nix-prefetch", args); 62 - export const nixPrefetchURL = (args: string[]) => run("nix-prefetch-url", args); 63 53 64 54 export const read = Deno.readTextFile; 65 55 export const write = Deno.writeTextFile;
-79
pkgs/development/web/deno/update/deps.ts
··· 1 - import { 2 - getExistingVersion, 3 - genValueRegExp, 4 - logger, 5 - nixPrefetchURL, 6 - versionRegExp, 7 - write, 8 - } from "./common.ts"; 9 - 10 - const log = logger("deps"); 11 - 12 - export interface Architecture { 13 - nix: string; 14 - rust: string; 15 - } 16 - interface PrefetchResult { 17 - arch: Architecture; 18 - sha256: string; 19 - } 20 - 21 - const getRustyV8Version = async ( 22 - owner: string, 23 - repo: string, 24 - version: string, 25 - ) => 26 - fetch( 27 - `https://github.com/${owner}/${repo}/raw/${version}/core/Cargo.toml`, 28 - ) 29 - .then((res) => res.text()) 30 - .then((txt) => 31 - txt.match(genValueRegExp("rusty_v8", versionRegExp))?.shift() 32 - ); 33 - 34 - const archShaTasks = (version: string, arches: Architecture[]) => 35 - arches.map(async (arch: Architecture): Promise<PrefetchResult> => { 36 - log("Fetching:", arch.nix); 37 - const sha256 = await nixPrefetchURL( 38 - [`https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch.rust}.a`], 39 - ); 40 - log("Done: ", arch.nix); 41 - return { arch, sha256 }; 42 - }); 43 - 44 - const templateDeps = (version: string, deps: PrefetchResult[]) => 45 - `# auto-generated file -- DO NOT EDIT! 46 - {}: 47 - rec { 48 - librusty_v8 = { 49 - version = "${version}"; 50 - sha256s = { 51 - ${deps.map((d) => ` ${d.arch.nix} = "${d.sha256}";`).join("\n")} 52 - }; 53 - }; 54 - } 55 - `; 56 - 57 - export async function updateDeps( 58 - filePath: string, 59 - owner: string, 60 - repo: string, 61 - denoVersion: string, 62 - arches: Architecture[], 63 - ) { 64 - log("Starting deps update"); 65 - // 0.0.0 66 - const version = await getRustyV8Version(owner, repo, denoVersion); 67 - if (typeof version !== "string") { 68 - throw "no librusty_v8 version"; 69 - } 70 - log("librusty_v8 version:", version); 71 - const existingVersion = await getExistingVersion(filePath); 72 - if (version === existingVersion) { 73 - log("Version already matches latest, skipping..."); 74 - return; 75 - } 76 - const archShaResults = await Promise.all(archShaTasks(version, arches)); 77 - await write(filePath, templateDeps(version, archShaResults)); 78 - log("Finished deps update"); 79 - }
+92
pkgs/development/web/deno/update/librusty_v8.ts
··· 1 + import { 2 + genValueRegExp, 3 + getExistingVersion, 4 + logger, 5 + run, 6 + versionRegExp, 7 + write, 8 + } from "./common.ts"; 9 + 10 + const log = logger("librusty_v8"); 11 + 12 + export interface Architecture { 13 + nix: string; 14 + rust: string; 15 + } 16 + interface PrefetchResult { 17 + arch: Architecture; 18 + sha256: string; 19 + } 20 + 21 + const getLibrustyV8Version = async ( 22 + owner: string, 23 + repo: string, 24 + version: string, 25 + ) => 26 + fetch(`https://github.com/${owner}/${repo}/raw/${version}/core/Cargo.toml`) 27 + .then((res) => res.text()) 28 + .then((txt) => 29 + txt.match(genValueRegExp("rusty_v8", versionRegExp))?.shift() 30 + ); 31 + 32 + const fetchArchShaTasks = (version: string, arches: Architecture[]) => 33 + arches.map( 34 + async (arch: Architecture): Promise<PrefetchResult> => { 35 + log("Fetching:", arch.nix); 36 + const sha256 = await run("nix-prefetch", [ 37 + ` 38 + { fetchurl }: 39 + fetchurl { 40 + url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${arch.rust}.a"; 41 + } 42 + `, 43 + ]); 44 + log("Done: ", arch.nix); 45 + return { arch, sha256 }; 46 + }, 47 + ); 48 + 49 + const templateDeps = (version: string, deps: PrefetchResult[]) => 50 + `# auto-generated file -- DO NOT EDIT! 51 + { rust, stdenv, fetchurl }: 52 + 53 + let 54 + arch = rust.toRustTarget stdenv.hostPlatform; 55 + fetch_librusty_v8 = args: fetchurl { 56 + name = "librusty_v8-\${args.version}"; 57 + url = "https://github.com/denoland/rusty_v8/releases/download/v\${args.version}/librusty_v8_release_\${arch}.a"; 58 + sha256 = args.shas.\${stdenv.hostPlatform.system}; 59 + meta = { inherit (args) version; }; 60 + }; 61 + in 62 + fetch_librusty_v8 { 63 + version = "${version}"; 64 + shas = { 65 + ${deps.map(({ arch, sha256 }) => ` ${arch.nix} = "${sha256}";`).join("\n")} 66 + }; 67 + } 68 + `; 69 + 70 + export async function updateLibrustyV8( 71 + filePath: string, 72 + owner: string, 73 + repo: string, 74 + denoVersion: string, 75 + arches: Architecture[], 76 + ) { 77 + log("Starting librusty_v8 update"); 78 + // 0.0.0 79 + const version = await getLibrustyV8Version(owner, repo, denoVersion); 80 + if (typeof version !== "string") { 81 + throw "no librusty_v8 version"; 82 + } 83 + log("librusty_v8 version:", version); 84 + const existingVersion = await getExistingVersion(filePath); 85 + if (version === existingVersion) { 86 + log("Version already matches latest, skipping..."); 87 + return; 88 + } 89 + const archShaResults = await Promise.all(fetchArchShaTasks(version, arches)); 90 + await write(filePath, templateDeps(version, archShaResults)); 91 + log("Finished deps update"); 92 + }
+5 -5
pkgs/development/web/deno/update/src.ts
··· 1 1 import { 2 2 genValueRegExp, 3 3 logger, 4 - nixPrefetch, 5 4 read, 5 + run, 6 6 sha256RegExp, 7 7 versionRegExp, 8 8 write, ··· 16 16 const log = logger("src"); 17 17 18 18 const prefetchSha256 = (nixpkgs: string, version: string) => 19 - nixPrefetch(["-f", nixpkgs, "deno.src", "--rev", version]); 19 + run("nix-prefetch", ["-f", nixpkgs, "deno.src", "--rev", version]); 20 20 const prefetchCargoSha256 = (nixpkgs: string) => 21 - nixPrefetch( 22 - [`{ sha256 }: (import ${nixpkgs} {}).deno.cargoDeps.overrideAttrs (_: { outputHash = sha256; })`], 21 + run( 22 + "nix-prefetch", 23 + [`{ sha256 }: (import ${nixpkgs} {}).deno.cargoDeps.overrideAttrs (_: { inherit sha256; })`], 23 24 ); 24 25 25 26 const replace = (str: string, replacers: Replacer[]) => ··· 53 54 [ 54 55 genVerReplacer("version", trimVersion), 55 56 genShaReplacer("sha256", sha256), 56 - genShaReplacer("cargoSha256", ""), // Empty ready for prefetchCargoSha256 57 57 ], 58 58 ); 59 59 log("Fetching cargoSha256 for:", sha256);
+4 -12
pkgs/development/web/deno/update/update.ts
··· 2 2 /* 3 3 #!nix-shell -i "deno run --allow-net --allow-run --allow-read --allow-write" -p deno git nix-prefetch 4 4 */ 5 - import { 6 - commit, 7 - getExistingVersion, 8 - getLatestVersion, 9 - logger, 10 - } from "./common.ts"; 11 - import { Architecture, updateDeps } from "./deps.ts"; 5 + import { getExistingVersion, getLatestVersion, logger } from "./common.ts"; 6 + import { Architecture, updateLibrustyV8 } from "./librusty_v8.ts"; 12 7 import { updateSrc } from "./src.ts"; 13 8 14 9 const log = logger("update"); ··· 19 14 const repo = "deno"; 20 15 const denoDir = `${nixpkgs}/pkgs/development/web/${repo}`; 21 16 const src = `${denoDir}/default.nix`; 22 - const deps = `${denoDir}/deps.nix`; 17 + const librusty_v8 = `${denoDir}/librusty_v8.nix`; 23 18 const architectures: Architecture[] = [ 24 19 { nix: "x86_64-linux", rust: "x86_64-unknown-linux-gnu" }, 25 20 { nix: "aarch64-linux", rust: "aarch64-unknown-linux-gnu" }, ··· 42 37 43 38 const tasks = [ 44 39 updateSrc(src, nixpkgs, version), 45 - updateDeps(deps, owner, repo, version, architectures), 40 + updateLibrustyV8(librusty_v8, owner, repo, version, architectures), 46 41 ]; 47 42 await Promise.all(tasks); 48 43 log("Updating deno complete"); 49 - log("Commiting"); 50 - await commit(repo, existingVersion, trimVersion, [src, deps]); 51 - log("Done");