Skip to content

Commit

Permalink
feat: add option to customize the pushed branch
Browse files Browse the repository at this point in the history
  • Loading branch information
dhpagani committed May 31, 2022
1 parent 9b8c94a commit 2a7cc0e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,7 @@ This action will bump version, tag commit and generate a changelog with conventi
- **Optional** `git-user-email`: The git user.email to use for the commit. Default `conventional.changelog.action@github.com`
- **Optional** `git-pull-method`: The git pull method used when pulling all changes from remote. Default `--ff-only`
- **Optional** `git-push`: Push all the GIT changes. Default `true`
- **Optional** `git-branch`: The branch used to push. Default is the current branch (`${{ github.ref }}`)
- **Optional** `preset`: Preset that is used from conventional commits. Default `angular`.
- **Optional** `tag-prefix`: Prefix for the git tags. Default `v`.
- **Optional** `output-file`: File to output the changelog to. Default `CHANGELOG.md`, when providing `'false'` no file will be generated / updated.
Expand Down Expand Up @@ -129,6 +130,7 @@ Overwrite everything
skip-on-empty: 'false'
skip-version-file: 'false'
skip-commit: 'false'
git-branch: 'my-maintenance-branch'
```

No file changelog
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Expand Up @@ -41,6 +41,11 @@ inputs:
default: 'true'
required: false

git-branch:
description: 'The git branch to be pushed'
default: ${{ github.ref }}
required: false

preset:
description: 'The preset from Conventional Changelog to use'
default: 'angular'
Expand Down
8 changes: 3 additions & 5 deletions src/helpers/git.js
Expand Up @@ -2,9 +2,7 @@ const core = require('@actions/core')
const exec = require('@actions/exec')
const assert = require('assert')

const { GITHUB_REPOSITORY, GITHUB_REF, ENV } = process.env

const branch = GITHUB_REF.replace('refs/heads/', '')
const { GITHUB_REPOSITORY, ENV } = process.env

module.exports = new (class Git {

Expand Down Expand Up @@ -122,7 +120,7 @@ module.exports = new (class Git {
*
* @return {Promise<>}
*/
push = () => (
push = (branch) => (
this.exec(`push origin ${branch} --follow-tags`)
)

Expand Down Expand Up @@ -160,7 +158,7 @@ module.exports = new (class Git {
/**
* Validates the commands run
*/
testHistory = () => {
testHistory = (branch) => {
if (ENV === 'dont-use-git') {
const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_PULL, SKIP_CI } = process.env

Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Expand Up @@ -29,6 +29,7 @@ async function run() {
const gitUserName = core.getInput('git-user-name')
const gitUserEmail = core.getInput('git-user-email')
const gitPush = core.getBooleanInput('git-push')
const gitBranch = core.getInput('git-branch')
const tagPrefix = core.getInput('tag-prefix')
const preset = !core.getInput('config-file-path') ? core.getInput('preset') : ''
const preCommitFile = core.getInput('pre-commit')
Expand Down Expand Up @@ -61,6 +62,7 @@ async function run() {
core.info(`Using "${outputFile}" as output file`)
core.info(`Using "${conventionalConfigFile}" as config file`)
core.info(`Using "${gitUrl}" as gitUrl`)
core.info(`Using "${gitBranch}" as gitBranch`)

if (preCommitFile) {
core.info(`Using "${preCommitFile}" as pre-commit script`)
Expand Down Expand Up @@ -187,7 +189,7 @@ async function run() {
if (gitPush) {
try {
core.info('Push all changes')
await git.push()
await git.push(gitBranch)

} catch (error) {
console.error(error)
Expand Down Expand Up @@ -221,7 +223,7 @@ async function run() {

try {
// If we are running in test mode we use this to validate everything still runs
git.testHistory()
git.testHistory(gitBranch)

} catch (error) {
console.error(error)
Expand Down

0 comments on commit 2a7cc0e

Please sign in to comment.