xmoj-script 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/.config.yml +21 -0
- package/.github/ISSUE_TEMPLATE/bug.yml +30 -0
- package/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/.github/ISSUE_TEMPLATE/docs.yml +25 -0
- package/.github/ISSUE_TEMPLATE/feature.yml +25 -0
- package/.github/dependabot.yml +12 -0
- package/.github/labeler.yml +12 -0
- package/.github/pull_request_template.md +10 -0
- package/.github/workflows/AutoLabelIssue.yml +24 -0
- package/.github/workflows/AutoLablePR.yml +23 -0
- package/.github/workflows/CodeQL.yml +29 -0
- package/.github/workflows/Daily.yml +23 -0
- package/.github/workflows/DependencyScan.yml +13 -0
- package/.github/workflows/Prerelease.yml +43 -0
- package/.github/workflows/Release.yml +45 -0
- package/.github/workflows/UpdateToRelease.yml +30 -0
- package/.github/workflows/UpdateVersion.yml +26 -0
- package/.gitmodules +3 -0
- package/.vscode/settings.json +148 -0
- package/404.html +362 -0
- package/AddonScript.js +10 -0
- package/CNAME +1 -0
- package/CODE_OF_CONDUCT.md +218 -0
- package/Compare.md +21 -0
- package/Images/1.png +0 -0
- package/Images/10.png +0 -0
- package/Images/11.png +0 -0
- package/Images/12.png +0 -0
- package/Images/13.png +0 -0
- package/Images/14.png +0 -0
- package/Images/15.png +0 -0
- package/Images/16.png +0 -0
- package/Images/17.png +0 -0
- package/Images/2.png +0 -0
- package/Images/3.png +0 -0
- package/Images/4.png +0 -0
- package/Images/5.png +0 -0
- package/Images/6.png +0 -0
- package/Images/7.png +0 -0
- package/Images/8.png +0 -0
- package/Images/9.png +0 -0
- package/LICENSE +674 -0
- package/README.md +86 -0
- package/SECURITY.md +12 -0
- package/Update/AutoLabel.js +179 -0
- package/Update/GetVersion.js +20 -0
- package/Update/UpdateToRelease.js +73 -0
- package/Update/UpdateVersion.js +80 -0
- package/Update/package.json +7 -0
- package/Update.json +702 -0
- package/XMOJ.png +0 -0
- package/XMOJ.user.js +4490 -0
- package/backend/.github/.config.yml +21 -0
- package/backend/.github/ISSUE_TEMPLATE/bug.yml +30 -0
- package/backend/.github/ISSUE_TEMPLATE/config.yml +5 -0
- package/backend/.github/ISSUE_TEMPLATE/feature.yml +25 -0
- package/backend/.github/dependabot.yml +12 -0
- package/backend/.github/labeler.yml +14 -0
- package/backend/LICENSE +661 -0
- package/backend/README.md +3 -0
- package/backend/Source/BBSSpider.js +50 -0
- package/backend/Source/Database.ts +188 -0
- package/backend/Source/Initial.sql +95 -0
- package/backend/Source/Output.ts +14 -0
- package/backend/Source/Process.ts +1227 -0
- package/backend/Source/Result.ts +24 -0
- package/backend/Source/XMOJ-bbs.code-workspace +11 -0
- package/backend/Source/index.ts +31 -0
- package/backend/bun.lockb +0 -0
- package/backend/package.json +19 -0
- package/backend/wrangler.toml +17 -0
- package/eula.md +121 -0
- package/favicon.ico +0 -0
- package/index.html +947 -0
- package/package.json +22 -0
- package/robots.txt +2 -0
- package/sitemap-live/0.xml +26 -0
- package/sitemap.xml +6 -0
package/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+

|
2
|
+

|
3
|
+

|
4
|
+

|
5
|
+

|
6
|
+

