-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (58 loc) · 1.95 KB
/
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
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
const core = require("@actions/core");
const github = require("@actions/github");
const exec = require("@actions/exec");
const io = require("@actions/io");
const git = require("simple-git");
async function run() {
try {
let commitName;
await exec.exec("git log -1 --pretty=format:%s", [], {
listeners: {
stdout: (data) => {
commitName = data.toString().trim();
},
},
});
console.log(`\n\n📝 Commit name ➜ ${commitName}`);
// Get the previous tag
const gitRepo = git();
await exec.exec("git fetch --tags");
const tags = await gitRepo.tags();
console.log('Tags: ', tags);
console.log('Latest: ', tags.latest);
previousTag = tags.latest || "0.0.0";
console.log(`\n🏷️ Latest tag found ➜ ${tags.latest}`);
// Get the previous version and split it into major, minor, and patch
const previousVersion = previousTag.replace('v', '').split(".").map(Number);
let [major, minor, patch] = previousVersion;
// Determine the increment based on the commit name
let incrementType = "";
if (commitName.startsWith("patch:")) {
patch += 1; // Increment patch
incrementType = "patch";
} else if (commitName.startsWith("minor:")) {
minor += 1; // Increment minor and reset patch to 0
patch = 0;
incrementType = "minor";
} else if (commitName.startsWith("major:")) {
major += 1; // Increment major and reset minor and patch to 0
minor = 0;
patch = 0;
incrementType = "major";
}
const newVersion = `v${major}.${minor}.${patch}`;
if (incrementType !== "") {
console.log(`\n🚀 New version ➜ ${newVersion}`);
core.setOutput("newVersion", newVersion);
core.setOutput("makeRelease", true);
core.setOutput("commitName", commitName);
} else {
console.log(
`\n🛑 No New Version needed`
);
}
} catch (error) {
core.setFailed(error.message);
}
}
run();