Skip to content

Commit

Permalink
feat: add [skip ci] by default to commit message
Browse files Browse the repository at this point in the history
This is useful when you are working on an organizational
repository where you are passing in a custom admin token
as any pushes with this token, will cause a new build to be
scheduled.

This adds the [skip ci] instruction by default.
With an option to supress it
  • Loading branch information
asgerjensen committed May 24, 2022
1 parent d040501 commit a0bcde8
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -620,3 +620,42 @@ jobs:
else
echo "Changelog config not applied" && exit 1
fi
test-skip-ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: "./"

- run: npm ci --prod

- run: "git config --global user.email 'changelog@github.com'"
- run: "git config --global user.name 'Awesome Github action'"
- run: "git add . && git commit --allow-empty -m 'feat: Added fake file so version will be bumped'"

- name: Generate changelog
id: changelog
uses: ./
env:
ENV: 'dont-use-git'
EXPECTED_TAG: 'v1.5.0'
SKIP_CI: 'false'
with:
github-token: ${{ secrets.github_token }}
version-file: 'test-file.json'
skip-ci: 'false'

- name: Show file
run: |
echo "$(<test-file.json)"
- name: Test output
run: node ./test-output.js
env:
FILES: 'test-file.json'
EXPECTED_VERSION: '1.5.0'


1 change: 1 addition & 0 deletions README.md
Expand Up @@ -24,6 +24,7 @@ This action will bump version, tag commit and generate a changelog with conventi
- **Optional** `fallback-version`: The fallback version, if no older one can be detected, or if it is the first one. Default `'0.1.0'`
- **Optional** `config-file-path`: Path to the conventional changelog config file. If set, the preset setting will be ignored
- **Optional** `pre-changelog-generation`: Path to the pre-changelog-generation script file. No hook by default.
- **Optional** `skip-ci`: Adds instruction to github to not consider the push something to rebuild. Default `true`.

### Pre-Commit hook

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Expand Up @@ -108,6 +108,10 @@ inputs:
description: 'Path to the pre-changelog-generation script file'
required: false

skip-ci:
description: 'Adds [skip ci] to commit message, to avoid triggering a new build'
default: 'true'
required: false

outputs:
changelog:
Expand Down
8 changes: 6 additions & 2 deletions src/helpers/git.js
Expand Up @@ -161,7 +161,7 @@ module.exports = new (class Git {
*/
testHistory = () => {
if (ENV === 'dont-use-git') {
const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_PULL } = process.env
const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_PULL, SKIP_CI } = process.env

const expectedCommands = [
'git config user.name "Conventional Changelog Action"',
Expand All @@ -174,7 +174,11 @@ module.exports = new (class Git {

if (!SKIPPED_COMMIT) {
expectedCommands.push('git add .')
expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG}"`)
if (SKIP_CI === false) {
expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG}"`)
} else {
expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG} [skip ci]"`)
}
}

expectedCommands.push(`git tag -a ${EXPECTED_TAG} -m "${EXPECTED_TAG}"`)
Expand Down
7 changes: 6 additions & 1 deletion src/index.js
Expand Up @@ -25,7 +25,7 @@ async function handleVersioningByExtension(ext, file, versionPath, releaseType)

async function run() {
try {
const gitCommitMessage = core.getInput('git-message')
let gitCommitMessage = core.getInput('git-message')
const gitUserName = core.getInput('git-user-name')
const gitUserEmail = core.getInput('git-user-email')
const gitPush = core.getInput('git-push').toLowerCase() === 'true'
Expand All @@ -42,6 +42,11 @@ async function run() {
const skipEmptyRelease = core.getInput('skip-on-empty').toLowerCase() === 'true'
const conventionalConfigFile = core.getInput('config-file-path')
const preChangelogGenerationFile = core.getInput('pre-changelog-generation')
const skipCi = core.getInput('skip-ci')

if (skipCi) {
gitCommitMessage += " [skip ci]"
}

core.info(`Using "${preset}" preset`)
core.info(`Using "${gitCommitMessage}" as commit message`)
Expand Down

0 comments on commit a0bcde8

Please sign in to comment.