Skip to content

Commit

Permalink
fix: add root release and release pr to data
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jan 24, 2023
1 parent 7c8f347 commit f4ce7d2
Show file tree
Hide file tree
Showing 7 changed files with 541 additions and 104 deletions.
114 changes: 98 additions & 16 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
release:
outputs:
pr: ${{ steps.release.outputs.pr }}
release: ${{ steps.release.outputs.release }}
releases: ${{ steps.release.outputs.releases }}
release-flags: ${{ steps.release.outputs.release-flags }}
branch: ${{ steps.release.outputs.pr-branch }}
pr-number: ${{ steps.release.outputs.pr-number }}
comment-id: ${{ steps.pr-comment.outputs.result }}
Expand Down Expand Up @@ -63,26 +63,25 @@ jobs:
REF_NAME: ${{ github.ref_name }}
with:
script: |
const { REF_NAME, PR_NUMBER } = process.env
const repo = { owner: context.repo.owner, repo: context.repo.repo }
const issue = { ...repo, issue_number: PR_NUMBER }
const { REF_NAME, PR_NUMBER: issue_number } = process.env
const { runId, repo: { owner, repo } } = context
const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: context.runId })
const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
let body = '## Release Manager\n\n'
const comments = await github.paginate(github.rest.issues.listComments, issue)
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
let commentId = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`main\`. `
body += `To force CI to update this PR, run this command:\n\n`
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME}\n\`\`\``
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME} -R ${owner}/${repo}\n\`\`\``
if (commentId) {
await github.rest.issues.updateComment({ ...repo, comment_id: commentId, body })
await github.rest.issues.updateComment({ owner, repo, comment_id: commentId, body })
} else {
const { data: comment } = await github.rest.issues.createComment({ ...issue, body })
const { data: comment } = await github.rest.issues.createComment({ owner, repo, issue_number, body })
commentId = comment?.id
}
Expand Down Expand Up @@ -272,6 +271,45 @@ jobs:
name: Post Release - Release
if: github.repository_owner == 'npm' && needs.release.outputs.releases
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Create Release PR Comment
uses: actions/github-script@v6
env:
RELEASES: ${{ needs.release.outputs.releases }}
with:
script: |
const releases = JSON.parse(process.env.RELEASES)
const { runId, repo: { owner, repo } } = context
const issue_number = releases[0].prNumber
let body = '## Release Workflow\n\n'
for (const { pkgName, version, url } of releases) {
body += `- \`${pkgName}@${version}\` ${url}\n`
}
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
const releaseComments = comments.filter(c => c.user.login === 'github-actions[bot]' && c.body.includes('Release is at'))
for (const comment of releaseComments) {
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id })
}
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `${body}- Workflow run: :arrows_counterclockwise: ${runUrl}`,
})
release-integration:
needs: release
name: Release Integration
if: needs.release.outputs.release
runs-on: ubuntu-latest
defaults:
run:
shell: bash
Expand All @@ -290,10 +328,54 @@ jobs:
run: npm i --prefer-online --no-fund --no-audit -g npm@latest
- name: npm Version
run: npm -v
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Run Post Release Actions
env:
RELEASES: ${{ needs.release.outputs.releases }}
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="${{ fromJSON(needs.release.output.release).version }}"
npm view ${name}@${version}
post-release-integration:
needs: [ release, release-integration ]
name: Post Release Integration - Release
if: github.repository_owner == 'npm' && needs.release.outputs.release && always()
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Get Needs Result
id: needs-result
run: |
npm run rp-release --ignore-scripts --if-present ${{ join(fromJSON(needs.release.outputs.release-flags), ' ') }}
result=""
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="x"
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="heavy_multiplication_x"
else
result="white_check_mark"
fi
echo "::set-output name=result::$result"
- name: Update Release PR Comment
uses: actions/github-script@v6
env:
PR_NUMBER: ${{ fromJSON(needs.release.outputs.release).prNumber }}
RESULT: ${{ steps.needs-result.outputs.result }}
with:
script: |
const { PR_NUMBER: issue_number, RESULT } = process.env
const { repo: { owner, repo } } = context
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
const updateComment = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith('## Release Workflow\n\n'))
if (updateComment) {
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
await github.rest.issues.updateComment({
owner,
repo,
comment_id: updateComment.id,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
}
4 changes: 2 additions & 2 deletions bin/release-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const DEFAULT_RELEASE_PROCESS = `
Release Please will run on the just pushed release commit and create GitHub releases and tags for each package.
\`\`\`
gh run watch \`gh run list -w release -b <BASE-BRANCH> -L 1 --json databaseId -q ".[0].databaseId"\`
gh run watch \`gh run list -R {NWO} -w release -b <BASE-BRANCH> -L 1 --json databaseId -q ".[0].databaseId"\`
\`\`\`
` /* eslint-enable max-len */

Expand Down Expand Up @@ -82,7 +82,7 @@ const getReleaseProcess = async ({ owner, repo }) => {
} catch (e) {
log('Release wiki not found', e.message)
log('Using default release process')
releaseProcess = DEFAULT_RELEASE_PROCESS.trim() + '\n'
releaseProcess = DEFAULT_RELEASE_PROCESS.replace(/\{NWO\}/g, `${owner}/${repo}`).trim() + '\n'
}

// XXX: the release steps need to always be the last thing in the doc for this to work
Expand Down
21 changes: 14 additions & 7 deletions bin/release-please.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ const debugPr = (val) => {
}
}

const debugRelease = (val) => {
if (dryRun) {
console.log('ROOT RELEASE:', JSON.stringify(val, null, 2))
}
}

const debugReleases = (val) => {
if (dryRun) {
console.log('ALL RELEASES:', JSON.stringify(val, null, 2))
}
}

main({
token: process.env.GITHUB_TOKEN,
repo: process.env.GITHUB_REPOSITORY,
Expand All @@ -44,18 +56,13 @@ main({
}

if (release) {
debugRelease(release)
core.setOutput('release', JSON.stringify(release))
core.setOutput('release-path', release.path)
core.setOutput('release-version', release.version)
core.setOutput('release-tag', release.tagName)
core.setOutput('release-url', release.url)
}

if (releases) {
debugReleases(releases)
core.setOutput('releases', JSON.stringify(releases))
core.setOutput('release-flags', JSON.stringify(releases.map((r) => {
return r.path === '.' ? '-iwr' : `-w ${r.path}`
})))
}

return null
Expand Down
12 changes: 12 additions & 0 deletions lib/content/_job-release-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
{{> stepGit }}
{{> stepNode }}
- name: View in Registry
run: |
name=$(cat package.json | jq -r .name)
version="$\{{ fromJSON(needs.release.output.release).version }}"
npm view ${name}@${version}
95 changes: 82 additions & 13 deletions lib/content/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
release:
outputs:
pr: $\{{ steps.release.outputs.pr }}
release: $\{{ steps.release.outputs.release }}
releases: $\{{ steps.release.outputs.releases }}
release-flags: $\{{ steps.release.outputs.release-flags }}
branch: $\{{ steps.release.outputs.pr-branch }}
pr-number: $\{{ steps.release.outputs.pr-number }}
comment-id: $\{{ steps.pr-comment.outputs.result }}
Expand All @@ -40,26 +40,25 @@ jobs:
REF_NAME: $\{{ github.ref_name }}
with:
script: |
const { REF_NAME, PR_NUMBER } = process.env
const repo = { owner: context.repo.owner, repo: context.repo.repo }
const issue = { ...repo, issue_number: PR_NUMBER }
const { REF_NAME, PR_NUMBER: issue_number } = process.env
const { runId, repo: { owner, repo } } = context
const { data: workflow } = await github.rest.actions.getWorkflowRun({ ...repo, run_id: context.runId })
const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
let body = '## Release Manager\n\n'
const comments = await github.paginate(github.rest.issues.listComments, issue)
let commentId = comments?.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
let commentId = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith(body))?.id
body += `Release workflow run: ${workflow.html_url}\n\n#### Force CI to Update This Release\n\n`
body += `This PR will be updated and CI will run for every non-\`chore:\` commit that is pushed to \`{{ defaultBranch }}\`. `
body += `To force CI to update this PR, run this command:\n\n`
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME}\n\`\`\``
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME} -R ${owner}/${repo}\n\`\`\``
if (commentId) {
await github.rest.issues.updateComment({ ...repo, comment_id: commentId, body })
await github.rest.issues.updateComment({ owner, repo, comment_id: commentId, body })
} else {
const { data: comment } = await github.rest.issues.createComment({ ...issue, body })
const { data: comment } = await github.rest.issues.createComment({ owner, repo, issue_number, body })
commentId = comment?.id
}
Expand Down Expand Up @@ -123,9 +122,79 @@ jobs:

post-release:
needs: release
{{> job jobName="Post Release - Release" jobIf="needs.release.outputs.releases" }}
- name: Run Post Release Actions
{{> job jobName="Post Release - Release" jobIf="needs.release.outputs.releases" jobSkipSetup=true }}
- name: Create Release PR Comment
uses: actions/github-script@v6
env:
RELEASES: $\{{ needs.release.outputs.releases }}
with:
script: |
const releases = JSON.parse(process.env.RELEASES)
const { runId, repo: { owner, repo } } = context
const issue_number = releases[0].prNumber
let body = '## Release Workflow\n\n'
for (const { pkgName, version, url } of releases) {
body += `- \`${pkgName}@${version}\` ${url}\n`
}
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
const releaseComments = comments.filter(c => c.user.login === 'github-actions[bot]' && c.body.includes('Release is at'))
for (const comment of releaseComments) {
await github.rest.issues.deleteComment({ owner, repo, comment_id: comment.id })
}
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: `${body}- Workflow run: :arrows_counterclockwise: ${runUrl}`,
})
release-integration:
needs: release
name: Release Integration
if: needs.release.outputs.release
{{> jobReleaseIntegration }}

