From 1ab9daf558f97a76cbeafd46b380cc69aa5e561a Mon Sep 17 00:00:00 2001 From: NotRyken <127091011+NotRyken@users.noreply.github.com> Date: Sun, 16 Aug 2026 14:00:01 +0800 Subject: [PATCH] update --- .github/workflows/release.yml | 17 +++--- .github/workflows/scripts/src/notify-prs.js | 57 ++++++++++++++++++++- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef8e544..020583f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -56,11 +56,11 @@ on: - 'ubuntu-latest' - 'windows-latest' default: 'ubuntu-latest' - notify-prs: - type: boolean - description: Notify Included PRs + notify-pr-months: + type: number + description: Notify PRs (Months) required: true - default: true + default: 2 sync-desc-modrinth: type: boolean description: Sync Modrinth Description @@ -199,13 +199,16 @@ jobs: NEOFORGE_TASK: ${{ inputs.neoforge && 'neoforge:publishCurseforge' || '' }} run: ./gradlew $FABRIC_TASK $NEOFORGE_TASK --stacktrace - - name: Wait 10 seconds - run: sleep 10 + # Wait a few seconds to make sure the tag(s) are available. + - name: Wait 7 seconds + run: sleep 7 - name: Notify PRs uses: actions/github-script@v9 - if: inputs.notify-prs && steps.github.outcome == 'success' + if: inputs.notify-prs > 0 && steps.github.outcome == 'success' continue-on-error: true + env: + SCAN_MONTHS: ${{ github.event.inputs.notify-pr-months }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | diff --git a/.github/workflows/scripts/src/notify-prs.js b/.github/workflows/scripts/src/notify-prs.js index a24af15..f22a664 100644 --- a/.github/workflows/scripts/src/notify-prs.js +++ b/.github/workflows/scripts/src/notify-prs.js @@ -2,6 +2,7 @@ * @typedef {import('@octokit/rest').Octokit} Octokit * @typedef {import('@actions/github').context} Context * @typedef {import('@actions/core')} Core + * @typedef {import('@octokit/openapi-types').components['schemas']['release']} Release * @typedef {import('@octokit/openapi-types').components['schemas']['tag']} Tag * @typedef {import('@octokit/openapi-types').components['schemas']['pull-request']} PullRequest * @typedef {import('@octokit/openapi-types').components['schemas']['commit-comparison']} CommitComparison @@ -34,6 +35,18 @@ module.exports = async ({github, context, core}) => { // Functions // + /** + * @returns {Promise} + */ + async function getAllReleases() { + // https://docs.github.com/en/rest/releases/releases#list-releases + return await github.paginate(github.rest.repos.listReleases, { + owner, + repo, + per_page: 100, + }); + } + /** * @returns {Promise} */ @@ -152,9 +165,49 @@ module.exports = async ({github, context, core}) => { // Control flow // + const scanMonths = Number(process.env.SCAN_MONTHS ?? `0`) + if (!Number.isInteger(scanMonths)) { + console.log(`Env SCAN_MONTHS (${process.env.SCAN_MONTHS}) is not an integer: aborting`); + return; + } else if (scanMonths < 1) { + console.log(`Env SCAN_MONTHS (${scanMonths}) is less than one: aborting)`) + return; + } + + const allReleases = await getAllReleases(); + console.log(`Found ${allReleases.length} total releases`); + if (allReleases.length > 0) { + console.log(`Newest release tag is ${allReleases[0].tag_name}`); + } + const allTags = await getAllTags(); console.log(`Found ${allTags.length} total tags`); + const cutoff = new Date(new Date().setMonth(new Date().getMonth() - scanMonths)); + + const recentReleases = new Map(allReleases + .filter((release) => release.published_at && new Date(release.published_at).getTime() >= cutoff) + .map((release) => [release.tag_name, release]) + ); + console.log(`Filtered ${recentReleases.length} recent releases`); + if (recentReleases.length > 0) { + console.log(`Oldest recent release tag is ${recentReleases[recentReleases.length - 1].tag_name}`); + } + + const recentTags = allTags + .filter((tag) => recentReleases.has(tag.name)) + .sort((a, b) => { + // newest first + const releaseA = recentReleases.get(a.name); + const releaseB = recentReleases.get(b.name); + return (new Date(releaseB.published_at).getTime() - new Date(releaseA.published_at).getTime()); + }); + console.log(`Filtered ${recentTags.length} recent tags`); + if (recentTags.length > 0) { + console.log(`Newest recent tag is ${recentTags[0].name}`); + console.log(`Oldest recent tag is ${recentTags[recentTags.length - 1].name}`); + } + const releaseTagNames = []; if (context.payload && context.payload.release) { // release context; use the release tag @@ -163,7 +216,7 @@ module.exports = async ({github, context, core}) => { } else { // other context; iterate all tags with matching SHA console.log(`No release context; searching tags`) - for (const tag of allTags) { + for (const tag of recentTags) { if (tag.commit.sha === process.env.GITHUB_SHA) { console.log(`Found tag with matching SHA: ${tag.name}`); releaseTagNames.push(tag.name); @@ -188,7 +241,7 @@ module.exports = async ({github, context, core}) => { /** @type {Set} */ let pullNumbers; - const previousTag = await getPreviousTag(allTags, loaderName, releaseTagName); + const previousTag = await getPreviousTag(recentTags, loaderName, releaseTagName); if (previousTag) { console.log(`Found previous tag: ${previousTag.name}`);