Merge pull request #144 from apr-1985/skip_git_pull

feat:Allow skipping of the Git pull before tagging
releases/v3
Tycho Bokdam 2021-11-30 10:19:57 +01:00 committed by GitHub
commit f05181d095
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 63 additions and 4 deletions

View File

@ -139,6 +139,37 @@ jobs:
github-token: ${{ secrets.github_token }} github-token: ${{ secrets.github_token }}
skip-commit: 'true' 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
SKIPPED_PULL: true
with:
github-token: ${{ secrets.github_token }}
skip-commit: 'true'
skip-git-pull: 'true'
test-git-fallback: test-git-fallback:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@ -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** `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-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** `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-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-version-file`: Do not update the version file. Default `'false'`.
- **Optional** `skip-commit`: Do not create a release commit. Default `'false'`. - **Optional** `skip-commit`: Do not create a release commit. Default `'false'`.
@ -148,6 +149,22 @@ Tag only
skip-commit: "true" 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 Use a custom file for versioning
```yaml ```yaml

View File

@ -70,6 +70,11 @@ inputs:
default: 'version' default: 'version'
required: false 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: skip-on-empty:
description: 'Do nothing when the changelog from the latest release is empty' description: 'Do nothing when the changelog from the latest release is empty'
default: 'true' default: 'true'

View File

@ -161,14 +161,17 @@ module.exports = new (class Git {
*/ */
testHistory = () => { testHistory = () => {
if (ENV === 'dont-use-git') { 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 = [ const expectedCommands = [
'git config user.name "Conventional Changelog Action"', 'git config user.name "Conventional Changelog Action"',
'git config user.email "conventional.changelog.action@github.com"', '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) { if (!SKIPPED_COMMIT) {
expectedCommands.push('git add .') expectedCommands.push('git add .')
expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG}"`) expectedCommands.push(`git commit -m "chore(release): ${EXPECTED_TAG}"`)

View File

@ -36,6 +36,7 @@ async function run() {
const releaseCount = core.getInput('release-count') const releaseCount = core.getInput('release-count')
const versionFile = core.getInput('version-file') const versionFile = core.getInput('version-file')
const versionPath = core.getInput('version-path') 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 skipVersionFile = core.getInput('skip-version-file').toLowerCase() === 'true'
const skipCommit = core.getInput('skip-commit').toLowerCase() === 'true' const skipCommit = core.getInput('skip-commit').toLowerCase() === 'true'
const skipEmptyRelease = core.getInput('skip-on-empty').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 empty releases is "${skipEmptyRelease ? 'enabled' : 'disabled'}"`)
core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`) core.info(`Skipping the update of the version file is "${skipVersionFile ? 'enabled' : 'disabled'}"`)
if (!skipGitPull) {
core.info('Pull to make sure we have the full git history') core.info('Pull to make sure we have the full git history')
await git.pull() await git.pull()
}
const config = conventionalConfigFile && requireScript(conventionalConfigFile) const config = conventionalConfigFile && requireScript(conventionalConfigFile)