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
17 changes: 10 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down
57 changes: 55 additions & 2 deletions .github/workflows/scripts/src/notify-prs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,6 +35,18 @@ module.exports = async ({github, context, core}) => {
// Functions
//

/**
* @returns {Promise<Release[]>}
*/
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<Tag[]>}
*/
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -188,7 +241,7 @@ module.exports = async ({github, context, core}) => {
/** @type {Set<number>} */
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}`);

Expand Down