-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathtag-published-packages.mjs
More file actions
70 lines (57 loc) · 1.77 KB
/
tag-published-packages.mjs
File metadata and controls
70 lines (57 loc) · 1.77 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
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
70
import childProcess from 'child_process';
import fs from 'fs';
import readline from 'readline';
function maybeCreateGitTagForPackage({ name, version }) {
if (!name || !version) {
console.warn('Missing package data for git tag, skipping', { name, version });
return;
}
const tag = `js/${name}@${version}`;
try {
childProcess.execSync(`git rev-parse --verify ${tag}`, { stdio: "ignore" });
console.warn(`Git tag already exists, skipping: ${tag}`);
} catch {
childProcess.execSync(`git tag -a "${tag}" -m "Released JS package: @human-protocol/${name} - ${version}"`);
console.log(`Created tag: ${tag}`);
}
}
async function tagPublishedPackages(publishLogFilePath) {
if (!publishLogFilePath || !fs.existsSync(publishLogFilePath)) {
throw new Error(`Publish log file not found: ${publishLogFilePath}`);
}
const logFileStream = fs.createReadStream(publishLogFilePath);
const logFileRl = readline.createInterface({
input: logFileStream,
crlfDelay: Infinity,
});
for await (const logLine of logFileRl) {
let logEntry;
try {
logEntry = JSON.parse(logLine);
} catch {
continue;
}
const {
published: isPublished,
name: packageName,
version: packageVersion,
} = logEntry;
if (isPublished && packageName && packageVersion) {
console.log(`Found published package: ${packageName} - ${packageVersion}`);
maybeCreateGitTagForPackage({
name: packageName,
version: packageVersion,
});
}
}
}
(async () => {
try {
const publishLogFilePath = process.argv[2];
await tagPublishedPackages(publishLogFilePath);
process.exit(0);
} catch (error) {
console.error('Failed to create git tags for published packages', error);
process.exit(1);
}
})();