forked from Deep-Symmetry/github-version-action
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
43 lines (39 loc) · 1.57 KB
/
Copy pathindex.js
File metadata and controls
43 lines (39 loc) · 1.57 KB
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
const core = require('@actions/core');
const exec = require('@actions/exec');
/** Returns true if the tag name supplied looks like it encodes a version. */
const isVersion = (tag) => /^(v(ersion)?)?-?\d+(\.\d+)*(-snapshot)?/i.test(tag);
try {
const varName = core.getInput('var-name', { required: true });
const tagVarName = core.getInput('tag-var-name');
const mvnVarName = core.getInput('mvn-var-name');
let result = '';
const options = {};
options.listeners = {
stdout: (data) => {
result += data.toString();
}
};
(async () => {
// Fetch all the tags
await exec.exec('git', ['fetch', '--depth=1', 'origin', '+refs/tags/*:refs/tags/*']);
// Fetch all the history
await exec.exec('git', ['fetch', '--prune', '--unshallow']);
// Now list all the tags on the current branch in reverse chronological order, collecting the output.
await exec.exec('git', ['tag', '--sort=-taggerdate', '--merged'], options);
const lines = result.split("\n");
const rawVersion = lines.find(isVersion);
const mvnVersion = rawVersion.replace(/^v(ersion)?-?/i, "");
const version = mvnVersion.replace(/snapshot$/i, "Preview");
core.exportVariable(varName, version);
if (!!tagVarName) {
core.exportVariable(tagVarName, rawVersion);
}
if (!!mvnVarName) {
core.exportVariable(mvnVarName, mvnVersion);
}
})().catch(e => {
core.setFailed(e.message);
});
} catch (error) {
core.setFailed(error.message);
}