Draft release on release branch push #127
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Draft release on release branch push | |
on: create | |
jobs: | |
draft_release_notes: | |
if: github.event.ref_type == 'branch' && startsWith('${{ github.event.ref }}', 'bump_to_version_') | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get release version | |
id: releaseVersion | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
return '${{ github.event.ref }}'.substring('bump_to_version_'.length); | |
- name: Get milestone for version | |
id: milestone | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
const milestones = await github.paginate(github.rest.issues.listMilestones, { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'all' | |
}) | |
const milestone = milestones.find(milestone => milestone.title == '${{steps.releaseVersion.outputs.result}}') | |
if (milestone) { | |
return milestone.number | |
} else { | |
return null | |
} | |
- name: Generate release notes | |
if: fromJSON(steps.milestone.outputs.result) | |
id: generate | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
result-encoding: string | |
script: | | |
const pullRequests = await github.paginate(github.rest.pulls.list, { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'closed', | |
base: 'main' | |
}) | |
var draftText = "> Please categorize the following changes:\n\n" | |
for (let pull of pullRequests) { | |
if (pull.merged_at && pull.milestone && pull.milestone.number == ${{steps.milestone.outputs.result}}) { | |
// Skip PR with only `dev/*` labels, as these represent internal changes | |
if (pull.labels.length > 0 && pull.labels.every(label => label.name.startsWith("dev/"))) { | |
continue | |
} | |
// Add labels to description, to ease categorization | |
var lineItem = "* " | |
for (let label of pull.labels) { | |
lineItem += label.name.charAt(0).toUpperCase() + label.name.slice(1) + ": " | |
} | |
lineItem += pull.title + " (#" + pull.number + ")" | |
// Add author if labeled as 'community' | |
if (pull.labels.some(label => label.name == "community")) { | |
lineItem += " (@" + pull.user.login + ")" | |
} | |
draftText += lineItem + "\n" | |
} | |
} | |
draftText += "\n### Added\n\n### Changed\n\n### Fixed\n\n### Removed\n\n" | |
// Escape backticks | |
draftText = draftText.replace(/`/g,"\\`") | |
return draftText | |
- name: Create draft release | |
if: fromJSON(steps.milestone.outputs.result) | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{secrets.GITHUB_TOKEN}} | |
script: | | |
await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: 'v${{ steps.releaseVersion.outputs.result }}', | |
name: '${{ steps.releaseVersion.outputs.result }}', | |
draft: true, | |
body: `${{ steps.generate.outputs.result }}` | |
}) |