|
7
|
+
|
8
|
+
[点击此处访问官网查看更多内容](https://web.xmoj-bbs.tech)
|
9
|
+
|
10
|
+
原项目: https://github.com/langningchen/XMOJ-Script
|
11
|
+
|
12
|
+
### 帮助文档
|
13
|
+
地址:https://docs.xmoj-bbs.tech
|
14
|
+
仓库:https://github.com/XMOJ-Script-dev/docs
|
15
|
+
|
16
|
+
### 介绍
|
17
|
+
|
18
|
+
小明的OJ是一个功能强大的浏览器扩展,旨在提升用户在小明的OJ(某虚拟在线竞赛平台)上的使用体验。
|
19
|
+
该脚本通过添加多种实用功能和界面优化,使用户能够更高效地参与竞赛、管理代码和享受更好的界面交互。
|
20
|
+
|
21
|
+
- **比赛ACM排名与下载功能**:允许用户查看比赛的ACM排名,并提供下载选项,方便离线查阅。
|
22
|
+
- **讨论区**:我们自行搭建了一个讨论服务,你可以在里面发表你的声音。
|
23
|
+
- **短消息**:我们自行搭建了一个短消息服务,你可以在这里和你最好的伙伴交流。
|
24
|
+
- **查看更多标程**:展示更多的标准程序代码,帮助用户更好地理解题目要求和正确解法。
|
25
|
+
- **获取测试点数据**:允许用户获取的测试点数据,加快你调试的速度。
|
26
|
+
- **自动刷新比赛列表与排名**:使比赛列表和排名页面自动定时刷新,获取最新信息。
|
27
|
+
- **界面时间自动倒计时**:在比赛列表等界面上自动显示剩余时间倒计时,方便用户了解时间情况。
|
28
|
+
- **回放视频下载功能**:为回放视频添加下载选项,方便用户离线观看回放。
|
29
|
+
- **自动提交已AC题目**:自动将已通过的题目再次提交,提高题目的通过率。
|
30
|
+
- **自动选择O2优化**:在代码提交界面自动选择O2优化选项,提高代码效率。
|
31
|
+
- **界面美化**:改善界面外观,提供更好的用户体验。
|
32
|
+
- 使用新版的Bootstrap样式库:更新界面样式,使之更现代。
|
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
|
+
更多图片可在[官网](https://www.xmoj-bbs.tech)上查看
|
61
|
+
|
62
|
+
通过小明的OJ增强脚本,您将能够更便捷地参与竞赛,提高AC率,管理代码,优化学习体验,同时享受美化界面带来的愉悦感受。
|
63
|
+
无论是竞技还是学习,这个脚本都将成为您在小明的OJ平台上的得力助手。
|
64
|
+
无论您是新手还是经验丰富的竞赛选手,小明的OJ都将为您的比赛体验带来前所未有的便利和效率。
|
65
|
+
立即安装并体验吧!
|
66
|
+
|
67
|
+
|
68
|
+
### 安装
|
69
|
+
请参考 [官网介绍](https://www.xmoj-bbs.tech) 。
|
70
|
+
|
71
|
+
### 加入我们
|
72
|
+
您想为我们的脚本添砖加瓦吗?快加入我们,为小明的OJ用户创造更美好的环境!(具体要求参见Code Of Conduct)
|
73
|
+
|
74
|
+
小明的OJ增强脚本开发期待以您的邂逅!
|
75
|
+
|
76
|
+
### 贡献
|
77
|
+
请注意, 外部开发者应向`extern-contrib`提交 pull requests。
|
78
|
+
|
79
|
+
### How to set up a development server
|
80
|
+
In the 'Server/Sources' folder input your GitHub PAT and Cloudflare Turnstile Site key in 'Secrets.ts', and run:
|
81
|
+
```bash
|
82
|
+
cd Server
|
83
|
+
npm install
|
84
|
+
npx wrangler d1 execute DB --file ./Source/Initial.sql --local
|
85
|
+
npx wrangler dev
|
86
|
+
```
|
package/SECURITY.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# 安全策略
|
2
|
+
|
3
|
+
## 当前支持的版本
|
4
|
+
|
5
|
+
| 版本 | 是否支持 | 预计结束支持时间 | 停止支持原因 |
|
6
|
+
| ------- | ------------------ | --------- | -------- |
|
7
|
+
| 1.0.x | :white_check_mark: | 支持 | |
|
8
|
+
| 0.3.x | :x: | 已停止支持 | 开发组人员变动 |
|
9
|
+
| 0.2.x | :x: | 已停止支持 | 讨论功能重大更新 |
|
10
|
+
| 0.1.x | :x: | 已停止支持 | 重大安全隐患 + 依赖问题(ansi_up) |
|
11
|
+
|
12
|
+
注意:在开发过程中,服务器和用户脚本可能在任何时候发生重大变动,造成非最新版本结束支持。在这种情况下,我们会尽快更新用户脚本!感谢您的谅解。
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import * as github from '@actions/github';
|
2
|
+
|
3
|
+
const Octokit = github.getOctokit(process.argv[2]);
|
4
|
+
const TrustedUsers = [
|
5
|
+
"boomzero",
|
6
|
+
"PythonSmall-Q"
|
7
|
+
];
|
8
|
+
const LabelList = [
|
9
|
+
"addon-script",
|
10
|
+
"bug",
|
11
|
+
"Cloudflare-related",
|
12
|
+
"dependency",
|
13
|
+
"designing",
|
14
|
+
"documentation",
|
15
|
+
"docs",
|
16
|
+
"duplicate",
|
17
|
+
"discussing",
|
18
|
+
"enhancement",
|
19
|
+
"frozen",
|
20
|
+
"github_actions",
|
21
|
+
"GitHub-related",
|
22
|
+
"good-first-issue",
|
23
|
+
"good first issue",
|
24
|
+
"hacktoberfest-accepted",
|
25
|
+
"help-wanted",
|
26
|
+
"invalid",
|
27
|
+
"investigating",
|
28
|
+
"needs-triage",
|
29
|
+
"priority-high",
|
30
|
+
"priority-low",
|
31
|
+
"question",
|
32
|
+
"review-needed",
|
33
|
+
"server",
|
34
|
+
"stale",
|
35
|
+
"update-script",
|
36
|
+
"user-script",
|
37
|
+
"website",
|
38
|
+
"wontfix",
|
39
|
+
"working-on-it",
|
40
|
+
"fixed"
|
41
|
+
];
|
42
|
+
let Data = github.context.payload.comment.body;
|
43
|
+
let Owner = github.context.repo.owner;
|
44
|
+
let Repo = github.context.repo.repo;
|
45
|
+
let IssueNumber = github.context.payload.issue.number;
|
46
|
+
let CommentID = github.context.payload.comment.id;
|
47
|
+
let User = github.context.payload.comment.user.login;
|
48
|
+
let Labels = github.context.payload.issue.labels.map((label) => label.name);
|
49
|
+
let Milestone = github.context.payload.issue.milestone?.number;
|
50
|
+
console.log("Data : " + Data);
|
51
|
+
console.log("Owner : " + Owner);
|
52
|
+
console.log("Repo : " + Repo);
|
53
|
+
console.log("IssueNumber : " + IssueNumber);
|
54
|
+
console.log("CommentID : " + CommentID);
|
55
|
+
console.log("User : " + User);
|
56
|
+
console.log("Labels : " + Labels);
|
57
|
+
console.log("Milestone : " + Milestone);
|
58
|
+
|
59
|
+
const LatestMilestone = await Octokit.issues.listMilestones({
|
60
|
+
owner: Owner,
|
61
|
+
repo: Repo,
|
62
|
+
state: "open"
|
63
|
+
}).then((response) => {
|
64
|
+
if (response.data.length !== 0) {
|
65
|
+
return response.data[response.data.length - 1].number;
|
66
|
+
}
|
67
|
+
return null;
|
68
|
+
});
|
69
|
+
const AddLabel = (Label) => {
|
70
|
+
if (Labels.includes(Label)) {
|
71
|
+
console.log("Label " + Label + " already exists");
|
72
|
+
return false;
|
73
|
+
}
|
74
|
+
if (!LabelList.includes(Label)) {
|
75
|
+
console.log("Label " + Label + " not exists");
|
76
|
+
return false;
|
77
|
+
}
|
78
|
+
Labels.push(Label);
|
79
|
+
return true;
|
80
|
+
};
|
81
|
+
const RemoveLabel = (Label) => {
|
82
|
+
if (!Labels.includes(Label)) {
|
83
|
+
console.log("Label " + Label + " not exists");
|
84
|
+
return false;
|
85
|
+
}
|
86
|
+
Labels = Labels.filter((label) => label !== Label);
|
87
|
+
return true;
|
88
|
+
};
|
89
|
+
const ClearLabel = () => {
|
90
|
+
Labels = [];
|
91
|
+
};
|
92
|
+
|
93
|
+
if (!TrustedUsers.includes(User)) {
|
94
|
+
console.log("Not trusted user " + User);
|
95
|
+
process.exit(0);
|
96
|
+
}
|
97
|
+
|
98
|
+
let NewData = Data.replaceAll(/(\/-?good first issue)|\/[A-Za-z_-]+/g, (match) => {
|
99
|
+
console.log("Found command " + match);
|
100
|
+
let Label = match.substring(1);
|
101
|
+
if (Label.startsWith("-")) {
|
102
|
+
Label = Label.substring(1);
|
103
|
+
if (RemoveLabel(Label)) {
|
104
|
+
return "";
|
105
|
+
}
|
106
|
+
} else {
|
107
|
+
if (AddLabel(Label)) {
|
108
|
+
if (Label === "needs-triage") {
|
109
|
+
Octokit.issues.addAssignees({
|
110
|
+
owner: Owner,
|
111
|
+
repo: Repo,
|
112
|
+
issue_number: IssueNumber,
|
113
|
+
assignees: [Owner]
|
114
|
+
});
|
115
|
+
}
|
116
|
+
else if (Label === "wontfix" || Label === "duplicate" || Label === "invalid") {
|
117
|
+
Octokit.issues.update({
|
118
|
+
owner: Owner,
|
119
|
+
repo: Repo,
|
120
|
+
issue_number: IssueNumber,
|
121
|
+
state: "closed",
|
122
|
+
state_reason: "not_planned"
|
123
|
+
});
|
124
|
+
|
125
|
+
ClearLabel();
|
126
|
+
AddLabel(Label);
|
127
|
+
Milestone = null;
|
128
|
+
}
|
129
|
+
else if (Label === "fixed"){
|
130
|
+
Octokit.issues.update({
|
131
|
+
owner: Owner,
|
132
|
+
repo: Repo,
|
133
|
+
issue_number: IssueNumber,
|
134
|
+
state: "closed",
|
135
|
+
state_reason: "completed"
|
136
|
+
});
|
137
|
+
ClearLabel();
|
138
|
+
}
|
139
|
+
return "";
|
140
|
+
}
|
141
|
+
}
|
142
|
+
return match;
|
143
|
+
});
|
144
|
+
|
145
|
+
if (User === "PythonSmall-Q") {
|
146
|
+
if (RemoveLabel("needs-triage")) {
|
147
|
+
AddLabel("investigating");
|
148
|
+
Milestone = LatestMilestone;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
console.log("----------------------------------------");
|
153
|
+
console.log("NewData : " + NewData);
|
154
|
+
console.log("NewLabels : " + Labels);
|
155
|
+
console.log("NewMilestone: " + Milestone);
|
156
|
+
|
157
|
+
NewData = NewData.trim();
|
158
|
+
if (NewData === "") {
|
159
|
+
Octokit.issues.deleteComment({
|
160
|
+
owner: Owner,
|
161
|
+
repo: Repo,
|
162
|
+
comment_id: CommentID
|
163
|
+
});
|
164
|
+
} else if (NewData !== Data) {
|
165
|
+
Octokit.issues.updateComment({
|
166
|
+
owner: Owner,
|
167
|
+
repo: Repo,
|
168
|
+
comment_id: CommentID,
|
169
|
+
body: NewData
|
170
|
+
});
|
171
|
+
}
|
172
|
+
|
173
|
+
Octokit.issues.update({
|
174
|
+
owner: Owner,
|
175
|
+
repo: Repo,
|
176
|
+
issue_number: IssueNumber,
|
177
|
+
labels: Labels,
|
178
|
+
milestone: Milestone
|
179
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { readFileSync } from "fs";
|
2
|
+
import { execSync } from "child_process";
|
3
|
+
|
4
|
+
const JSONFileName = "./Update.json";
|
5
|
+
const JSFileName = "./XMOJ.user.js";
|
6
|
+
var JSONFileContent = readFileSync(JSONFileName, "utf8");
|
7
|
+
var JSFileContent = readFileSync(JSFileName, "utf8");
|
8
|
+
|
9
|
+
var JSONObject = JSON.parse(JSONFileContent);
|
10
|
+
|
11
|
+
var LastJSONVersion = Object.keys(JSONObject.UpdateHistory)[Object.keys(JSONObject.UpdateHistory).length - 1];
|
12
|
+
var LastJSVersion = JSFileContent.match(/@version\s+(\d+\.\d+\.\d+)/)[1];
|
13
|
+
if (LastJSONVersion != LastJSVersion) {
|
14
|
+
console.log("Error: XMOJ.user.js and Update.json have different versions.");
|
15
|
+
console.log("XMOJ.user.js: " + LastJSVersion);
|
16
|
+
console.log("Update.json: " + LastJSONVersion);
|
17
|
+
process.exit(1);
|
18
|
+
}
|
19
|
+
console.log("Latest version: " + LastJSONVersion);
|
20
|
+
execSync("echo version=" + LastJSONVersion + " >> $GITHUB_OUTPUT");
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
2
|
+
import { execSync } from "child_process";
|
3
|
+
|
4
|
+
var GithubToken = process.argv[2];
|
5
|
+
var PRNumber = process.argv[3];
|
6
|
+
process.env.GITHUB_TOKEN = GithubToken;
|
7
|
+
execSync("gh pr checkout " + PRNumber);
|
8
|
+
console.info("PR #" + PRNumber + " has been checked out.");
|
9
|
+
|
10
|
+
const JSONFileName = "./Update.json";
|
11
|
+
const JSFileName = "./XMOJ.user.js";
|
12
|
+
var JSONFileContent = readFileSync(JSONFileName, "utf8");
|
13
|
+
var JSFileContent = readFileSync(JSFileName, "utf8");
|
14
|
+
var JSONObject = JSON.parse(JSONFileContent);
|
15
|
+
|
16
|
+
var LastJSONVersion = Object.keys(JSONObject.UpdateHistory)[Object.keys(JSONObject.UpdateHistory).length - 1];
|
17
|
+
var LastJSVersion = JSFileContent.match(/@version\s+(\d+\.\d+\.\d+)/)[1];
|
18
|
+
var LastVersion = LastJSVersion.split(".");
|
19
|
+
var LastPR = JSONObject.UpdateHistory[LastJSONVersion].UpdateContents[0].PR;
|
20
|
+
var LastType = JSONObject.UpdateHistory[LastJSONVersion].Prerelease ? "Prerelease" : "Release";
|
21
|
+
console.log("Last JS version : " + LastJSVersion);
|
22
|
+
console.log("Last JSON version : " + LastJSONVersion);
|
23
|
+
console.log("Last PR : " + LastPR);
|
24
|
+
console.log("Last type : " + LastType);
|
25
|
+
if (LastJSONVersion.split(".")[2] != LastJSVersion.split(".")[2]) {
|
26
|
+
console.error("XMOJ.user.js and Update.json have different patch versions.");
|
27
|
+
process.exit(1);
|
28
|
+
}
|
29
|
+
|
30
|
+
var CurrentVersion = LastVersion[0] + "." + LastVersion[1] + "." + (parseInt(LastVersion[2]) + 1);
|
31
|
+
if (LastType == "Release") {
|
32
|
+
CurrentVersion = LastJSONVersion;
|
33
|
+
}
|
34
|
+
console.log("Current version : " + CurrentVersion);
|
35
|
+
|
36
|
+
JSONObject.UpdateHistory[CurrentVersion] = {
|
37
|
+
"UpdateDate": Date.now(),
|
38
|
+
"Prerelease": false,
|
39
|
+
"UpdateContents": []
|
40
|
+
};
|
41
|
+
|
42
|
+
for (var i = Object.keys(JSONObject.UpdateHistory).length - 2; i >= 0; i--) {
|
43
|
+
var Version = Object.keys(JSONObject.UpdateHistory)[i];
|
44
|
+
if (JSONObject.UpdateHistory[Version].Prerelease == false) {
|
45
|
+
break;
|
46
|
+
}
|
47
|
+
for (var j = 0; j < JSONObject.UpdateHistory[Version].UpdateContents.length; j++) {
|
48
|
+
JSONObject.UpdateHistory[CurrentVersion].UpdateContents.push(JSONObject.UpdateHistory[Version].UpdateContents[j]);
|
49
|
+
console.log("Add update content #" + JSONObject.UpdateHistory[Version].UpdateContents[j].PR + ": " + JSONObject.UpdateHistory[Version].UpdateContents[j].Description);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
JSONObject.UpdateHistory[CurrentVersion].UpdateContents.reverse();
|
53
|
+
writeFileSync(JSONFileName, JSON.stringify(JSONObject, null, 4), "utf8");
|
54
|
+
console.warn("Update.json has been updated.");
|
55
|
+
|
56
|
+
var NewJSFileContent = JSFileContent.replace(/@version(\s+)\d+\.\d+\.\d+/, "@version$1" + CurrentVersion);
|
57
|
+
writeFileSync(JSFileName, NewJSFileContent, "utf8");
|
58
|
+
console.warn("XMOJ.user.js has been updated.");
|
59
|
+
|
60
|
+
execSync("git config --global user.email \"github-actions[bot]@users.noreply.github.com\"");
|
61
|
+
execSync("git config --global user.name \"github-actions[bot]\"");
|
62
|
+
execSync("git pull");
|
63
|
+
execSync("git push origin --delete actions/temp || true");
|
64
|
+
execSync("git checkout -b actions/temp");
|
65
|
+
execSync("git commit -a -m \"Update to release " + CurrentVersion + "\"");
|
66
|
+
execSync("git push -u origin actions/temp -f");
|
67
|
+
console.warn("Pushed to actions/temp.");
|
68
|
+
|
69
|
+
var PRNumber = execSync("gh pr create --title \"Update to release " + CurrentVersion + "\" --body \"Update to release " + CurrentVersion + "\" --base dev --head actions/temp").toString().split("/")[6].trim();
|
70
|
+
console.warn("PR #" + PRNumber + " has been created.");
|
71
|
+
|
72
|
+
execSync("gh pr merge " + PRNumber + " --merge --auto");
|
73
|
+
console.warn("PR #" + PRNumber + " has enabled auto merge.");
|
@@ -0,0 +1,80 @@
|
|
1
|
+
import { readFileSync, writeFileSync } from "fs";
|
2
|
+
import { execSync } from "child_process";
|
3
|
+
|
4
|
+
var GithubToken = process.argv[2];
|
5
|
+
var PRNumber = process.argv[3];
|
6
|
+
process.env.GITHUB_TOKEN = GithubToken;
|
7
|
+
execSync("gh pr checkout " + PRNumber);
|
8
|
+
console.info("PR #" + PRNumber + " has been checked out.");
|
9
|
+
|
10
|
+
const JSONFileName = "./Update.json";
|
11
|
+
const JSFileName = "./XMOJ.user.js";
|
12
|
+
var JSONFileContent = readFileSync(JSONFileName, "utf8");
|
13
|
+
var JSFileContent = readFileSync(JSFileName, "utf8");
|
14
|
+
var JSONObject = JSON.parse(JSONFileContent);
|
15
|
+
|
16
|
+
var LastJSONVersion = Object.keys(JSONObject.UpdateHistory)[Object.keys(JSONObject.UpdateHistory).length - 1];
|
17
|
+
var LastJSVersion = JSFileContent.match(/@version\s+(\d+\.\d+\.\d+)/)[1];
|
18
|
+
var LastVersion = LastJSVersion.split(".");
|
19
|
+
var LastPR = JSONObject.UpdateHistory[LastJSONVersion].UpdateContents[0].PR;
|
20
|
+
var LastDescription = JSONObject.UpdateHistory[LastJSONVersion].UpdateContents[0].Description;
|
21
|
+
var LastReleaseVersionOnline = execSync("gh release list --exclude-pre-releases --limit 1").toString().trim().split("\t")[2];
|
22
|
+
console.log("Last JS version : " + LastJSVersion);
|
23
|
+
console.log("Last JSON version : " + LastJSONVersion);
|
24
|
+
console.log("Last PR : " + LastPR);
|
25
|
+
console.log("Last description : " + LastDescription);
|
26
|
+
console.log("Last release online: " + LastReleaseVersionOnline);
|
27
|
+
if (LastJSONVersion != LastJSVersion) {
|
28
|
+
console.error("XMOJ.user.js and Update.json have different patch versions.");
|
29
|
+
process.exit(1);
|
30
|
+
}
|
31
|
+
|
32
|
+
var CurrentVersion = LastVersion[0] + "." + LastVersion[1] + "." + (parseInt(LastVersion[2]) + 1);
|
33
|
+
var CurrentPR = Number(PRNumber);
|
34
|
+
var CurrentDescription = String(process.argv[4]);
|
35
|
+
if (LastPR == CurrentPR || JSONObject.UpdateHistory[LastJSONVersion].Prerelease == false && LastReleaseVersionOnline != LastJSONVersion) {
|
36
|
+
CurrentVersion = LastJSONVersion;
|
37
|
+
}
|
38
|
+
|
39
|
+
console.log("Current version : " + CurrentVersion);
|
40
|
+
console.log("Current PR : " + CurrentPR);
|
41
|
+
console.log("Current description: " + CurrentDescription);
|
42
|
+
|
43
|
+
var ChangedFileList = execSync("gh pr diff " + CurrentPR + " --name-only").toString().trim().split("\n");
|
44
|
+
console.log("Changed files : " + ChangedFileList.join(", "));
|
45
|
+
|
46
|
+
let CommitMessage = "";
|
47
|
+
if (LastPR == CurrentPR) {
|
48
|
+
console.warn("Warning: PR is the same as last version.");
|
49
|
+
JSONObject.UpdateHistory[CurrentVersion].UpdateDate = Date.now();
|
50
|
+
JSONObject.UpdateHistory[CurrentVersion].UpdateContents[0].Description = CurrentDescription;
|
51
|
+
CommitMessage = "Update time and description of " + CurrentVersion;
|
52
|
+
}
|
53
|
+
else if (ChangedFileList.indexOf("XMOJ.user.js") == -1) {
|
54
|
+
console.warn("XMOJ.user.js is not changed, so the version should not be updated.");
|
55
|
+
process.exit(0);
|
56
|
+
} else {
|
57
|
+
JSONObject.UpdateHistory[CurrentVersion] = {
|
58
|
+
"UpdateDate": Date.now(),
|
59
|
+
"Prerelease": true,
|
60
|
+
"UpdateContents": [{
|
61
|
+
"PR": CurrentPR,
|
62
|
+
"Description": CurrentDescription
|
63
|
+
}]
|
64
|
+
};
|
65
|
+
writeFileSync(JSFileName, JSFileContent.replace(/@version(\s+)\d+\.\d+\.\d+/, "@version$1" + CurrentVersion), "utf8");
|
66
|
+
console.warn("XMOJ.user.js has been updated.");
|
67
|
+
CommitMessage = "Update version info to " + CurrentVersion;
|
68
|
+
}
|
69
|
+
console.log("Commit message : " + CommitMessage);
|
70
|
+
|
71
|
+
writeFileSync(JSONFileName, JSON.stringify(JSONObject, null, 4), "utf8");
|
72
|
+
|
73
|
+
console.warn("Update.json has been updated.");
|
74
|
+
|
75
|
+
execSync("git config --global user.email \"github-actions[bot]@users.noreply.github.com\"");
|
76
|
+
execSync("git config --global user.name \"github-actions[bot]\"");
|
77
|
+
execSync("git pull");
|
78
|
+
execSync("git commit -a -m \"" + CommitMessage + "\"");
|
79
|
+
execSync("git push -f");
|
80
|
+
console.log("Pushed to GitHub.");
|