Skip to content

Commit

Permalink
chore: release scripts should update Cargo.lock file when bumping ver…
Browse files Browse the repository at this point in the history
…sions (#11879)
  • Loading branch information
dsherret authored Aug 30, 2021
1 parent 0aa6b1e commit ca75752
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 14 deletions.
2 changes: 2 additions & 0 deletions tools/release/01_bump_dependency_crate_versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ const workspace = await DenoWorkspace.load();
for (const crate of workspace.getDependencyCrates()) {
await crate.increment("minor");
}

await workspace.updateLockFile();
1 change: 1 addition & 0 deletions tools/release/03_bump_cli_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const originalVersion = cliCrate.version;

// increment the version
await cliCrate.increment(getVersionIncrement());
await workspace.updateLockFile();

// output the Releases.md markdown text
console.log(
Expand Down
30 changes: 27 additions & 3 deletions tools/release/helpers/cargo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,34 @@ export async function getMetadata(directory: string) {
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({
cwd: directory,
cmd: ["cargo", "publish"],
cwd: params.directory,
cmd: ["cargo", ...params.args],
stderr: "inherit",
stdout: "inherit",
});
Expand Down
35 changes: 24 additions & 11 deletions tools/release/helpers/deno_workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

import * as path from "https://deno.land/[email protected]/path/mod.ts";
import * as semver from "https://deno.land/x/[email protected]/mod.ts";
import {
CargoMetadata,
CargoPackageMetadata,
getMetadata,
publishCrate,
} from "./cargo.ts";
import * as cargo from "./cargo.ts";
import { getCratesIoMetadata } from "./crates_io.ts";
import { withRetries } from "./helpers.ts";

Expand All @@ -21,10 +16,12 @@ export class 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 = [];
for (const memberId of metadata.workspace_members) {
const pkg = metadata.packages.find((pkg) => pkg.id === memberId);
Expand Down Expand Up @@ -82,14 +79,22 @@ export class DenoWorkspace {
}
return crate;
}

build() {
return cargo.build(DenoWorkspace.rootDirPath);
}

updateLockFile() {
return cargo.check(DenoWorkspace.rootDirPath);
}
}

export class DenoWorkspaceCrate {
#workspace: DenoWorkspace;
#pkg: CargoPackageMetadata;
#pkg: cargo.CargoPackageMetadata;
#isUpdatingManifest = false;

constructor(workspace: DenoWorkspace, pkg: CargoPackageMetadata) {
constructor(workspace: DenoWorkspace, pkg: cargo.CargoPackageMetadata) {
this.#workspace = workspace;
this.#pkg = pkg;
}
Expand Down Expand Up @@ -141,14 +146,22 @@ export class DenoWorkspaceCrate {
// times before failing hard.
return await withRetries({
action: async () => {
await publishCrate(this.directoryPath);
await cargo.publishCrate(this.directoryPath);
return true;
},
retryCount: 3,
retryDelaySeconds: 10,
});
}

build() {
return cargo.build(this.directoryPath);
}

updateLockFile() {
return cargo.check(this.directoryPath);
}

increment(part: "major" | "minor" | "patch") {
const newVersion = semver.parse(this.version)!.inc(part).toString();
return this.setVersion(newVersion);
Expand Down

0 comments on commit ca75752

Please sign in to comment.