From e63e00c563bd7191db28f0e8c5308adc2bd840c6 Mon Sep 17 00:00:00 2001 From: Patrick Dreker Date: Wed, 23 Nov 2022 10:13:36 +0100 Subject: [PATCH 1/3] fix: honour pre-release flag for default version if there is no previous version and no explicit fallback version is specified emit a pre-release version (0.1.0-rc.0 by default) if the pre-release flag is true. --- README.md | 2 +- src/helpers/bumpVersion.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index df5b69e..a4e584b 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This action will bump version, tag commit and generate a changelog with conventi - **Optional** `skip-version-file`: Do not update the version file. Default `'false'`. - **Optional** `skip-commit`: Do not create a release commit. Default `'false'`. - **Optional** `pre-commit`: Path to the pre-commit script file. No hook by default. -- **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** `fallback-version`: The fallback version, if no older one can be detected, or if it is the first one. Default `'0.1.0'`. If `pre-release`is set to `true` it will default to the configured pre-release format (i.e. `'0.1.0-rc.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`. diff --git a/src/helpers/bumpVersion.js b/src/helpers/bumpVersion.js index 3155303..fb78487 100644 --- a/src/helpers/bumpVersion.js +++ b/src/helpers/bumpVersion.js @@ -25,7 +25,7 @@ module.exports = async (releaseType, version) => { newVersion = version } else { // default - newVersion = '0.1.0' + newVersion = (prerelease ? `0.1.0-${identifier}.0` : '0.1.0') } core.info(`The version could not be detected, using fallback version '${newVersion}'.`) From fc4c16dd9b531599647b491bd1bbb118f6cd24c6 Mon Sep 17 00:00:00 2001 From: Patrick Dreker Date: Wed, 23 Nov 2022 14:02:43 +0100 Subject: [PATCH 2/3] fix: add testcase for new + pre-release --- .github/workflows/test.yml | 304 +++++++++++++++++++++---------------- 1 file changed, 169 insertions(+), 135 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 427305f..07b4762 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: 'Test the action' +name: "Test the action" on: pull_request: branches: @@ -24,11 +24,11 @@ jobs: id: changelog uses: ./ env: - ENV: 'dont-use-git' - EXPECTED_TAG: 'v1.5.0' + ENV: "dont-use-git" + EXPECTED_TAG: "v1.5.0" with: github-token: ${{ secrets.github_token }} - version-file: 'test-file.json' + version-file: "test-file.json" - name: Show file run: | @@ -38,7 +38,7 @@ jobs: run: node ./test-github-output.js env: TAG: ${{ steps.changelog.outputs.tag }} - EXPECTED_TAG: 'v1.5.0' + EXPECTED_TAG: "v1.5.0" test-json: runs-on: ubuntu-latest @@ -58,11 +58,11 @@ jobs: id: changelog uses: ./ env: - ENV: 'dont-use-git' - EXPECTED_TAG: 'v1.5.0' + ENV: "dont-use-git" + EXPECTED_TAG: "v1.5.0" with: github-token: ${{ secrets.github_token }} - version-file: 'test-file.json' + version-file: "test-file.json" - name: Show file run: | @@ -71,8 +71,8 @@ jobs: - name: Test output run: node ./test-output.js env: - FILES: 'test-file.json' - EXPECTED_VERSION: '1.5.0' + FILES: "test-file.json" + EXPECTED_VERSION: "1.5.0" test-json-new: runs-on: ubuntu-latest @@ -92,11 +92,11 @@ jobs: id: changelog uses: ./ env: - ENV: 'dont-use-git' - EXPECTED_TAG: 'v0.1.0' + ENV: "dont-use-git" + EXPECTED_TAG: "v0.1.0" with: github-token: ${{ secrets.github_token }} - version-file: 'test-file-new.json' + version-file: "test-file-new.json" - name: Show file run: | @@ -105,8 +105,43 @@ jobs: - name: Test output run: node ./test-output.js env: - FILES: 'test-file-new.json' - EXPECTED_VERSION: '0.1.0' + FILES: "test-file-new.json" + EXPECTED_VERSION: "0.1.0" + + test-json-new-prerelease: + 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: "v0.1.0-rc.0" + with: + github-token: ${{ secrets.github_token }} + version-file: "test-file-new-prerelease.json" + pre-release: true + + - name: Show file + run: | + echo "$( Date: Wed, 23 Nov 2022 14:56:33 +0100 Subject: [PATCH 3/3] fix: simplify logic fallback version logic, remove default from action.yaml --- action.yml | 121 ++++++++++++++++++------------------- src/helpers/bumpVersion.js | 11 ++-- 2 files changed, 67 insertions(+), 65 deletions(-) diff --git a/action.yml b/action.yml index 3d0ba37..15aac91 100644 --- a/action.yml +++ b/action.yml @@ -1,156 +1,155 @@ -name: 'Conventional Changelog Action' -description: 'Bump version, tag commit and generates changelog with conventional commits.' -author: 'Tycho Bokdam' +name: "Conventional Changelog Action" +description: "Bump version, tag commit and generates changelog with conventional commits." +author: "Tycho Bokdam" runs: - using: 'node16' - main: 'src/index.js' + using: "node16" + main: "src/index.js" branding: - icon: 'edit' - color: 'red' + icon: "edit" + color: "red" inputs: github-token: - description: 'Github token' + description: "Github token" default: ${{ github.token }} required: false git-message: - description: 'Commit message to use' - default: 'chore(release): {version}' + description: "Commit message to use" + default: "chore(release): {version}" required: false git-user-name: - description: 'The git user.name to use for the commit' - default: 'Conventional Changelog Action' + description: "The git user.name to use for the commit" + default: "Conventional Changelog Action" required: false git-user-email: - description: 'The git user.email to use for the commit' - default: 'conventional.changelog.action@github.com' + description: "The git user.email to use for the commit" + default: "conventional.changelog.action@github.com" required: false git-pull-method: - description: 'The git pull method used when pulling all changes from remote' - default: '--ff-only' + description: "The git pull method used when pulling all changes from remote" + default: "--ff-only" required: false git-push: - description: 'Should all the git changes be push' - default: 'true' + description: "Should all the git changes be push" + default: "true" required: false git-branch: - description: 'The git branch to be pushed' + description: "The git branch to be pushed" default: ${{ github.ref }} required: false preset: - description: 'The preset from Conventional Changelog to use' - default: 'angular' + description: "The preset from Conventional Changelog to use" + default: "angular" required: false tag-prefix: - description: 'Prefix that is used for the git tag' - default: 'v' + description: "Prefix that is used for the git tag" + default: "v" required: false output-file: - description: 'File to output the changelog to' - default: 'CHANGELOG.md' + description: "File to output the changelog to" + default: "CHANGELOG.md" required: false release-count: - description: 'Number of releases to preserve in changelog' - default: '5' + description: "Number of releases to preserve in changelog" + default: "5" required: false version-file: - description: 'The path to the file that contains the version to bump (supports comma-separated list of file paths)' - default: './package.json' + description: "The path to the file that contains the version to bump (supports comma-separated list of file paths)" + default: "./package.json" required: false version-path: - description: 'The place inside the version file to bump' - default: 'version' + description: "The place inside the version file to bump" + 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' + 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' + description: "Do nothing when the changelog from the latest release is empty" + default: "true" required: false skip-version-file: - description: 'Do not update the version file' - default: 'false' + description: "Do not update the version file" + default: "false" required: false skip-commit: - description: 'Do create a release commit' - default: 'false' + description: "Do create a release commit" + default: "false" required: false pre-commit: - description: 'Path to the pre-commit script file' + description: "Path to the pre-commit script file" required: false fallback-version: - description: 'The fallback version, if no older one can be detected, or if it is the first one' - default: '0.1.0' + description: "The fallback version, if no older one can be detected, or if it is the first one" required: false config-file-path: - description: 'Path to the conventional changelog config file. If set, the preset setting will be ignored' + description: "Path to the conventional changelog config file. If set, the preset setting will be ignored" required: false pre-changelog-generation: - description: 'Path to the pre-changelog-generation script file' + description: "Path to the pre-changelog-generation script file" required: false git-url: - description: 'Git Url' - default: 'github.com' + description: "Git Url" + default: "github.com" required: false git-path: - description: 'Path filter for the logs. If set, only commits that match the path filter will be considered' - default: '' + description: "Path filter for the logs. If set, only commits that match the path filter will be considered" + default: "" required: false skip-ci: - description: 'Adds [skip ci] to commit message, to avoid triggering a new build' - default: 'true' + description: "Adds [skip ci] to commit message, to avoid triggering a new build" + default: "true" required: false create-summary: - description: 'Adds the generated changelog as Action Summary' - default: 'false' + description: "Adds the generated changelog as Action Summary" + default: "false" required: false pre-release: - description: 'Marks the release as pre-release' - default: 'false' + description: "Marks the release as pre-release" + default: "false" required: false pre-release-identifier: - description: 'The identifier to use for pre-releases' - default: 'rc' + description: "The identifier to use for pre-releases" + default: "rc" required: false outputs: changelog: - description: 'The generated changelog for the new version' + description: "The generated changelog for the new version" clean_changelog: - description: 'The generated changelog for the new version without the version name in it' + description: "The generated changelog for the new version without the version name in it" version: - description: 'The new version' + description: "The new version" tag: - description: 'The name of the generated tag' + description: "The name of the generated tag" skipped: - description: 'boolean to check if this step have been skipped' + description: "boolean to check if this step have been skipped" diff --git a/src/helpers/bumpVersion.js b/src/helpers/bumpVersion.js index fb78487..c310491 100644 --- a/src/helpers/bumpVersion.js +++ b/src/helpers/bumpVersion.js @@ -19,11 +19,14 @@ module.exports = async (releaseType, version) => { if (version) { newVersion = semver.inc(version, (prerelease ? 'prerelease' : releaseType), identifier) } else { - let version = semver.valid(core.getInput('fallback-version')) - if (version) { - newVersion = version - } else { + const fallbackVersion = core.getInput('fallback-version') + + if (fallbackVersion) { + newVersion = semver.valid(fallbackVersion) + } + + if (!newVersion) { // default newVersion = (prerelease ? `0.1.0-${identifier}.0` : '0.1.0') }