post-release-integration:
needs: [release, release-integration]
{{> job jobName="Post Release Integration - Release" jobIf="needs.release.outputs.release && always()" jobSkipSetup=true }}
- name: Get Needs Result
id: needs-result
run: |
{{ rootNpmPath }} run rp-release --ignore-scripts --if-present $\{{ join(fromJSON(needs.release.outputs.release-flags), ' ') }}
result=""
if [[ "$\{{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="x"
elif [[ "$\{{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="heavy_multiplication_x"
else
result="white_check_mark"
fi
echo "::set-output name=result::$result"
- name: Update Release PR Comment
uses: actions/github-script@v6
env:
PR_NUMBER: $\{{ fromJSON(needs.release.outputs.release).prNumber }}
RESULT: $\{{ steps.needs-result.outputs.result }}
with:
script: |
const { PR_NUMBER: issue_number, RESULT } = process.env
const { repo: { owner, repo } } = context
const comments = await github.paginate(github.rest.issues.listComments, { owner, repo, issue_number })
const updateComment = comments.find(c => c.user.login === 'github-actions[bot]' && c.body.startsWith('## Release Workflow\n\n'))
if (updateComment) {
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
await github.rest.issues.updateComment({
owner,
repo,
comment_id: updateComment.id,
body: updateComment.body.replace(/Workflow run: :[a-z_]+:/, `Workflow run: :${RESULT}:`),
})
} else {
console.log('No matching comments found:', JSON.stringify(comments, null, 2))
}
Loading

0 comments on commit f4ce7d2

Please sign in to comment.