-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
54 lines (48 loc) · 1.57 KB
/
action.js
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
import core from "@actions/core";
import exec from "@actions/exec";
import { execSync } from "child_process";
import process from "process";
try {
await exec.exec('git config --global user.name "ilo-nanpa[bot]"');
await exec.exec(
'git config --global user.email "174912985+ilo-nanpa[bot]@users.noreply.github.com"',
);
// clone and build nanpa
const pwd = process.cwd();
await exec.exec("git clone https://github.com/nbsp/nanpa.git ../nanpa");
process.chdir("../nanpa");
const tag = await exec.getExecOutput("git describe --abbrev=0");
await exec.exec(`git checkout ${tag.stdout}`);
execSync("curl https://sh.rustup.rs -sSf | sh -s -- -y");
core.addPath(`${process.env.HOME}/.cargo/bin`);
await exec.exec("cargo build --release");
core.addPath(`${process.cwd()}/target/release`);
process.chdir(pwd);
const pkgs = JSON.parse(core.getInput("packages"));
// run nanpa for each package
for (const pkg of pkgs) {
let pre, name;
let found = /(.*)@[\d\.]+(-([\w\d]+)\.\d+)?/.exec(pkg);
if (found) {
if (found[1].includes("/")) {
name = found[1].replace(/^[^/]*\//, "");
} else {
name = "";
}
if (found[3]) {
pre = `--pre ${found[3]}`;
} else {
pre = "";
}
}
await exec.exec(`nanpa changeset ${name} ${pre} -y`);
}
await exec.exec("git add .");
await exec.exec('git commit -m"nanpa: bump"');
for (const pkg of pkgs) {
await exec.exec(`git tag ${pkg} -m ${pkg}`);
}
await exec.exec("git push origin --follow-tags");
} catch (error) {
core.setFailed(error.message);
}