From 5ff4cb3443c2d1755c7489ed08e56eada44a7c0c Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Fri, 12 Nov 2021 08:41:31 +0000 Subject: [PATCH 1/9] feat:Allow skipping of the Git pull before tagging --- README.md | 17 +++++++++++++++++ action.yml | 5 +++++ src/index.js | 7 +++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index edca823..f0beb43 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This action will bump version, tag commit and generate a changelog with conventi - **Optional** `release-count`: Number of releases to preserve in changelog. Default `5`, use `0` to regenerate all. - **Optional** `version-file`: The path to the file that contains the version to bump. Default `./package.json`. - **Optional** `version-path`: The place inside the version file to bump. Default `version`. +- **Optional** `skip-git-pull`: Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags. Default `'false'`. - **Optional** `skip-on-empty`: Boolean to specify if you want to skip empty release (no-changelog generated). This case occured when you push `chore` commit with `angular` for example. Default `'true'`. - **Optional** `skip-version-file`: Do not update the version file. Default `'false'`. - **Optional** `skip-commit`: Do not create a release commit. Default `'false'`. @@ -148,6 +149,22 @@ Tag only skip-commit: "true" ``` +Skip Git Pull +In CI you might not want to pull extra changes before tagging e.g. if running a long build before tagging, another commit may have come into the branch which would get pulled leading to tagging a different commit to the one which was built. + +```yaml +- name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + +- name: Conventional Changelog Action + uses: TriPSs/conventional-changelog-action@v3 + with: + github-token: ${{ secrets.github_token }} + skip-git-pull: "true" +``` + Use a custom file for versioning ```yaml diff --git a/action.yml b/action.yml index 2360b2c..354f3ed 100644 --- a/action.yml +++ b/action.yml @@ -70,6 +70,11 @@ inputs: default: 'version' required: false + skip-git-pull: + description: 'Do not pull the repo before tagging. Ensure you full cloned the repo in the first place to get tags' + default: 'false' + required: false + skip-on-empty: description: 'Do nothing when the changelog from the latest release is empty' default: 'true' diff --git a/src/index.js b/src/index.js index f36e63d..2220c0f 100644 --- a/src/index.js +++ b/src/index.js @@ -36,6 +36,7 @@ async function run() { const releaseCount = core.getInput('release-count') const versionFile = core.getInput('version-file') const versionPath = core.getInput('version-path') + const skipGitPull = core.getInput('skip-git-pull').toLowerCase() === 'true' const skipVersionFile = core.getInput('skip-version-file').toLowerCase() === 'true' const skipCommit = core.getInput('skip-commit').toLowerCase() === 'true' const skipEmptyRelease = core.getInput('skip-on-empty').toLowerCase() === 'true' @@ -64,8 +65,10 @@ async function run() { core.info(`Skipping empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`) core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`) - core.info('Pull to make sure we have the full git history') - await git.pull() + if (!skipGitPull) { + core.info('Pull to make sure we have the full git history') + await git.pull() + } const config = conventionalConfigFile && requireScript(conventionalConfigFile) From 013f0647d0d0968dcf049cca241b6fb46dfe1bcc Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Mon, 15 Nov 2021 09:12:31 +0000 Subject: [PATCH 2/9] Update test.yml --- .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07eb840..a01c46b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -138,6 +138,36 @@ jobs: with: github-token: ${{ secrets.github_token }} skip-commit: 'true' + + test-git-no-pull: + 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 tag | xargs git tag -d + - name: Create fake tag + run: "git tag -a 'v0.55.8' -m 'v0.55.8'" + - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" + + - name: Generate changelog + id: changelog + uses: ./ + env: + ENV: 'dont-use-git' + EXPECTED_TAG: 'v0.55.9' + SKIPPED_COMMIT: true + with: + github-token: ${{ secrets.github_token }} + skip-commit: 'true' + skip-git-pull: 'true' test-git-fallback: runs-on: ubuntu-latest From eb527b4b2a89a994d210a8f5791d62ac9e487136 Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Mon, 15 Nov 2021 09:15:44 +0000 Subject: [PATCH 3/9] chore: Add test case for skip-git-pull --- .github/workflows/test.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07eb840..0b9ee84 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -138,6 +138,36 @@ jobs: with: github-token: ${{ secrets.github_token }} skip-commit: 'true' + + test-git-no-pull: + 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 tag | xargs git tag -d + - name: Create fake tag + run: "git tag -a 'v0.55.8' -m 'v0.55.8'" + - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" + + - name: Generate changelog + id: changelog + uses: ./ + env: + ENV: 'dont-use-git' + EXPECTED_TAG: 'v0.55.9' + SKIPPED_COMMIT: true + with: + github-token: ${{ secrets.github_token }} + skip-commit: 'true' + skip-git-pull: 'true' test-git-fallback: runs-on: ubuntu-latest From 865880cdc6f4a140053206cecbe3bfbfbc2ec0ea Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Mon, 15 Nov 2021 09:17:27 +0000 Subject: [PATCH 4/9] chore: run test job --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a01c46b..e464627 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,8 @@ name: 'Test the action' on: + push: + branches: + - skip_git_pull-1 pull_request: branches: - master From ac4ebd34bbfd83c3fd4393281995c052760ea02c Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Mon, 15 Nov 2021 09:34:08 +0000 Subject: [PATCH 5/9] chore: allow test to work --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e464627..7de2cd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -129,6 +129,7 @@ jobs: - run: git tag | xargs git tag -d - name: Create fake tag run: "git tag -a 'v0.55.8' -m 'v0.55.8'" + - run: "echo 'askjfhsadjkfh' > banana.txt" - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" - name: Generate changelog From 73e939a72d7ef53558280f4644f2dc5b2ef8aaa3 Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Mon, 15 Nov 2021 09:35:39 +0000 Subject: [PATCH 6/9] chore: fix my test --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7de2cd0..4f861ea 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -159,6 +159,7 @@ jobs: - run: git tag | xargs git tag -d - name: Create fake tag run: "git tag -a 'v0.55.8' -m 'v0.55.8'" + - run: "echo 'askjfhsadjkfh' > banana.txt" - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" - name: Generate changelog From 5c73ddeb477eb532bc4443dba1b773fef9e9a0c8 Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Wed, 17 Nov 2021 10:11:43 +0000 Subject: [PATCH 7/9] chore: test breaking the expectedCommands --- src/helpers/git.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/git.js b/src/helpers/git.js index f77058f..80679d5 100644 --- a/src/helpers/git.js +++ b/src/helpers/git.js @@ -166,7 +166,7 @@ module.exports = new (class Git { const expectedCommands = [ 'git config user.name "Conventional Changelog Action"', 'git config user.email "conventional.changelog.action@github.com"', - 'git pull --tags --ff-only', + 'git upll --tags --ff-only', ] if (!SKIPPED_COMMIT) { From a85ab5798acc7142b08c485b6d55dd33c835ac77 Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Wed, 17 Nov 2021 10:13:42 +0000 Subject: [PATCH 8/9] chore: revert change to expectedCommands --- src/helpers/git.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/git.js b/src/helpers/git.js index 80679d5..f77058f 100644 --- a/src/helpers/git.js +++ b/src/helpers/git.js @@ -166,7 +166,7 @@ module.exports = new (class Git { const expectedCommands = [ 'git config user.name "Conventional Changelog Action"', 'git config user.email "conventional.changelog.action@github.com"', - 'git upll --tags --ff-only', + 'git pull --tags --ff-only', ] if (!SKIPPED_COMMIT) { From c9222a9423dd92ce64b0cfc8408bdd7902dbb2a7 Mon Sep 17 00:00:00 2001 From: apr-1985 Date: Wed, 17 Nov 2021 10:33:20 +0000 Subject: [PATCH 9/9] chore: Test expectedCommands for skipping git pulls --- .github/workflows/test.yml | 6 +----- src/helpers/git.js | 7 +++++-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f861ea..eddf199 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,8 +1,5 @@ name: 'Test the action' on: - push: - branches: - - skip_git_pull-1 pull_request: branches: - master @@ -129,7 +126,6 @@ jobs: - run: git tag | xargs git tag -d - name: Create fake tag run: "git tag -a 'v0.55.8' -m 'v0.55.8'" - - run: "echo 'askjfhsadjkfh' > banana.txt" - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" - name: Generate changelog @@ -159,7 +155,6 @@ jobs: - run: git tag | xargs git tag -d - name: Create fake tag run: "git tag -a 'v0.55.8' -m 'v0.55.8'" - - run: "echo 'askjfhsadjkfh' > banana.txt" - run: "git add . && git commit -m 'fix: Added fake file so version will be bumped'" - name: Generate changelog @@ -169,6 +164,7 @@ jobs: ENV: 'dont-use-git' EXPECTED_TAG: 'v0.55.9' SKIPPED_COMMIT: true + SKIPPED_PULL: true with: github-token: ${{ secrets.github_token }} skip-commit: 'true' diff --git a/src/helpers/git.js b/src/helpers/git.js index f77058f..b35cf0c 100644 --- a/src/helpers/git.js +++ b/src/helpers/git.js @@ -161,14 +161,17 @@ module.exports = new (class Git { */ testHistory = () => { if (ENV === 'dont-use-git') { - const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH } = process.env + const { EXPECTED_TAG, SKIPPED_COMMIT, EXPECTED_NO_PUSH, SKIPPED_PULL } = process.env const expectedCommands = [ 'git config user.name "Conventional Changelog Action"', 'git config user.email "conventional.changelog.action@github.com"', - 'git pull --tags --ff-only', ] + if (!SKIPPED_PULL) { + expectedCommands.push('git pull --tags --ff-only') + } + if (!SKIPPED_COMMIT) { expectedCommands.push('git add .') expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG}"`)