Prepare infra meeting notes as release #119
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: "Prepare infra meeting notes as release" | |
on: | |
workflow_dispatch: | |
inputs: | |
milestone_id: | |
description: '"Current" milestone id to prepare as release' | |
required: true | |
type: string | |
milestone_name: | |
description: '"Current" milestone name' | |
required: true | |
default: 'current' | |
type: string | |
next_milestone_id: | |
description: '"Next" milestone id' | |
required: true | |
# "permanent" 'next' milestone: https://github.com/jenkins-infra/helpdesk/milestone/10 | |
default: '10' | |
type: string | |
next_milestone_name: | |
description: '"Next" milestone name' | |
required: true | |
default: 'next' | |
type: string | |
jobs: | |
release: | |
name: "Prepare infra meeting notes as release" | |
runs-on: "ubuntu-latest" | |
steps: | |
- name: "Get current date" | |
id: date | |
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT | |
- name: "Generate markdown from current and next milestone" | |
id: milestones_as_markdown | |
uses: actions/github-script@v6 | |
with: | |
result-encoding: string | |
script: | | |
const getMilestoneAsMarkdown = async function(milestone, milestoneName, issuesState, closeReason) { | |
const opts = github.rest.issues.listForRepo.endpoint.merge({ | |
...context.issue, | |
milestone, | |
state: issuesState, | |
sort: 'created', | |
direction: 'desc', | |
per_page: 100, | |
}) | |
const issues = await github.paginate(opts) | |
let markdown = '' | |
let category = (closeReason == 'completed') ? 'Done' : 'Closed as not planned' | |
let query = '?closed=1' | |
// There should not be any closed issue in the 'next' milestone, only 'Done' ones | |
if (issuesState == 'open') { | |
category = (milestoneName != 'next') ? 'Work In Progress' : 'Backlog' | |
if (milestoneName == 'todo') category = 'TODO (next milestone)' | |
query = '' | |
} | |
title = `* [${category}](${context.payload.repository.html_url}/milestone/${milestone}${query}):` | |
if (issues.length > 0) { | |
for (const issue of issues) { | |
if ((issuesState == 'open') || ((issuesState == 'closed') && (issue.state_reason == closeReason))){ | |
markdown = markdown.concat("\r\n").concat(` * [${issue.title}](${issue.html_url})`) | |
} | |
} | |
} | |
if (markdown != '') markdown = title.concat("\r\n").concat(markdown) | |
return markdown | |
} | |
done = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'closed', 'completed') | |
notPlanned = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'closed', 'not_planned') | |
wip = await getMilestoneAsMarkdown(context.payload.inputs.milestone_id, context.payload.inputs.milestone_name, 'open', '') | |
try { | |
todoMilestone = parseInt(context.payload.inputs.milestone_id) + 1 | |
todo = await getMilestoneAsMarkdown(todoMilestone, 'todo', 'open', '') | |
} catch (error) { | |
console.error(error); | |
todo = '' | |
} | |
next = await getMilestoneAsMarkdown(context.payload.inputs.next_milestone_id, context.payload.inputs.next_milestone_name, 'open', '') | |
return `Markdown for the infra team sync meeting notes preparation: | |
<pre><code> | |
${done} | |
${notPlanned} | |
${wip} | |
${next} | |
</code></pre> | |
<details><summary>Preview:</summary> | |
${done} | |
* New items: | |
* placeholder 1 | |
* placeholder 2 | |
${wip} | |
${todo} | |
<!-- | |
${next} | |
--> | |
</details> | |
Generated from the ["${context.payload.inputs.milestone_name}"](${context.payload.repository.html_url}/milestone/${context.payload.inputs.milestone_id}) and the ["${context.payload.inputs.next_milestone_name}"](${context.payload.repository.html_url}/milestone/${context.payload.inputs.next_milestone_id}) milestones.` | |
- name: "Create release" | |
id: create_release | |
uses: actions/github-script@v6 | |
env: | |
CURRENT_DATE: ${{ steps.date.outputs.date }} | |
RELEASE_BODY: ${{steps.milestones_as_markdown.outputs.result}} | |
with: | |
script: | | |
name = `infra-team-sync-${process.env.CURRENT_DATE}` | |
tag = `${name}_${context.runNumber}` | |
try { | |
await github.rest.repos.createRelease({ | |
name: name, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: process.env.RELEASE_BODY, | |
tag_name: tag, | |
draft: true, | |
generate_release_notes: true, | |
prerelease: false, | |
}); | |
} catch (error) { | |
core.setFailed(error.message); | |
} |