Skip to content

Commit d3bd686

Browse files
authored
Merge pull request #841 from XMOJ-Script-dev/codex/add-standardized-process-for-release-notes
Parse release notes from comment block
2 parents ea79887 + c7137ff commit d3bd686

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

.github/workflows/UpdateToRelease.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- opened
66
- reopened
77
- synchronize
8+
- edited
89
branches:
910
- master
1011
jobs:
@@ -24,7 +25,8 @@ jobs:
2425
gh pr comment ${{ github.event.pull_request.number }} --body "请向\`dev\`分支提交pull request, 本pull request将被自动关闭"
2526
gh pr close ${{ github.event.pull_request.number }}
2627
else
27-
node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }}
28+
node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }} "$PR_BODY"
2829
fi
2930
env:
3031
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
PR_BODY: ${{ github.event.pull_request.body }}

.github/workflows/UpdateVersion.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ jobs:
2323
private-key: ${{ secrets.APP_PRIVATE_KEY }}
2424
- uses: actions/checkout@v5
2525
- name: Update version
26-
run: node ./Update/UpdateVersion.js ${{ steps.generate_token.outputs.token }} ${{ github.event.number }} "${{ github.event.pull_request.title }}"
26+
env:
27+
PR_BODY: ${{ github.event.pull_request.body }}
28+
run: node ./Update/UpdateVersion.js ${{ steps.generate_token.outputs.token }} ${{ github.event.number }} "${{ github.event.pull_request.title }}" "$PR_BODY"

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ We believe that you must be excited to contribute to our repo, but first, please
1818
- Be patient. We are a small team and may not be able to review your PR immediately.
1919
- Please be considerate towards the developers and other users when raising issues or presenting pull requests.
2020
- Respect our decision(s), and do not be upset or abusive if your submission is not used.
21+
- For release pull requests, include an HTML comment block starting with `<!-- release-notes` and ending with `-->` in the PR description. The automation will extract that block into the release notes.

Update/UpdateToRelease.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import {execSync} from "child_process";
33

44
var GithubToken = process.argv[2];
55
var PRNumber = process.argv[3];
6+
function extractReleaseNotes(body) {
7+
const match = body
8+
.replace(/\r\n/g, "\n")
9+
.match(/<!--\s*release[- ]notes\s*([\s\S]*?)-->/i);
10+
return match ? match[1].trim() : "";
11+
}
12+
var CurrentNotes = extractReleaseNotes(String(process.argv[4] || ""));
613
process.env.GITHUB_TOKEN = GithubToken;
714
execSync("gh pr checkout " + PRNumber);
815
console.info("PR #" + PRNumber + " has been checked out.");
@@ -45,6 +52,7 @@ console.log("Last JSON version : " + LastJSONVersion);
4552
console.log("Last PR : " + LastPR);
4653
console.log("Last type : " + LastType);
4754
console.log("npm version : " + NpmVersion);
55+
console.log("Current notes : " + (CurrentNotes || "No release notes were provided for this release."));
4856

4957
if (LastJSONVersion != LastJSVersion) {
5058
console.error("XMOJ.user.js and Update.json have different patch versions.");
@@ -67,7 +75,7 @@ JSONObject.UpdateHistory[CurrentVersion] = {
6775
"UpdateDate": Date.now(),
6876
"Prerelease": false,
6977
"UpdateContents": [],
70-
"Notes": "No release notes were provided for this release."
78+
"Notes": CurrentNotes || "No release notes were provided for this release."
7179
};
7280

7381
for (var i = Object.keys(JSONObject.UpdateHistory).length - 2; i >= 0; i--) {

Update/UpdateVersion.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ execSync("git config --global user.email \"github-actions[bot]@users.noreply.git
4747
execSync("git config --global user.name \"github-actions[bot]\"");
4848
var CurrentPR = Number(PRNumber);
4949
var CurrentDescription = String(process.argv[4]);
50+
function extractReleaseNotes(body) {
51+
const match = body
52+
.replace(/\r\n/g, "\n")
53+
.match(/<!--\s*release[- ]notes\s*([\s\S]*?)-->/i);
54+
return match ? match[1].trim() : "";
55+
}
56+
var CurrentNotes = extractReleaseNotes(String(process.argv[5] || ""));
5057
if (LastJSVersion != NpmVersion) {
5158
console.warn("Assuming you manually ran npm version.");
5259
} else if (!(LastPR == CurrentPR && NpmVersion == LastJSVersion)) {
@@ -58,6 +65,7 @@ var CurrentVersion = execSync("jq -r '.version' package.json").toString().trim()
5865
console.log("Current version : " + CurrentVersion);
5966
console.log("Current PR : " + CurrentPR);
6067
console.log("Current description: " + CurrentDescription);
68+
console.log("Current notes : " + (CurrentNotes || "No release notes were provided for this release."));
6169

6270
var ChangedFileList = execSync("gh pr diff " + CurrentPR + " --name-only").toString().trim().split("\n");
6371
console.log("Changed files : " + ChangedFileList.join(", "));
@@ -67,6 +75,9 @@ if (LastPR == CurrentPR && NpmVersion == LastJSVersion) {
6775
console.warn("Warning: PR is the same as last version.");
6876
JSONObject.UpdateHistory[LastJSVersion].UpdateDate = Date.now();
6977
JSONObject.UpdateHistory[LastJSVersion].UpdateContents[0].Description = CurrentDescription;
78+
if (CurrentNotes) {
79+
JSONObject.UpdateHistory[LastJSVersion].Notes = CurrentNotes;
80+
}
7081
CommitMessage = "Update time and description of " + LastJSVersion;
7182
} else if (ChangedFileList.indexOf("XMOJ.user.js") == -1) {
7283
console.warn("XMOJ.user.js is not changed, so the version should not be updated.");
@@ -79,7 +90,7 @@ if (LastPR == CurrentPR && NpmVersion == LastJSVersion) {
7990
"PR": CurrentPR,
8091
"Description": CurrentDescription
8192
}],
82-
"Notes": "No release notes were provided for this release."
93+
"Notes": CurrentNotes || "No release notes were provided for this release."
8394
};
8495
writeFileSync(JSFileName, JSFileContent.replace(/@version(\s+)\d+\.\d+\.\d+/, "@version$1" + CurrentVersion), "utf8");
8596
console.warn("XMOJ.user.js has been updated.");

0 commit comments

Comments
 (0)