Skip to content

Commit c92a99d

Browse files
committed
ci: use current branch when gathering PRs for stable releases (remix-run#10032)
sync with remix remix-run/remix#5342 Signed-off-by: Logan McAnsh <logan@mcan.sh> (cherry picked from commit 6120207)
1 parent 1a16a50 commit c92a99d

File tree

6 files changed

+59
-48
lines changed

6 files changed

+59
-48
lines changed

.github/workflows/release-comments.yml

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ on:
66
ref:
77
required: true
88
type: string
9-
packageVersionToFollow:
9+
package_version_to_follow:
10+
required: true
11+
type: string
12+
release_branch:
1013
required: true
1114
type: string
1215

@@ -38,5 +41,5 @@ jobs:
3841
GITHUB_TOKEN: ${{ github.token }}
3942
VERSION: ${{ inputs.ref }}
4043
DEFAULT_BRANCH: "main"
41-
NIGHTLY_BRANCH: "dev"
42-
PACKAGE_VERSION_TO_FOLLOW: ${{ inputs.packageVersionToFollow }}
44+
RELEASE_BRANCH: ${{ inputs.release_branch }}
45+
PACKAGE_VERSION_TO_FOLLOW: ${{ inputs.package_version_to_follow }}

.github/workflows/release.yml

+13-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
if: github.repository == 'remix-run/react-router'
1616
runs-on: ubuntu-latest
1717
outputs:
18-
publishedPackages: ${{ steps.changesets.outputs.publishedPackages }}
18+
published_packages: ${{ steps.changesets.outputs.published_packages }}
1919
published: ${{ steps.changesets.outputs.published }}
2020
steps:
2121
- name: 🛑 Cancel Previous Runs
@@ -58,13 +58,13 @@ jobs:
5858
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN_SO_OTHER_ACTIONS_RUN }}
5959
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6060

61-
findPackage:
61+
find_package_version:
6262
name: 🦋 Find Package
6363
needs: [release]
6464
runs-on: ubuntu-latest
6565
if: github.repository == 'remix-run/react-router' && needs.release.outputs.published == 'true'
6666
outputs:
67-
package: ${{ steps.findPackage.outputs.package }}
67+
package_version: ${{ steps.find_package_version.outputs.package_version }}
6868
steps:
6969
- name: 🛑 Cancel Previous Runs
7070
uses: styfle/cancel-workflow-action@0.11.0
@@ -78,19 +78,20 @@ jobs:
7878
node-version: 16
7979
cache: "npm"
8080

81-
- id: findPackage
81+
- id: find_package_version
8282
run: |
83-
package=$(node ./scripts/release/find-release-from-changeset.js)
84-
echo "package=${package}" >> $GITHUB_OUTPUT
83+
package_version=$(node ./scripts/release/find-release-from-changeset.js)
84+
echo "package_version=${package_version}" >> $GITHUB_OUTPUT
8585
env:
86-
packageVersionToFollow: "react-router"
87-
publishedPackages: ${{ needs.release.outputs.publishedPackages }}
86+
package_version_to_follow: "react-router"
87+
published_packages: ${{ needs.release.outputs.published_packages }}
8888

8989
comment:
9090
name: 📝 Comment on related issues and pull requests
91-
if: github.repository == 'remix-run/react-router' && needs.findPackage.outputs.package != ''
92-
needs: [release, findPackage]
91+
if: github.repository == 'remix-run/react-router' && needs.find_package_version.outputs.packageVersion != ''
92+
needs: [release, find_package_version]
9393
uses: ./.github/workflows/release-comments.yml
9494
with:
95-
ref: refs/tags/${{ needs.findPackage.outputs.package }}
96-
packageVersionToFollow: "react-router"
95+
ref: refs/tags/remix@${{ needs.find_package_version.outputs.packageVersion }}
96+
package_version_to_follow: "react-router"
97+
release_branch: ${{ github.ref_name }}

scripts/release/comment.ts

