Skip to content

Commit dfbdadc

Browse files
committed
fix: properly recreate release PR when run via workflow_dispatch
1 parent cb8ee8a commit dfbdadc

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ jobs:
7474
const comments = await github.paginate(github.rest.issues.listComments, issue)
7575
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
7676
77-
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Rerun for This Release\n\n`
77+
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
7878
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`main\`. `
79-
body += `To force CI to rerun, run this command:\n\n`
79+
body += `To force CI to update this PR, run this command:\n\n`
8080
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME}\n\`\`\``
8181
8282
if (commentId) {

lib/content/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ jobs:
5151
const comments = await github.paginate(github.rest.issues.listComments, issue)
5252
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
5353
54-
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Rerun for This Release\n\n`
55-
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`main\`. `
56-
body += `To force CI to rerun, run this command:\n\n`
54+
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
55+
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{{ defaultBranch }}\`. `
56+
body += `To force CI to update this PR, run this command:\n\n`
5757
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME}\n\`\`\``
5858
5959
if (commentId) {

lib/release-please/index.js

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,47 @@ const main = async ({ repo: fullRepo, token, dryRun, branch, force }) => {
2929
.filter(([k, v]) => k.startsWith('RELEASE_PLEASE_') && v != null)
3030
.map(([k, v]) => [k.replace('RELEASE_PLEASE_', ''), v])
3131

32+
const baseBranch = branch ?? github.repository.defaultBranch
33+
3234
const manifest = await RP.Manifest.fromManifest(
3335
github,
34-
branch ?? github.repository.defaultBranch,
36+
baseBranch,
3537
undefined,
3638
undefined,
3739
Object.fromEntries(manifestOverrides)
3840
)
3941

40-
let pullRequests = []
41-
let allReleases = []
4242
if (force) {
43-
// If we are forcing the release CI to run again, then we get
44-
// the release PR from the repo and return it, which will trigger
45-
// the rest of the steps in the workflow to run
46-
const prNumber = await github.octokit.issues.listForRepo({
43+
const { data: releasePrs } = await github.octokit.pulls.list({
4744
owner,
4845
repo,
49-
labels: 'autorelease: pending',
50-
per_page: 1,
51-
}).then(res => res.data[0]?.number)
52-
if (prNumber) {
53-
pullRequests = await github.octokit.pulls.get({
54-
owner,
55-
repo,
56-
pull_number: prNumber,
57-
}).then(res => [{
58-
...res.data,
59-
headBranchName: res.data.head.ref,
60-
updates: [],
61-
}])
46+
head: `release-please--branches--${baseBranch}`,
47+
})
48+
49+
if (releasePrs.length !== 1) {
50+
throw new Error(`Found ${releasePrs.length} matching PRs, expected 1`)
6251
}
63-
} else {
64-
pullRequests = await (dryRun ? manifest.buildPullRequests() : manifest.createPullRequests())
65-
allReleases = await (dryRun ? manifest.buildReleases() : manifest.createReleases())
52+
53+
const [releasePr] = releasePrs
54+
const id = process.env.GITHUB_RUN_ID
55+
? `by https://github.com/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`
56+
: `manually starting at ${new Date().toJSON()}`
57+
58+
// XXX(hack): to get release please to recreate a pull request it needs
59+
// to have a different body string so we append a message a message that CI
60+
// is running. This will force release-please to rebase the PR but it
61+
// wont update the body again, so we only append to it.
62+
await github.octokit.pulls.update({
63+
owner,
64+
repo,
65+
pull_number: releasePr.number,
66+
body: `${releasePr.body.trim()}\n- This PR is being recreated ${id}`,
67+
})
6668
}
6769

70+
const pullRequests = await (dryRun ? manifest.buildPullRequests() : manifest.createPullRequests())
71+
const allReleases = await (dryRun ? manifest.buildReleases() : manifest.createReleases())
72+
6873
// We only ever get a single pull request with our current release-please settings
6974
const rootPr = pullRequests.filter(Boolean)?.[0]
7075
if (rootPr?.number) {

tap-snapshots/test/apply/source-snapshots.js.test.cjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,9 @@ jobs:
828828
const comments = await github.paginate(github.rest.issues.listComments, issue)
829829
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
830830
831-
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Rerun for This Release/n/n\`
831+
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Update This Release/n/n\`
832832
body += \`This PR will be updated and CI will run for every non-/\`chore:/\` commit that is pushed to /\`main/\`. \`
833-
body += \`To force CI to rerun, run this command:/n/n\`
833+
body += \`To force CI to update this PR, run this command:/n/n\`
834834
body += \`/\`/\`/\`/ngh workflow run release.yml -r \${REF_NAME}/n/\`/\`/\`\`
835835
836836
if (commentId) {
@@ -2298,9 +2298,9 @@ jobs:
22982298
const comments = await github.paginate(github.rest.issues.listComments, issue)
22992299
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
23002300
2301-
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Rerun for This Release/n/n\`
2301+
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Update This Release/n/n\`
23022302
body += \`This PR will be updated and CI will run for every non-/\`chore:/\` commit that is pushed to /\`main/\`. \`
2303-
body += \`To force CI to rerun, run this command:/n/n\`
2303+
body += \`To force CI to update this PR, run this command:/n/n\`
23042304
body += \`/\`/\`/\`/ngh workflow run release.yml -r \${REF_NAME}/n/\`/\`/\`\`
23052305
23062306
if (commentId) {
@@ -3611,9 +3611,9 @@ jobs:
36113611
const comments = await github.paginate(github.rest.issues.listComments, issue)
36123612
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
36133613
3614-
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Rerun for This Release/n/n\`
3614+
body += \`Release workflow run: \${workflow.html_url}/n/n#### Force CI to Update This Release/n/n\`
36153615
body += \`This PR will be updated and CI will run for every non-/\`chore:/\` commit that is pushed to /\`main/\`. \`
3616-
body += \`To force CI to rerun, run this command:/n/n\`
3616+
body += \`To force CI to update this PR, run this command:/n/n\`
36173617
body += \`/\`/\`/\`/ngh workflow run release.yml -r \${REF_NAME}/n/\`/\`/\`\`
36183618
36193619
if (commentId) {

0 commit comments

Comments
 (0)