Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging and dispatch to rerun release workflows on tagged releases #277

Merged
merged 3 commits into from
Feb 7, 2023
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
23 changes: 17 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ name: Release

on:
workflow_dispatch:
inputs:
release-pr:
description: a release PR number to rerun release jobs on
type: string
push:
branches:
- main
Expand Down Expand Up @@ -53,7 +57,7 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx --offline template-oss-release-please ${{ github.ref_name }} ${{ github.event_name }}
npx --offline template-oss-release-please "${{ github.ref_name }}" "${{ inputs.release-pr }}"
- name: Post Pull Request Comment
if: steps.release.outputs.pr-number
uses: actions/github-script@v6
Expand All @@ -76,7 +80,7 @@ jobs:
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} -R ${owner}/${repo}\n\`\`\``
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME} -R ${owner}/${repo} -f release-pr=${issue_number}\n\`\`\``

if (commentId) {
await github.rest.issues.updateComment({ owner, repo, comment_id: commentId, body })
Expand Down Expand Up @@ -291,14 +295,17 @@ jobs:
}

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'))
.then(cs => cs.map(c => ({ id: c.id, login: c.user.login, body: c.body })))
console.log(`Found comments: ${JSON.stringify(comments, null, 2)}`)
const releaseComments = comments.filter(c => c.login === 'github-actions[bot]' && c.body.includes('Release is at'))

for (const comment of releaseComments) {
console.log(`Release comment: ${JSON.stringify(comment, null, 2)}`)
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({
await github.rest.issues.createComment({
owner,
repo,
issue_number,
Expand Down Expand Up @@ -378,10 +385,14 @@ jobs:
with:
script: |
const { PR_NUMBER: issue_number, RESULT } = process.env
const { repo: { owner, repo } } = context
const { runId, 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'))
const updateComment = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.startsWith('## Release Workflow\n\n') &&
c.body.includes(runId)
)

if (updateComment) {
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
Expand Down
4 changes: 2 additions & 2 deletions bin/release-please.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const core = require('@actions/core')
const main = require('../lib/release-please/index.js')

const dryRun = !process.env.CI
const [branch, eventName] = process.argv.slice(2)
const [branch, forcePullRequest] = process.argv.slice(2)

const debugPr = (val) => {
if (dryRun) {
Expand Down Expand Up @@ -45,7 +45,7 @@ main({
repo: process.env.GITHUB_REPOSITORY,
dryRun,
branch,
force: eventName === 'workflow_dispatch',
forcePullRequest: forcePullRequest ? +forcePullRequest : null,
}).then(({ pr, release, releases }) => {
if (pr) {
debugPr(pr)
Expand Down
23 changes: 17 additions & 6 deletions lib/content/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Release

on:
workflow_dispatch:
inputs:
release-pr:
description: a release PR number to rerun release jobs on
type: string
push:
branches:
{{#each branches}}
Expand Down Expand Up @@ -30,7 +34,7 @@ jobs:
env:
GITHUB_TOKEN: $\{{ secrets.GITHUB_TOKEN }}
run: |
{{ rootNpxPath }} --offline template-oss-release-please $\{{ github.ref_name }} $\{{ github.event_name }}
{{ rootNpxPath }} --offline template-oss-release-please "$\{{ github.ref_name }}" "$\{{ inputs.release-pr }}"
- name: Post Pull Request Comment
if: steps.release.outputs.pr-number
uses: actions/github-script@v6
Expand All @@ -53,7 +57,7 @@ jobs:
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} -R ${owner}/${repo}\n\`\`\``
body += `\`\`\`\ngh workflow run release.yml -r ${REF_NAME} -R ${owner}/${repo} -f release-pr=${issue_number}\n\`\`\``

if (commentId) {
await github.rest.issues.updateComment({ owner, repo, comment_id: commentId, body })
Expand Down Expand Up @@ -139,14 +143,17 @@ jobs:
}

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'))
.then(cs => cs.map(c => ({ id: c.id, login: c.user.login, body: c.body })))
console.log(`Found comments: ${JSON.stringify(comments, null, 2)}`)
const releaseComments = comments.filter(c => c.login === 'github-actions[bot]' && c.body.includes('Release is at'))

for (const comment of releaseComments) {
console.log(`Release comment: ${JSON.stringify(comment, null, 2)}`)
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({
await github.rest.issues.createComment({
owner,
repo,
issue_number,
Expand Down Expand Up @@ -182,10 +189,14 @@ jobs:
with:
script: |
const { PR_NUMBER: issue_number, RESULT } = process.env
const { repo: { owner, repo } } = context
const { runId, 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'))
const updateComment = comments.find(c =>
c.user.login === 'github-actions[bot]' &&
c.body.startsWith('## Release Workflow\n\n') &&
c.body.includes(runId)
)

if (updateComment) {
console.log('Found comment to update:', JSON.stringify(updateComment, null, 2))
Expand Down
Loading