-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.js
More file actions
95 lines (77 loc) · 2.14 KB
/
github.js
File metadata and controls
95 lines (77 loc) · 2.14 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const { exec } = require("../utils/util");
const {
getRepoInfo,
getSha,
tagExists,
createTag,
createRelease,
} = require("../utils/github");
const {
checkVersionExists,
GITHUB_URL,
getNpmDistTag,
} = require("../utils/npm");
const packageJson = require("../../package.json");
const build = require("../utils/build");
const { generateChangelog } = require("../utils/util");
async function buildProject() {
const github_token = process.env.GITHUB_TOKEN;
if (!github_token) {
throw new Error("Github Token Not Found");
}
const { owner, repo } = getRepoInfo();
const sha = getSha();
const tempjson = {
...packageJson,
name: `@${owner}/${packageJson.name}`,
};
const version = tempjson.version;
if (!version) {
throw new Error("package.json version not found");
}
console.log("Starting GitHub Release Process");
console.log(`Repository: ${owner}/${repo}`);
console.log(`Version: ${version}`);
console.log(`Current commit: ${sha.slice(0, 7)}`);
const npmVerExists = checkVersionExists(tempjson.name, version, GITHUB_URL);
const githubTagExists = tagExists(version);
let buildPath = null;
let err = false;
if (githubTagExists) {
console.log(`Tag (git) ${version} already exists`);
} else {
try {
console.log(`Git tag ${version} does not exist`);
buildPath ??= await build(tempjson);
//createTag(version, sha);
const changelog = generateChangelog(version);
await createRelease(version, buildPath, changelog);
} catch (error) {
console.log(error);
err = true;
}
}
if (npmVerExists) {
console.log(`Version (npm) ${version} already exists`);
} else {
try {
console.log(`npm version ${version} does not exist`);
buildPath ??= await build(tempjson);
const distTag = getNpmDistTag(version);
const tagArg = distTag === "latest" ? "" : ` --tag ${distTag}`;
exec(`npm publish "${buildPath}" --registry=${GITHUB_URL}${tagArg}`, {
stdio: "inherit",
});
} catch (error) {
console.log(error);
err = true;
}
if (err) throw new Error("Failed to publish");
}
}
if (require.main === module) {
buildProject().catch((err) => {
console.error("Patch failed:", err);
process.exit(1);
});
}