From a0bcde8dcf6c731817d1142609d778fd4367ae05 Mon Sep 17 00:00:00 2001 From: Asger Jensen Date: Tue, 24 May 2022 17:03:45 +0200 Subject: [PATCH] feat: add [skip ci] by default to commit message 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 --- .github/workflows/test.yml | 39 ++++++++++++++++++++++++++++++++++++++ README.md | 1 + action.yml | 4 ++++ src/helpers/git.js | 8 ++++++-- src/index.js | 7 ++++++- 5 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d3d7465..5aaef6d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 "$( { 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"', @@ -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}"`) diff --git a/src/index.js b/src/index.js index 2220c0f5..157e9e78 100644 --- a/src/index.js +++ b/src/index.js @@ -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' @@ -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`)