Skip to content

Commit

Permalink
ci: Updated prepare-release.js to not require changelog.json
Browse files Browse the repository at this point in the history
  • Loading branch information
bizob2828 committed Apr 1, 2024
1 parent df2a0fd commit 7785c1e
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/prep-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ on:
description: Whether or not to use the new conventional commit release note workflow
type: string
required: false
changelog_json:
description: Whether or not it should generate a changelog.json(should only be for node-newrelic)
type: boolean
required: false

jobs:
generate-release-notes:
Expand Down Expand Up @@ -47,6 +51,6 @@ jobs:
git config user.name $GITHUB_ACTOR
git config user.email gh-actions-${GITHUB_ACTOR}@github.com
- name: Create Release Notes
run: node ./agent-repo/bin/prepare-release.js --release-type ${{ inputs.release_type }} --branch ${{ github.ref }} --repo ${{ github.repository }} --changelog ${{ inputs.changelog_file }} ${{ inputs.use_new_release == 'true' && '--use-new-release' || '' }}
run: node ./agent-repo/bin/prepare-release.js --release-type ${{ inputs.release_type }} --branch ${{ github.ref }} --repo ${{ github.repository }} --changelog ${{ inputs.changelog_file }} ${{ inputs.use_new_release == 'true' && '--use-new-release' || '' }} ${{ inputs.changelog_json == true && '--changelog-json' || ''}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ jobs:
with:
release_type: ${{ github.event.inputs.release_type }}
use_new_release: ${{ vars.USE_NEW_RELEASE }}
changelog_json: true
47 changes: 30 additions & 17 deletions bin/prepare-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ program.option(
'newrelic/node-newrelic'
)
program.option('--use-new-release', 'use new conventional commit release note process')
program.option(
'--changelog-json',
'generate notes with a corresponding changelog.json(only for node-newrelic)'
)

function stopOnError(err) {
if (err) {
Expand Down Expand Up @@ -119,12 +123,13 @@ async function prepareReleaseNotes() {
let releaseData
if (options.useNewRelease) {
logStep('Create Release Notes - Conventional Commit based')
const [markdown] = await generateConventionalReleaseNotes(
const [markdown] = await generateConventionalReleaseNotes({
owner,
repo,
packageInfo.version,
options.changelog
)
newVersion: packageInfo.version,
markdownChangelog: options.changelog,
generateJsonChangelog: options.changelogJson
})
releaseData = markdown
} else {
logStep('Create Release Notes')
Expand Down Expand Up @@ -314,12 +319,21 @@ async function generateReleaseNotes(owner, repo) {
/**
* Function for generating and writing our release notes based on Conventional Commits
*
* @param {string} owner github repo org
* @param {string} repo github repo name
* @param {string} newVersion version to be published
* @param {string} markdownChangelog filepath of markdown changelog
* @param {object} params function params
* @param {string} params.owner github repo org
* @param {string} params.repo github repo name
* @param {string} params.newVersion version to be published
* @param {string} params.markdownChangelog filepath of markdown changelog
* @param {boolean} params.generateJsonChangelog indicator if it should update changelog.json
* @returns {array} generate data of markdown and json

Check warning on line 328 in bin/prepare-release.js

View workflow job for this annotation

GitHub Actions / lint (lts/*)

The type 'array' is undefined
*/
async function generateConventionalReleaseNotes(owner, repo, newVersion, markdownChangelog) {
async function generateConventionalReleaseNotes({
owner,
repo,
newVersion,
markdownChangelog,
generateJsonChangelog
}) {
const github = new Github(owner, repo)
const latestRelease = await github.getLatestRelease()

Expand All @@ -332,15 +346,14 @@ async function generateConventionalReleaseNotes(owner, repo, newVersion, markdow

const commits = await changelog.getFormattedCommits()

const [markdown, json] = await Promise.all([
changelog.generateMarkdownChangelog(commits),
changelog.generateJsonChangelog(commits)
])
const markdown = await changelog.generateMarkdownChangelog(commits)
await changelog.writeMarkdownChangelog(markdown, markdownChangelog)

await Promise.all([
changelog.writeMarkdownChangelog(markdown, markdownChangelog),
changelog.writeJsonChangelog(json)
])
let json = null
if (generateJsonChangelog) {
json = await changelog.generateJsonChangelog(commits)
await changelog.writeJsonChangelog(json)
}

return [markdown, json]
}
Expand Down
64 changes: 50 additions & 14 deletions bin/test/prepare-release.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,13 @@ tap.test('Prepare Release script', (testHarness) => {
}
mockConventionalCommands.generateJsonChangelog.resolves(expectedJson)

const [markdown, json] = await script.generateConventionalReleaseNotes(
'org',
'repo',
'2.0.0',
'changelog.json'
)
const [markdown, json] = await script.generateConventionalReleaseNotes({
owner: 'org',
repo: 'repo',
newVersion: '2.0.0',
markdownChangelog: 'NEWS.md',
generateJsonChangelog: true
})

t.same(json, expectedJson)
t.equal(markdown, expectedMarkdown)
Expand All @@ -89,16 +90,51 @@ tap.test('Prepare Release script', (testHarness) => {
t.ok(mockConventionalCommands.generateMarkdownChangelog.calledWith(expectedCommits))
t.ok(mockConventionalCommands.generateJsonChangelog.calledWith(expectedCommits))

t.ok(
mockConventionalCommands.writeMarkdownChangelog.calledWith(
expectedMarkdown,
'changelog.json'
)
)
t.ok(mockConventionalCommands.writeMarkdownChangelog.calledWith(expectedMarkdown, 'NEWS.md'))
t.ok(mockConventionalCommands.writeJsonChangelog.calledWith(expectedJson))

t.end()
})

t.test(
'should not generate json file updates when generateJsonChangelog is false',
async (t) => {
mockGithubCommands.getLatestRelease.resolves({ tag_name: 'v1.2.3' })
const expectedCommits = [{ title: 'stuff: commit number one' }]
mockConventionalCommands.getFormattedCommits.resolves(expectedCommits)
const expectedMarkdown = `
### v2.0.0
#### Stuff
* commit number 1
### v1.2.3
`
mockConventionalCommands.generateMarkdownChangelog.resolves(expectedMarkdown)
const expectedJson = {
entries: [
{ version: '2.0.0', changes: [{ type: 'stuff', subject: 'commit number one' }] },
{ version: '1.2.3', changes: [] }
]
}
mockConventionalCommands.generateJsonChangelog.resolves(expectedJson)

const [markdown, json] = await script.generateConventionalReleaseNotes({
owner: 'org',
repo: 'repo',
newVersion: '2.0.0',
markdownChangelog: 'NEWS.md'
})

t.same(json, undefined)
t.equal(markdown, expectedMarkdown)

t.ok(mockConventionalCommands.generateMarkdownChangelog.calledWith(expectedCommits))
t.ok(
mockConventionalCommands.writeMarkdownChangelog.calledWith(expectedMarkdown, 'NEWS.md')
)
t.equal(mockConventionalCommands.generateJsonChangelog.callCount, 0)
t.equal(mockConventionalCommands.writeJsonChangelog.callCount, 0)
}
)
})

testHarness.test('isValid', (t) => {
Expand Down

0 comments on commit 7785c1e

Please sign in to comment.