forked from MMRLApp/MMRL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
114 lines (102 loc) · 4.11 KB
/
deploy.js
File metadata and controls
114 lines (102 loc) · 4.11 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
107
108
109
110
111
112
113
114
const { publish } = require("gh-pages");
const { config } = require("./package.json");
const { readFileSync, statSync, readdirSync } = require("fs");
const { resolve, basename, extname } = require("path");
require("dotenv").config({ path: resolve(__dirname, "local.properties") });
const { program } = require("commander");
const { spawn } = require("child_process");
program
.command("website")
.description("Publishes the app to the provided repo")
.option("-p, --prerelease", "Publish the app as a prerelease")
.option("-r, --remote [REMOTE]", "Use another remote", "mmrl-web")
.option("-b, --branch [BRANCH]", "Use another branch", "master")
.option("-o, --owner [OWNER]", "Use repo owner", "DerGoogler")
.option("-n, --name [NAME]", "Use repo name", "mmrl-web")
.option("-a, --add", "Only add, and never remove existing files.")
.option("-l, --blog <BLOG>", "Add a blog link to the release (Placeholder)")
.action((opt) => {
const __dir = ["app/src/main/assets/www"];
publish(resolve(__dirname, ...__dir), {
branch: opt.branch,
repo: `https://github.com/${opt.owner}/${opt.name}.git`,
dest: opt.prerelease ? "prerelease" : ".",
nojekyll: true,
cname: config.cname,
remote: opt.remote,
message: "CLI Auto-generated MMRL Web Update",
user: {
name: "github-actions[bot]",
email: "github-actions[bot]@users.noreply.github.com",
},
add: false,
});
});
program
.command("github")
.description("Publishes the app to GitHub releases")
.option("-p, --prerelease", "Publish the app as a prerelease")
.option("-o, --owner [OWNER]", "Use repo owner", "DerGoogler")
.option("-n, --name [NAME]", "Use repo name", "MMRL")
.option("-l, --blog <BLOG>", "Add a blog link to the release")
.option("-v, --verTag [VERTAG]", "Use a custom version tag", "v{tag}")
.option("-t, --token [TOKEN]", "Use another GitHub token", process.env.GITHUB_TOKEN)
.action(async (opt) => {
const versionTag = opt.verTag.replace(/{tag}/gm, config.version_name);
const { Octokit } = await import("@octokit/rest");
const octokit = new Octokit({
auth: opt.token,
});
const uploadAPKFiles = async (releaseId, apkFiles) => {
for (const apkFile of apkFiles) {
const filePath = resolve(apkFile);
const fileName = basename(filePath);
const fileData = readFileSync(filePath);
const fileSize = statSync(filePath).size;
try {
await octokit.repos.uploadReleaseAsset({
owner: opt.owner,
repo: opt.name,
release_id: releaseId,
name: fileName,
data: fileData,
headers: {
"content-type": "application/vnd.android.package-archive",
"content-length": fileSize,
},
});
console.log(`Uploaded ${fileName} successfully.`);
} catch (error) {
console.error(`Failed to upload ${fileName}:`, error);
}
}
};
const createReleaseAndUploadAPKFiles = async () => {
try {
// Create a new release
const release = await octokit.repos.createRelease({
owner: opt.owner,
repo: opt.name,
tag_name: versionTag,
name: versionTag,
body: `Changelogs are readable [here](https://github.com/DerGoogler/MMRL/wiki/Changelog) or directly in the app.\n\nWeb: https://mmrl.dergoogler.com\nBlog: ${
opt.blog ? opt.blog : "-"
}`,
draft: false,
prerelease: opt.prerelease,
});
const releaseId = release.data.id;
console.log(`Created release with ID: ${releaseId}`);
// Specify your APK files here
const __dir = ["app/default/release"];
const apkFiles = readdirSync(resolve(__dirname, ...__dir))
.flatMap((file) => resolve(__dirname, ...__dir, file))
.filter((fns) => extname(fns) === ".apk");
await uploadAPKFiles(releaseId, apkFiles);
} catch (error) {
console.error("Failed to create release or upload APK files:", error);
}
};
createReleaseAndUploadAPKFiles();
});
program.parse();