From c0f41727e6b6df5561d358a6bb0aaded9c25da61 Mon Sep 17 00:00:00 2001 From: Egor Kurnev Date: Mon, 14 Dec 2020 18:56:21 +0300 Subject: [PATCH] fix: Tag name can also be changed in pre-changelog-generation --- .github/workflows/test.yml | 6 +++--- README.md | 4 ++-- src/index.js | 7 +++++-- test/pre-changelog-generation.js | 10 ++++++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca4957f..a3234b9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -95,7 +95,7 @@ jobs: uses: actions/checkout@v2 with: path: "./" - - run: test -f test-version && (echo should not be here yet && exit 1) || exit 0 + - run: test -f pre-changelog-generation.test.json && (echo should not be here yet && exit 1) || exit 0 - name: Generate changelog id: changelog uses: ./ @@ -107,8 +107,8 @@ jobs: version-file: './test-file.toml' skip-on-empty: 'false' - - run: test -f test-version || (echo should be here && exit 1) - - run: cat test-version + - run: test -f pre-changelog-generation.test.json || (echo should be here && exit 1) + - run: cat pre-changelog-generation.test.json test-git: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index f8f213f..6ca34c8 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ A bunch of useful environment variables are available to the script with `proces Same restrictions as for the pre-commit hook, but exported function name should be `preChangelogGeneration` -Following props will be passed to the function as a single parameter and string output with version is expected: +Following props will be passed to the function as a single parameter and same output is expected: ```typescript interface Props { @@ -67,7 +67,7 @@ interface Props { version: string; // Next version e.g. 1.12.3 } -export function preChangelogGeneration(props: Props): string {} +export function preChangelogGeneration(props: Props): Props {} ``` ### Config-File-Path diff --git a/src/index.js b/src/index.js index 13b7211..ddeca49 100644 --- a/src/index.js +++ b/src/index.js @@ -110,13 +110,16 @@ async function run() { newVersion = versioning[0].newVersion } - const gitTag = `${tagPrefix}${newVersion}` + let gitTag = `${tagPrefix}${newVersion}` if (preChangelogGeneration) { - newVersion = await require(path.resolve(preChangelogGeneration)).preChangelogGeneration({ + const newVersionAndTag = await require(path.resolve(preChangelogGeneration)).preChangelogGeneration({ tag: gitTag, version: newVersion, }) + + gitTag = newVersionAndTag.tag + newVersion = newVersionAndTag.version } // Generate the string changelog diff --git a/test/pre-changelog-generation.js b/test/pre-changelog-generation.js index 8f1561a..762518e 100644 --- a/test/pre-changelog-generation.js +++ b/test/pre-changelog-generation.js @@ -9,8 +9,14 @@ exports.preChangelogGeneration = (props) => { t.ok(props.version, 'version should not be empty') const newVersion = '1.0.100' + const newTag = 'v1.0.100' - fs.writeFileSync('test-version', newVersion) + const body = { + version: newVersion, + tag: newTag, + } - return newVersion + fs.writeFileSync('pre-changelog-generation.test.json', JSON.stringify(body, null, 2)) + + return body }