1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

chore: release scripts should update Cargo.lock file when bumping versions (#11879)

This commit is contained in:
David Sherret 2021-08-30 13:35:48 -04:00 committed by GitHub
parent 0aa6b1e79f
commit ca75752e5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 14 deletions

View file

@ -7,3 +7,5 @@ const workspace = await DenoWorkspace.load();
for (const crate of workspace.getDependencyCrates()) { for (const crate of workspace.getDependencyCrates()) {
await crate.increment("minor"); await crate.increment("minor");
} }
await workspace.updateLockFile();

View file

@ -13,6 +13,7 @@ const originalVersion = cliCrate.version;
// increment the version // increment the version
await cliCrate.increment(getVersionIncrement()); await cliCrate.increment(getVersionIncrement());
await workspace.updateLockFile();
// output the Releases.md markdown text // output the Releases.md markdown text
console.log( console.log(

View file

@ -33,10 +33,34 @@ export async function getMetadata(directory: string) {
return JSON.parse(result!) as CargoMetadata; return JSON.parse(result!) as CargoMetadata;
} }
export async function publishCrate(directory: string) { export function publishCrate(directory: string) {
return runCargoSubCommand({
directory,
args: ["publish"],
});
}
export function build(directory: string) {
return runCargoSubCommand({
directory,
args: ["build", "-vv"],
});
}
export function check(directory: string) {
return runCargoSubCommand({
directory,
args: ["check"],
});
}
async function runCargoSubCommand(params: {
args: string[];
directory: string;
}) {
const p = Deno.run({ const p = Deno.run({
cwd: directory, cwd: params.directory,
cmd: ["cargo", "publish"], cmd: ["cargo", ...params.args],
stderr: "inherit", stderr: "inherit",
stdout: "inherit", stdout: "inherit",
}); });

View file

@ -2,12 +2,7 @@
import * as path from "https://deno.land/std@0.105.0/path/mod.ts"; import * as path from "https://deno.land/std@0.105.0/path/mod.ts";
import * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts"; import * as semver from "https://deno.land/x/semver@v1.4.0/mod.ts";
import { import * as cargo from "./cargo.ts";
CargoMetadata,
CargoPackageMetadata,
getMetadata,
publishCrate,
} from "./cargo.ts";
import { getCratesIoMetadata } from "./crates_io.ts"; import { getCratesIoMetadata } from "./crates_io.ts";
import { withRetries } from "./helpers.ts"; import { withRetries } from "./helpers.ts";
@ -21,10 +16,12 @@ export class DenoWorkspace {
} }
static async load(): Promise<DenoWorkspace> { static async load(): Promise<DenoWorkspace> {
return new DenoWorkspace(await getMetadata(DenoWorkspace.rootDirPath)); return new DenoWorkspace(
await cargo.getMetadata(DenoWorkspace.rootDirPath),
);
} }
private constructor(metadata: CargoMetadata) { private constructor(metadata: cargo.CargoMetadata) {
const crates = []; const crates = [];
for (const memberId of metadata.workspace_members) { for (const memberId of metadata.workspace_members) {
const pkg = metadata.packages.find((pkg) => pkg.id === memberId); const pkg = metadata.packages.find((pkg) => pkg.id === memberId);
@ -82,14 +79,22 @@ export class DenoWorkspace {
} }
return crate; return crate;
} }
build() {
return cargo.build(DenoWorkspace.rootDirPath);
}
updateLockFile() {
return cargo.check(DenoWorkspace.rootDirPath);
}
} }
export class DenoWorkspaceCrate { export class DenoWorkspaceCrate {
#workspace: DenoWorkspace; #workspace: DenoWorkspace;
#pkg: CargoPackageMetadata; #pkg: cargo.CargoPackageMetadata;
#isUpdatingManifest = false; #isUpdatingManifest = false;
constructor(workspace: DenoWorkspace, pkg: CargoPackageMetadata) { constructor(workspace: DenoWorkspace, pkg: cargo.CargoPackageMetadata) {
this.#workspace = workspace; this.#workspace = workspace;
this.#pkg = pkg; this.#pkg = pkg;
} }
@ -141,7 +146,7 @@ export class DenoWorkspaceCrate {
// times before failing hard. // times before failing hard.
return await withRetries({ return await withRetries({
action: async () => { action: async () => {
await publishCrate(this.directoryPath); await cargo.publishCrate(this.directoryPath);
return true; return true;
}, },
retryCount: 3, retryCount: 3,
@ -149,6 +154,14 @@ export class DenoWorkspaceCrate {
}); });
} }
build() {
return cargo.build(this.directoryPath);
}
updateLockFile() {
return cargo.check(this.directoryPath);
}
increment(part: "major" | "minor" | "patch") { increment(part: "major" | "minor" | "patch") {
const newVersion = semver.parse(this.version)!.inc(part).toString(); const newVersion = semver.parse(this.version)!.inc(part).toString();
return this.setVersion(newVersion); return this.setVersion(newVersion);