-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbump-crates.ts
97 lines (82 loc) · 3.13 KB
/
bump-crates.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { join } from "path";
import { rm } from "fs/promises";
import * as core from "@actions/core";
import { sh } from "./command";
import * as cargo from "./cargo";
import { gitEnv } from "./config";
export type Input = {
version: string;
liveRun: boolean;
branch: string;
repo: string;
path?: string;
githubToken: string;
bumpDepsRegExp?: RegExp;
bumpDepsVersion?: string;
bumpDepsBranch?: string;
};
export function setup(): Input {
const version = core.getInput("version", { required: true });
const liveRun = core.getBooleanInput("live-run", { required: true });
const branch = core.getInput("branch", { required: true });
const repo = core.getInput("repo", { required: true });
const path = core.getInput("path");
const githubToken = core.getInput("github-token", { required: true });
const bumpDepsPattern = core.getInput("bump-deps-pattern");
const bumpDepsVersion = core.getInput("bump-deps-version");
const bumpDepsBranch = core.getInput("bump-deps-branch");
return {
version,
liveRun,
branch,
repo,
path: path === "" ? undefined : path,
githubToken,
bumpDepsRegExp: bumpDepsPattern === "" ? undefined : new RegExp(bumpDepsPattern),
bumpDepsVersion: bumpDepsVersion === "" ? undefined : bumpDepsVersion,
bumpDepsBranch: bumpDepsBranch === "" ? undefined : bumpDepsBranch,
};
}
export async function main(input: Input) {
try {
const repo = input.repo.split("/")[1];
const workspace = input.path === undefined ? repo : join(repo, input.path);
const remote = `https://${input.githubToken}@github.com/${input.repo}.git`;
sh(`git clone --recursive --single-branch --branch ${input.branch} ${remote}`);
sh(`ls ${workspace}`);
await cargo.bump(workspace, input.version);
sh("git add .", { cwd: repo });
sh(`git commit --message 'chore: Bump version to \`${input.version}\`'`, { cwd: repo, env: gitEnv });
if (input.bumpDepsRegExp != undefined) {
await cargo.bumpDependencies(workspace, input.bumpDepsRegExp, input.bumpDepsVersion, input.bumpDepsBranch);
sh("git add .", { cwd: repo });
sh(`git commit --message 'chore: Bump ${input.bumpDepsRegExp} dependencies to \`${input.bumpDepsVersion}\`'`, {
cwd: repo,
env: gitEnv,
check: false,
});
sh("cargo check", { cwd: repo });
sh("git commit Cargo.lock --message 'chore: Update Cargo lockfile'", {
cwd: repo,
env: gitEnv,
check: false,
});
}
sh(`git push --force ${remote} ${input.branch}`, { cwd: repo });
if (input.liveRun) {
sh(`git tag --force ${input.version} --message v${input.version}`, { cwd: repo, env: gitEnv });
sh(`git push --force ${remote} ${input.version}`, { cwd: repo });
}
sh("git log -10", { cwd: repo });
sh("git show-ref --tags", { cwd: repo });
await cleanup(input);
} catch (error) {
await cleanup(input);
if (error instanceof Error) core.setFailed(error.message);
}
}
export async function cleanup(input: Input) {
const repo = input.repo.split("/")[1];
core.info(`Deleting repository clone ${repo}`);
await rm(repo, { recursive: true, force: true });
}