Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/UpdateToRelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- opened
- reopened
- synchronize
- edited
branches:
- master
jobs:
Expand All @@ -24,7 +25,8 @@ jobs:
gh pr comment ${{ github.event.pull_request.number }} --body "请向\`dev\`分支提交pull request, 本pull request将被自动关闭"
gh pr close ${{ github.event.pull_request.number }}
else
node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }}
node ./Update/UpdateToRelease.js ${{ secrets.GITHUB_TOKEN }} ${{ github.event.number }} "$PR_BODY"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_BODY: ${{ github.event.pull_request.body }}
4 changes: 3 additions & 1 deletion .github/workflows/UpdateVersion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ jobs:
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v5
- name: Update version
run: node ./Update/UpdateVersion.js ${{ steps.generate_token.outputs.token }} ${{ github.event.number }} "${{ github.event.pull_request.title }}"
env:
PR_BODY: ${{ github.event.pull_request.body }}
run: node ./Update/UpdateVersion.js ${{ steps.generate_token.outputs.token }} ${{ github.event.number }} "${{ github.event.pull_request.title }}" "$PR_BODY"
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ We believe that you must be excited to contribute to our repo, but first, please
- Be patient. We are a small team and may not be able to review your PR immediately.
- Please be considerate towards the developers and other users when raising issues or presenting pull requests.
- Respect our decision(s), and do not be upset or abusive if your submission is not used.
- 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.
10 changes: 9 additions & 1 deletion Update/UpdateToRelease.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import {execSync} from "child_process";

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

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

for (var i = Object.keys(JSONObject.UpdateHistory).length - 2; i >= 0; i--) {
Expand Down
13 changes: 12 additions & 1 deletion Update/UpdateVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ execSync("git config --global user.email \"github-actions[bot]@users.noreply.git
execSync("git config --global user.name \"github-actions[bot]\"");
var CurrentPR = Number(PRNumber);
var CurrentDescription = String(process.argv[4]);
function extractReleaseNotes(body) {
const match = body
.replace(/\r\n/g, "\n")
.match(/<!--\s*release[- ]notes\s*([\s\S]*?)-->/i);
return match ? match[1].trim() : "";
}
var CurrentNotes = extractReleaseNotes(String(process.argv[5] || ""));
if (LastJSVersion != NpmVersion) {
console.warn("Assuming you manually ran npm version.");
} else if (!(LastPR == CurrentPR && NpmVersion == LastJSVersion)) {
Expand All @@ -58,6 +65,7 @@ var CurrentVersion = execSync("jq -r '.version' package.json").toString().trim()
console.log("Current version : " + CurrentVersion);
console.log("Current PR : " + CurrentPR);
console.log("Current description: " + CurrentDescription);
console.log("Current notes : " + (CurrentNotes || "No release notes were provided for this release."));

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