Skip to content

Commit

Permalink
[#1] release notes by github release notes
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Nov 9, 2021
1 parent c5b7152 commit 3a9560d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
19 changes: 14 additions & 5 deletions .github/actions/markdown-template-engine-action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,23 @@ const run = async () => {
await git.push('origin', version)
}

const githubRelease = await GithubRelease.make()
const email = githubRelease.getAuthorEmail()
const authorName = githubRelease.getAuthorName()
let githubRelease = await GithubRelease.make()
let engine
let email
let authorName
if (githubRelease) {
email = githubRelease.getAuthorEmail()
authorName = githubRelease.getAuthorName()
engine = new TemplateEngine(template, githubRelease)
} else {
email = '41898282+github-actions[bot]@users.noreply.github.com'
authorName = 'github-actions[bot]'
githubRelease = await ReleaseNotes.makeByLatestGithubReleaseNotes()
engine = new TemplateEngine(template, githubRelease)
}
core.info(`email: ${email}, authorName: ${authorName}`)

const engine = new TemplateEngine(template)
const markdownContent = await engine.markdownContent(githubRelease)

const disableChanges = core.getInput('disable_sync_changes')
if (disableChanges.length == 0) {
fs.outputFileSync(templateMarkdownFile, markdownContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class GithubRelease {

static async make() {
const envClientPayload = core.getInput('client_payload')
if (!envClientPayload) {
return
}
const payload = envClientPayload.length > 0 ? JSON.parse(envClientPayload) : github.context.payload['client_payload']
const { data } = await axios.get(`https://api.github.com/users/${payload.username}`)
return new GithubRelease(payload, { name: data.name, email: `${payload.username}@users.noreply.github.com` })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

const axios = require('axios')
const GithubRelease = require('./github-release')

const whatsNewTempate = `# What's New in v__VERSION__
__BODY__
Expand Down Expand Up @@ -35,6 +36,18 @@ class ReleaseNotes {
return version.startsWith('v') ? version.substring(1) : version
}

static async makeByLatestGithubReleaseNotes() {
const { data } = await axios.get(`https://api.github.com/repos/pinpoint-apm/pinpoint/releases/latest`)
const tagName = ReleaseNotes.tagName(data.tag_name)
const latestReleaseNotes = whatsNewTempate.replace('__VERSION__', tagName)
.replace('__BODY__', data.body)
return makeLatestReleaseNotes(new GithubRelease({
release: {

}
}))
}

static makeOfMarkdownContents(contents) {
const match = /# What's New in v(?<version>[0-9.]+)/gm.exec(contents)
if (!match) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ const MarkdownContents = require('./markdown-contents')
const ReleaseNotes = require('./release-notes')

class TemplateEngine {
constructor(template) {
constructor(template, releaseNotes) {
this.template = template
this.releaseNotes = releaseNotes
}

// https://regex101.com/r/Sgd2aq/1/
async markdownContent(release) {
let tagExpression = /<!--\s<(?!\/)(?<markdownfile>.*.md)>\s-->\n/gm
let tag
Expand All @@ -41,7 +41,7 @@ const githubs = {
valueOfFilename: async function (filename, release) {
switch (filename) {
case 'latestReleaseNotes.md':
return ReleaseNotes.makeLatestReleaseNotes(release).contents
return this.releaseNotes.contents
default:
return (await MarkdownContents.makeMarkdownContentsFromPinpointReadme(filename)).contents
}
Expand Down

0 comments on commit 3a9560d

Please sign in to comment.