Skip to content

Commit

Permalink
feat(pr): create a release script that outputs conventional changes f…
Browse files Browse the repository at this point in the history
…or a range of commits/branches
  • Loading branch information
JoelAlphonso committed Jun 7, 2022
1 parent 382d8bd commit 1afd939
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/create-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Checkout project
uses: actions/checkout@v3
with:
persist-credentials: false
fetch-depth: 0
persist-credentials: false

- uses: bahmutov/npm-install@v1

Expand All @@ -40,7 +40,7 @@ jobs:
- name: Exrtact changelog
shell: bash
run: |
CHANGELOG=$(npx conventional-changelog --config conventional-changelog-pr.json)
CHANGELOG=$(./create-release-notes --from ${{ github.event.inputs.base }} --group)
CHANGELOG="${CHANGELOG//'%'/'%25'}"
CHANGELOG="${CHANGELOG//$'\n'/'%0A'}"
CHANGELOG="${CHANGELOG//$'\r'/'%0D'}"
Expand All @@ -58,7 +58,7 @@ jobs:
# Merge ${{ steps.extract_branch.outputs.branch }} into ${{ github.event.inputs.base }}
${{ steps.extract_changelog.outputs.changelog }}
pr_reviewer: "@locomotive-charcoal/reviewers" # Comma-separated list (no spaces)
# pr_assignee: ${{ github.event.inputs.user_name }} # Comma-separated list (no spaces)
pr_assignee: "${{ github.event.inputs.user_name }}" # Comma-separated list (no spaces)
pr_label: release,automatic-pr # Comma-separated list (no spaces)
pr_draft: false # Creates pull request as draft
pr_allow_empty: false # Creates pull request even if there are no changes
Expand Down
79 changes: 79 additions & 0 deletions create-release-notes
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env node
'use strict'

const conventionalChangelog = require('conventional-changelog')
const resolve = require('path').resolve
const _ = require('lodash')
const meow = require('meow')

const cli = meow(`
Usage
create-release-notes
Example
create-release-notes --from beta --to HEAD
Options
-g --group Group all messages under the same group. Needs to
-f, --from Commit or branch to start from when processing the release notes
-t, --to Commit or branch to end to when processing the release notes
-n, --config A filepath of your config script
Example of a config script: https://github.com/conventional-changelog/conventional-changelog/blob/master/packages/conventional-changelog-cli/test/fixtures/config.js
`, {
booleanDefault: undefined,
flags: {
config: {
alias: 'n',
type: 'string'
},
group: {
alias: 'g',
type: 'boolean'
},
from: {
type: 'string'
},
to: {
type: 'string'
},
}
})

let config;
const flags = cli.flags
let options = {};

if (flags.group) {
options.tagPrefix = 'null' // This allows us to igonre tags when generating release notes, this way we get all the changes in a single grouped release block.
}

if (flags.config) {
config = require(resolve(process.cwd(), flags.config))
} else {
config = _.merge(config, {
writerOpts: {
headerPartial: '## Changes : '
},
options: {
preset: {
name: 'conventionalcommits'
}
}
})
}

options.config = config
options = _.merge(options, config.options)

const gitRawCommitsOpts = _.merge({}, config.gitRawCommitsOpts || {})

if (flags.from) {
gitRawCommitsOpts.from = flags.from
}

if (flags.to) {
gitRawCommitsOpts.to = flags.to
}

conventionalChangelog(options, {}, gitRawCommitsOpts, config.parserOpts, config.writerOpts)
.pipe(process.stdout); // or any writable stream
4 changes: 4 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/exec": "^6.0.3",
"conventional-changelog": "^3.1.25",
"conventional-changelog-cli": "^2.2.2",
"conventional-changelog-conventionalcommits": "^5.0.0",
"cz-conventional-changelog": "^3.3.0",
Expand Down

0 comments on commit 1afd939

Please sign in to comment.