forked from WyriHaximus/github-action-get-previous-tag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
36 lines (34 loc) · 1.52 KB
/
main.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
const { exec } = require('child_process');
const core = require('@actions/core');
exec(`cd ${core.getInput('path')} && git fetch --tags --all`, (err, res, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', `Couldn't fetch`);
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
}
exec(`cd ${core.getInput('path')} && git rev-list --tags --max-count=1`, (err, rev, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any revisions because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
}
rev = rev.trim()
exec(`cd ${core.getInput('path')} && git describe --tags ${rev}`, (err, tag, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', rev)
console.log('\x1b[33m%s\x1b[0m', 'Could not find any tags because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
}
tag = tag.trim()
exec(`cd ${core.getInput('path')} && git describe --abbrev=0 HEAD^`, (err, pastTag, stderr) => {
pastTag = pastTag.trim()
console.log('\x1b[32m%s\x1b[0m', `Found tag: ${tag}`);
console.log('\x1b[32m%s\x1b[0m', `Found past tag: ${pastTag}`);
console.log(`::set-output name=tag::${tag}`);
console.log(`::set-output name=pastTag::${pastTag}`);
process.exit(0);
});
});
});
});