-
-
Notifications
You must be signed in to change notification settings - Fork 49
/
main.js
40 lines (34 loc) · 1.78 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
37
38
39
40
const { exec } = require('child_process');
const fs = require('fs');
const tagPrefix = `${process.env.INPUT_PREFIX || ''}*`;
const workingDirectory = process.env.INPUT_WORKINGDIRECTORY || null;
console.log('\x1b[33m%s\x1b[0m', 'Working directory: ', workingDirectory || '');
exec(`git for-each-ref --sort=-creatordate --count 1 --format="%(refname:short)" "refs/tags/${tagPrefix}"`, {cwd: workingDirectory}, (err, tag, stderr) => {
tag = tag.trim();
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any tags because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
} else if (tag === "") {
let timestamp = Math.floor(new Date().getTime() / 1000);
console.log('\x1b[33m%s\x1b[0m', 'Falling back to default tag');
console.log('\x1b[32m%s\x1b[0m', `Found tag: ${process.env.INPUT_FALLBACK}`);
console.log('\x1b[32m%s\x1b[0m', `Found timestamp: ${timestamp}`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${process.env.INPUT_FALLBACK}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `timestamp=${timestamp}\n`);
process.exit(0);
}
exec(`git log -1 --format=%at ${tag}`, {cwd: workingDirectory}, (err, timestamp, stderr) => {
if (err) {
console.log('\x1b[33m%s\x1b[0m', 'Could not find any timestamp because: ');
console.log('\x1b[31m%s\x1b[0m', stderr);
process.exit(1);
}
timestamp = timestamp.trim();
console.log('\x1b[32m%s\x1b[0m', `Found tag: ${tag}`);
console.log('\x1b[32m%s\x1b[0m', `Found timestamp: ${timestamp}`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `tag=${tag}\n`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `timestamp=${timestamp}\n`);
process.exit(0);
});
});