+27-20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
PR_FILES_STARTS_WITH,
66
IS_STABLE_RELEASE,
77
AWAITING_RELEASE_LABEL,
8+
DRY_RUN,
89
} from "./constants";
910
import {
1011
closeIssue,
@@ -41,19 +42,21 @@ async function commentOnIssuesAndPrsAboutRelease() {
4142
for (let pr of merged) {
4243
console.log(`commenting on pr ${getGitHubUrl("pull", pr.number)}`);
4344

44-
promises.push(
45-
commentOnPullRequest({
46-
owner: OWNER,
47-
repo: REPO,
48-
pr: pr.number,
49-
version: VERSION,
50-
})
51-
);
45+
if (!DRY_RUN) {
46+
promises.push(
47+
commentOnPullRequest({
48+
owner: OWNER,
49+
repo: REPO,
50+
pr: pr.number,
51+
version: VERSION,
52+
})
53+
);
54+
}
5255

5356
let prLabels = pr.labels.map((label) => label.name);
5457
let prIsAwaitingRelease = prLabels.includes(AWAITING_RELEASE_LABEL);
5558

56-
if (IS_STABLE_RELEASE && prIsAwaitingRelease) {
59+
if (IS_STABLE_RELEASE && prIsAwaitingRelease && !DRY_RUN) {
5760
promises.push(
5861
removeLabel({ owner: OWNER, repo: REPO, issue: pr.number })
5962
);
@@ -75,20 +78,24 @@ async function commentOnIssuesAndPrsAboutRelease() {
7578
let issueUrl = getGitHubUrl("issue", issue.number);
7679
console.log(`commenting on issue ${issueUrl}`);
7780

78-
promises.push(
79-
commentOnIssue({
80-
owner: OWNER,
81-
repo: REPO,
82-
issue: issue.number,
83-
version: VERSION,
84-
})
85-
);
81+
if (!DRY_RUN) {
82+
promises.push(
83+
commentOnIssue({
84+
owner: OWNER,
85+
repo: REPO,
86+
issue: issue.number,
87+
version: VERSION,
88+
})
89+
);
90+
}
8691

8792
if (IS_STABLE_RELEASE) {
8893
console.log(`closing issue ${issueUrl}`);
89-
promises.push(
90-
closeIssue({ owner: OWNER, repo: REPO, issue: issue.number })
91-
);
94+
if (!DRY_RUN) {
95+
promises.push(
96+
closeIssue({ owner: OWNER, repo: REPO, issue: issue.number })
97+
);
98+
}
9299
}
93100
}
94101
}

scripts/release/constants.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { cleanupRef, cleanupTagName, isNightly, isStable } from "./utils";
33
if (!process.env.DEFAULT_BRANCH) {
44
throw new Error("DEFAULT_BRANCH is required");
55
}
6-
if (!process.env.NIGHTLY_BRANCH) {
7-
throw new Error("NIGHTLY_BRANCH is required");
6+
if (!process.env.RELEASE_BRANCH) {
7+
throw new Error("RELEASE_BRANCH is required");
88
}
99
if (!process.env.GITHUB_TOKEN) {
1010
throw new Error("GITHUB_TOKEN is required");
@@ -28,8 +28,9 @@ export const VERSION = cleanupTagName(cleanupRef(process.env.VERSION));
2828
export const GITHUB_TOKEN = process.env.GITHUB_TOKEN;
2929
export const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;
3030
export const DEFAULT_BRANCH = process.env.DEFAULT_BRANCH;
31-
export const NIGHTLY_BRANCH = process.env.NIGHTLY_BRANCH;
31+
export const RELEASE_BRANCH = process.env.RELEASE_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";
3535
export const IS_STABLE_RELEASE = isStable(VERSION);
36+
export const DRY_RUN = process.env.DRY_RUN === "true";

scripts/release/find-release-from-changeset.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ function findReleaseFromChangeset(publishedPackages, packageVersionToFollow) {
2727
);
2828
}
2929

30-
let result = `${found.name}@${found.version}`;
31-
console.log(result);
32-
return result;
30+
console.log(found.version);
31+
return found.version;
3332
}
3433

3534
findReleaseFromChangeset(
36-
process.env.publishedPackages,
37-
process.env.packageVersionToFollow
35+
process.env.published_packages,
36+
process.env.package_version_to_follow
3837
);

scripts/release/github.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as semver from "semver";
33

44
import {
55
PR_FILES_STARTS_WITH,
6-
NIGHTLY_BRANCH,
6+
RELEASE_BRANCH,
77
DEFAULT_BRANCH,
88
PACKAGE_VERSION_TO_FOLLOW,
99
AWAITING_RELEASE_LABEL,
@@ -54,15 +54,15 @@ export async function prsMergedSinceLastTag({
5454
let prs: Awaited<ReturnType<typeof getMergedPRsBetweenTags>> = [];
5555

5656
// if both the current and previous tags are prereleases
57-
// we can just get the PRs for the "dev" branch
58-
// but if one of them is stable, we should wind up all of them from both the main and dev branches
57+
// we can just get the PRs for the `release` branch
58+
// but if one of them is stable, we should wind up all of them from both the main and `release` branches
5959
if (currentTag.isPrerelease && previousTag.isPrerelease) {
6060
prs = await getMergedPRsBetweenTags(
6161
owner,
6262
repo,
6363
previousTag,
6464
currentTag,
65-
NIGHTLY_BRANCH
65+
RELEASE_BRANCH
6666
);
6767
} else {
6868
let [nightly, stable] = await Promise.all([
@@ -71,7 +71,7 @@ export async function prsMergedSinceLastTag({
7171
repo,
7272
previousTag,
7373
currentTag,
74-
NIGHTLY_BRANCH
74+
RELEASE_BRANCH
7575
),
7676
getMergedPRsBetweenTags(
7777
owner,

0 commit comments

Comments
 (0)