forked from medallyon/update-package-version-on-release
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
38 lines (30 loc) · 985 Bytes
/
index.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
const core = require("@actions/core")
, github = require("@actions/github")
, fs = require("fs-extra");
// most @actions toolkit packages have async methods
async function run()
{
try
{
const payload = github.context.payload;
let tag = payload.release.tag_name;
if (tag.startsWith("v"))
tag = tag.replace("v", "");
if (!/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/gm.test(tag))
{
throw new Error("Release Tag does not match semantic versioning.");
}
const pkg = await fs.readJson("./package.json")
, originalVersion = pkg.version;
pkg.version = tag;
await fs.outputJson("./package.json", pkg, {
spaces: 2
});
core.info(`Modified version number in package.json from ${originalVersion.replace("v", "")} to ${pkg.version}`);
}
catch (error)
{
core.setFailed(error.message);
}
}
run();