Skip to content

Commit 16cf5df

Browse files
authored
ci: sync latest changes around getting previous release
1 parent f0325e0 commit 16cf5df

File tree

4 files changed

+71
-49
lines changed

4 files changed

+71
-49
lines changed

scripts/release/comment.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
OWNER,
44
REPO,
55
PR_FILES_STARTS_WITH,
6-
IS_NIGHTLY_RELEASE,
6+
IS_STABLE_RELEASE,
77
AWAITING_RELEASE_LABEL,
88
} from "./constants";
99
import {
@@ -53,7 +53,7 @@ async function commentOnIssuesAndPrsAboutRelease() {
5353
let prLabels = pr.labels.map((label) => label.name);
5454
let prIsAwaitingRelease = prLabels.includes(AWAITING_RELEASE_LABEL);
5555

56-
if (!IS_NIGHTLY_RELEASE && prIsAwaitingRelease) {
56+
if (IS_STABLE_RELEASE && prIsAwaitingRelease) {
5757
promises.push(
5858
removeLabel({ owner: OWNER, repo: REPO, issue: pr.number })
5959
);
@@ -73,27 +73,19 @@ async function commentOnIssuesAndPrsAboutRelease() {
7373

7474
issuesCommentedOn.add(issue.number);
7575
let issueUrl = getGitHubUrl("issue", issue.number);
76+
console.log(`commenting on issue ${issueUrl}`);
7677

77-
if (IS_NIGHTLY_RELEASE || !prIsAwaitingRelease) {
78-
console.log(`commenting on ${issueUrl}`);
79-
promises.push(
80-
commentOnIssue({
81-
owner: OWNER,
82-
repo: REPO,
83-
issue: issue.number,
84-
version: VERSION,
85-
})
86-
);
87-
} else {
88-
console.log(`commenting on and closing ${issueUrl}`);
89-
promises.push(
90-
commentOnIssue({
91-
owner: OWNER,
92-
repo: REPO,
93-
issue: issue.number,
94-
version: VERSION,
95-
})
96-
);
78+
promises.push(
79+
commentOnIssue({
80+
owner: OWNER,
81+
repo: REPO,
82+
issue: issue.number,
83+
version: VERSION,
84+
})
85+
);
86+
87+
if (IS_STABLE_RELEASE) {
88+
console.log(`closing issue ${issueUrl}`);
9789
promises.push(
9890
closeIssue({ owner: OWNER, repo: REPO, issue: issue.number })
9991
);
@@ -104,10 +96,7 @@ async function commentOnIssuesAndPrsAboutRelease() {
10496
let result = await Promise.allSettled(promises);
10597
let rejected = result.filter((r) => r.status === "rejected");
10698
if (rejected.length > 0) {
107-
console.log(
108-
"🚨 failed to comment on some issues/prs - the most likely reason is they were issues that were turned into discussions, which don't have an api to comment with"
109-
);
110-
console.log(rejected);
99+
console.error("🚨 failed to comment on some issues/prs", rejected);
111100
}
112101
}
113102

scripts/release/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cleanupRef, cleanupTagName, isNightly } from "./utils";
1+
import { cleanupRef, cleanupTagName, isNightly, isStable } from "./utils";
22

33
if (!process.env.DEFAULT_BRANCH) {
44
throw new Error("DEFAULT_BRANCH is required");
@@ -32,3 +32,4 @@ export const NIGHTLY_BRANCH = process.env.NIGHTLY_BRANCH;
3232
export const PR_FILES_STARTS_WITH = ["packages/"];
3333
export const IS_NIGHTLY_RELEASE = isNightly(VERSION);
3434
export const AWAITING_RELEASE_LABEL = "awaiting release";
35+
export const IS_STABLE_RELEASE = isStable(VERSION);

scripts/release/github.ts

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import {
77
DEFAULT_BRANCH,
88
PACKAGE_VERSION_TO_FOLLOW,
99
AWAITING_RELEASE_LABEL,
10+
IS_NIGHTLY_RELEASE,
11+
IS_STABLE_RELEASE,
1012
} from "./constants";
1113
import { gql, graphqlWithAuth, octokit } from "./octokit";
1214
import type { MinimalTag } from "./utils";
15+
import { isNightly, isStable } from "./utils";
1316
import { cleanupTagName } from "./utils";
1417
import { checkIfStringStartsWith } from "./utils";
1518

@@ -140,34 +143,32 @@ function getPreviousTagFromCurrentTag(
140143

141144
return { tag: tagName, date, isPrerelease };
142145
})
143-
.filter((v: any): v is MinimalTag => typeof v !== "undefined");
146+
.filter((v: any): v is MinimalTag => typeof v !== "undefined")
147+
.filter((tag) => {
148+
if (IS_STABLE_RELEASE) return isStable(tag.tag);
149+
let isNightlyTag = isNightly(tag.tag);
150+
if (IS_NIGHTLY_RELEASE) return isNightlyTag;
151+
return !isNightlyTag;
152+
})
153+
.sort((a, b) => {
154+
if (IS_NIGHTLY_RELEASE) {
155+
return b.date.getTime() - a.date.getTime();
156+
}
157+
158+
return semver.rcompare(a.tag, b.tag);
159+
});
144160

145161
let currentTagIndex = validTags.findIndex((tag) => tag.tag === currentTag);
146162
let currentTagInfo: MinimalTag | undefined = validTags.at(currentTagIndex);
147163
let previousTagInfo: MinimalTag | undefined;
148164

149165
if (!currentTagInfo) {
150-
throw new Error(`Could not find last tag ${currentTag}`);
151-
}
152-
153-
// if the currentTag was a stable tag, then we want to find the previous stable tag
154-
if (!currentTagInfo.isPrerelease) {
155-
validTags = validTags
156-
.filter((tag) => !tag.isPrerelease)
157-
.sort((a, b) => semver.rcompare(a.tag, b.tag));
158-
159-
currentTagIndex = validTags.findIndex((tag) => tag.tag === currentTag);
160-
currentTagInfo = validTags.at(currentTagIndex);
161-
if (!currentTagInfo) {
162-
throw new Error(`Could not find last stable tag ${currentTag}`);
163-
}
166+
throw new Error(`Could not find tag ${currentTag}`);
164167
}
165168

166169
previousTagInfo = validTags.at(currentTagIndex + 1);
167170
if (!previousTagInfo) {
168-
throw new Error(
169-
`Could not find previous prerelease tag from ${currentTag}`
170-
);
171+
throw new Error(`Could not find previous tag from ${currentTag}`);
171172
}
172173

173174
return {
@@ -232,21 +233,35 @@ interface GitHubGraphqlTag {
232233
interface GitHubGraphqlTagResponse {
233234
repository: {
234235
refs: {
236+
pageInfo: {
237+
hasNextPage: boolean;
238+
endCursor: string;
239+
};
235240
nodes: Array<GitHubGraphqlTag>;
236241
};
237242
};
238243
}
239244

240-
async function getTags(owner: string, repo: string) {
245+
async function getTags(
246+
owner: string,
247+
repo: string,
248+
endCursor?: string,
249+
nodes: Array<GitHubGraphqlTag> = []
250+
): Promise<GitHubGraphqlTag[]> {
241251
let response: GitHubGraphqlTagResponse = await graphqlWithAuth(
242252
gql`
243-
query GET_TAGS($owner: String!, $repo: String!) {
253+
query GET_TAGS($owner: String!, $repo: String!, $endCursor: String) {
244254
repository(owner: $owner, name: $repo) {
245255
refs(
246256
refPrefix: "refs/tags/"
247257
first: 100
248258
orderBy: { field: TAG_COMMIT_DATE, direction: DESC }
259+
after: $endCursor
249260
) {
261+
pageInfo {
262+
hasNextPage
263+
endCursor
264+
}
250265
nodes {
251266
name
252267
target {
@@ -267,15 +282,26 @@ async function getTags(owner: string, repo: string) {
267282
}
268283
}
269284
`,
270-
{ owner, repo }
285+
{ owner, repo, endCursor }
271286
);
272287

273-
return response.repository.refs.nodes.filter((node) => {
288+
let filtered = response.repository.refs.nodes.filter((node) => {
274289
return (
275290
node.name.startsWith(PACKAGE_VERSION_TO_FOLLOW) ||
276291
node.name.startsWith("v0.0.0-nightly-")
277292
);
278293
});
294+
295+
if (response.repository.refs.pageInfo.hasNextPage) {
296+
console.log("has next page", response.repository.refs.pageInfo.endCursor);
297+
298+
return getTags(owner, repo, response.repository.refs.pageInfo.endCursor, [
299+
...nodes,
300+
...filtered,
301+
]);
302+
}
303+
304+
return [...nodes, ...filtered];
279305
}
280306

281307
export async function getIssuesClosedByPullRequests(

scripts/release/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as semver from "semver";
2+
13
import { GITHUB_REPOSITORY, PACKAGE_VERSION_TO_FOLLOW } from "./constants";
24

35
export function checkIfStringStartsWith(
@@ -34,3 +36,7 @@ export function cleanupRef(ref: string) {
3436
export function isNightly(tagName: string) {
3537
return tagName.startsWith("v0.0.0-nightly-");
3638
}
39+
40+
export function isStable(tagName: string) {
41+
return semver.prerelease(tagName) === null;
42+
}

0 commit comments

Comments
 (0)