summaryrefslogtreecommitdiff
path: root/tools/release/helpers/cargo.ts
blob: 619d7a0f7c983d0b92e1c51b1cb4fa19843aab66 (plain)
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
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

import { runCommand } from "./helpers.ts";

export interface CargoMetadata {
  packages: CargoPackageMetadata[];
  /** Identifiers in the `packages` array of the workspace members. */
  "workspace_members": string[];
  /** The absolute workspace root directory path. */
  "workspace_root": string;
}

export interface CargoPackageMetadata {
  id: string;
  name: string;
  version: string;
  dependencies: CargoDependencyMetadata[];
  /** Path to Cargo.toml */
  "manifest_path": string;
}

export interface CargoDependencyMetadata {
  name: string;
  /** Version requrement (ex. ^0.1.0) */
  req: string;
}

export async function getMetadata(directory: string) {
  const result = await runCommand({
    cwd: directory,
    cmd: ["cargo", "metadata", "--format-version", "1"],
  });
  return JSON.parse(result!) as CargoMetadata;
}

export async function publishCrate(directory: string) {
  const p = Deno.run({
    cwd: directory,
    cmd: ["cargo", "publish"],
    stderr: "inherit",
    stdout: "inherit",
  });

  const status = await p.status();
  if (!status.success) {
    throw new Error("Failed");
  }
}