deno.land / x / deno@v1.28.2 / tools / release / 01_bump_crate_versions.ts
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114#!/usr/bin/env -S deno run -A --lock=tools/deno.lock.json// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { DenoWorkspace } from "./deno_workspace.ts";import { $, GitLogOutput, semver } from "./deps.ts";
const workspace = await DenoWorkspace.load();const repo = workspace.repo;const cliCrate = workspace.getCliCrate();const originalCliVersion = cliCrate.version;
// increment the cli versionif (Deno.args.some((a) => a === "--patch")) { await cliCrate.increment("patch");} else if (Deno.args.some((a) => a === "--minor")) { await cliCrate.increment("minor");} else if (Deno.args.some((a) => a === "--major")) { await cliCrate.increment("major");} else { await cliCrate.promptAndIncrement();}
// increment the dependency crate versionsfor (const crate of workspace.getCliDependencyCrates()) { await crate.increment("minor");}
// update the std version used in the code$.logStep("Updating std version...");await updateStdVersion();
// update the lock fileawait workspace.getCliCrate().cargoUpdate("--workspace");
// try to update the Releases.md markdown texttry { $.logStep("Updating Releases.md..."); await updateReleasesMd();} catch (err) { $.log(err); $.logError( "Error Updating Releases.md failed. Please manually run " + "`git log --oneline VERSION_FROM..VERSION_TO` and " + "use the output to update Releases.md", );}
async function updateReleasesMd() { const gitLog = await getGitLog(); const releasesMdFile = workspace.getReleasesMdFile(); releasesMdFile.updateWithGitLog({ version: cliCrate.version, gitLog, });
await workspace.runFormatter();}
async function getGitLog() { const originalVersion = semver.parse(originalCliVersion)!; const originalVersionTag = `v${originalCliVersion}`; // fetch the upstream tags await repo.gitFetchTags("upstream");
// make the repo unshallow so we can fetch the latest tag if (await repo.gitIsShallow()) { await repo.gitFetchUnshallow("origin"); }
// this means we're on the patch release const latestTag = await repo.gitLatestTag(); if (latestTag === originalVersionTag) { return await repo.getGitLogFromTags( "upstream", originalVersionTag, undefined, ); } else { // otherwise, get the history of the last release await repo.gitFetchHistory("upstream"); const lastMinorHistory = await repo.getGitLogFromTags( "upstream", `v${originalVersion.major}.${originalVersion.minor}.0`, originalVersionTag, ); const currentHistory = await repo.getGitLogFromTags( "upstream", latestTag, undefined, ); const lastMinorMessages = new Set( lastMinorHistory.lines.map((r) => r.message), ); return new GitLogOutput( currentHistory.lines.filter((l) => !lastMinorMessages.has(l.message)), ); }}
async function updateStdVersion() { const compatFilePath = $.path.join(cliCrate.folderPath, "deno_std.rs"); const text = await Deno.readTextFile(compatFilePath); const versionRe = /std@([0-9]+\.[0-9]+\.[0-9]+)/; const stdVersionText = versionRe.exec(text)?.[1]; if (stdVersionText == null) { throw new Error(`Could not find the deno_std version in ${compatFilePath}`); } const stdVersion = semver.parse(stdVersionText)!; const newStdVersion = stdVersion.inc("minor"); await Deno.writeTextFile( compatFilePath, text.replace(versionRe, `std@${newStdVersion}`), );}
Version Info