-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
106 lines (89 loc) · 4.51 KB
/
test.ts
File metadata and controls
106 lines (89 loc) · 4.51 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
96
97
98
99
100
101
102
103
104
105
106
import path from "path";
import fs from "fs/promises";
import { runCommandInDir } from "./sources/bin/src/util/runCommandInDir";
const tagPushed = "2.15.25";
const versionRegex = /^(\d+\.\d+\.\d+)( .+)?/;
async function doesPackageExist(packageIdentifier: string) {
try {
await runCommandInDir(process.cwd(), "yarn npm info " + packageIdentifier);
return true;
} catch (e) {
console.log(e);
return false;
}
}
(async () => {
const newSkeldjsVersion = tagPushed.match(versionRegex)![1];
const baseHindenburgDir = path.resolve(__dirname, "Hindenburg");
console.log("Resetting repository..");
await runCommandInDir(baseHindenburgDir, "git fetch --all");
await runCommandInDir(baseHindenburgDir, "git reset --hard HEAD");
const packageJsonPath = path.resolve(baseHindenburgDir, "package.json");
const changelogJsonPath = path.resolve(baseHindenburgDir, "changelog.json");
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf8"));
console.log("Updating skeldjs..");
const dependencies = Object.keys(packageJson.dependencies);
let flag = false;
for (const dependencyName of dependencies) {
if (dependencyName.startsWith("@skeldjs/")) {
if (await doesPackageExist(dependencyName + "@" + newSkeldjsVersion)) {
packageJson.dependencies[dependencyName] = "^" + newSkeldjsVersion;
console.log("Updated %s to version %s", dependencyName, newSkeldjsVersion);
flag = true;
} else {
console.log("Package doesn't exist: %s@%s", dependencyName, newSkeldjsVersion);
}
}
}
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, undefined, 4), "utf8");
if (!flag) {
console.log("No packages updated, exiting..");
return;
}
console.log("Installing updated packages..");
await runCommandInDir(baseHindenburgDir, "yarn");
if (!await runCommandInDir(baseHindenburgDir, "git diff")) { // if there were change
console.log("There were no changes to made");
return;
}
console.log("Configuring git credentials..");
await runCommandInDir(baseHindenburgDir, "git config user.name " + process.env.GH_APP_USERNAME);
await runCommandInDir(baseHindenburgDir, "git config user.email " + process.env.GH_APP_EMAIL);
console.log("Committing..");
await runCommandInDir(baseHindenburgDir, "git add package.json yarn.lock");
await runCommandInDir(baseHindenburgDir, "git commit -m \"Update skeldjs to v" + newSkeldjsVersion + "\"");
const lastCommitSha = await runCommandInDir(baseHindenburgDir, "git rev-parse HEAD");
if (!lastCommitSha) {
console.log("Couldn't get last commit");
return;
}
console.log("Reading package.json and changelog.json..");
let changelogJson = JSON.parse(await fs.readFile(changelogJsonPath, "utf8"));
const [ major, minor, patch, ...rest ] = packageJson.version.split(".");
const newHindenburgVersion = major + "." + minor + "." + (parseInt(patch) + 1) + "." + rest.join(".");
packageJson.version = newHindenburgVersion;
const date = new Date();
delete changelogJson["$schema"];
changelogJson = {
"$schema": "./misc/changelog.schema.json", // cheats to put version at the start of the changelog
[packageJson.version]: {
version: newHindenburgVersion,
contributors: ["Rhea"],
date: date.getUTCFullYear().toString().padStart(4, "0") + "-" + date.getUTCMonth().toString().padStart(2, "0") + "-" + date.getUTCDay().toString().padStart(2, "0"),
notes: [
{
description: "Update skeldjs to v" + newSkeldjsVersion,
commits: [ lastCommitSha.trim() ]
}
]
},
...changelogJson
};
console.log("Writing package.json and changelog.json..");
await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, undefined, 4), "utf8");
await fs.writeFile(changelogJsonPath, JSON.stringify(changelogJson, undefined, 4), "utf8");
await runCommandInDir(baseHindenburgDir, "git add package.json changelog.json");
await runCommandInDir(baseHindenburgDir, "git commit -m \"" + newHindenburgVersion + "\"");
await runCommandInDir(baseHindenburgDir, "git tag -a \"" + newHindenburgVersion + "\n\n- Update skeldjs to v" + newSkeldjsVersion + "\"");
await runCommandInDir(baseHindenburgDir, "git push https://x-access-token:" + this.);
})();