feat: Allow to specify custom tags which override auto generated ones

releases/v3
Egor Kurnev 2020-12-14 18:09:04 +03:00
parent efc77805a0
commit 8f6aa1969f
5 changed files with 92 additions and 13 deletions

View File

@ -87,6 +87,28 @@ jobs:
- run: test -f pre-commit.test.json || (echo should be here && exit 1) - run: test -f pre-commit.test.json || (echo should be here && exit 1)
- run: cat pre-commit.test.json - run: cat pre-commit.test.json
test-pre-changelog-generation:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
path: "./"
- run: test -f test-version && (echo should not be here yet && exit 1) || exit 0
- name: Generate changelog
id: changelog
uses: ./
env:
ENV: 'dont-use-git'
with:
github-token: ${{ secrets.github_token }}
pre-changelog-generation: test/pre-changelog-generation.js
version-file: './test-file.toml'
skip-on-empty: 'false'
- run: test -f test-version || (echo should be here && exit 1)
- run: cat test-version
test-git: test-git:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

View File

@ -52,6 +52,24 @@ export function preCommit(props: Props): void {}
A bunch of useful environment variables are available to the script with `process.env`. See [docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables) to learn more. A bunch of useful environment variables are available to the script with `process.env`. See [docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables) to learn more.
### Pre-Changelog-Generation hook
> Function in a specified file will be run right before the changelog generation phase, when the next
> version is already known, but it was not used anywhere yet. It can be useful if you want to manually update version or tag.
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:
```typescript
interface Props {
tag: string; // Next tag e.g. v1.12.3
version: string; // Next version e.g. 1.12.3
}
export function preChangelogGeneration(props: Props): string {}
```
### Config-File-Path ### Config-File-Path
A config file to define the conventional commit settings. Use it if you need to override values like `issuePrefix` or `issueUrlFormat`. If you set a `config-file-path`, the `preset` setting will be ignored. Therefore use an existing config and override the values you want to adjust. A config file to define the conventional commit settings. Use it if you need to override values like `issuePrefix` or `issueUrlFormat`. If you set a `config-file-path`, the `preset` setting will be ignored. Therefore use an existing config and override the values you want to adjust.
@ -206,6 +224,9 @@ $ act -j multiple-files -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s
# To run / config file path test # To run / config file path test
$ act -j test-config-file-path -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token $ act -j test-config-file-path -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
# To run pre-changelog-generation test
$ act -j test-pre-changelog-generation -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
``` ```
## [License](./LICENSE) ## [License](./LICENSE)

View File

@ -91,6 +91,10 @@ inputs:
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 required: false
pre-changelog-generation:
description: 'Path to the pre-changelog-generation script file'
required: false
outputs: outputs:
changelog: changelog:

View File

@ -39,6 +39,7 @@ async function run() {
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'
const conventionalConfigFile = core.getInput('config-file-path') const conventionalConfigFile = core.getInput('config-file-path')
const preChangelogGeneration = core.getInput('pre-changelog-generation')
core.info(`Using "${preset}" preset`) core.info(`Using "${preset}" preset`)
core.info(`Using "${gitCommitMessage}" as commit message`) core.info(`Using "${gitCommitMessage}" as commit message`)
@ -55,13 +56,17 @@ async function run() {
core.info(`Using "${preCommit}" as pre-commit script`) core.info(`Using "${preCommit}" as pre-commit script`)
} }
if (preChangelogGeneration) {
core.info(`Using "${preChangelogGeneration}" as pre-changelog-generation script`)
}
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'}"`)
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 && require(resolve(process.cwd(), conventionalConfigFile)); const config = conventionalConfigFile && require(resolve(process.cwd(), conventionalConfigFile))
conventionalRecommendedBump({ preset, tagPrefix, config }, async (error, recommendation) => { conventionalRecommendedBump({ preset, tagPrefix, config }, async (error, recommendation) => {
if (error) { if (error) {
@ -82,23 +87,37 @@ async function run() {
// skipVersionFile can mean there is no version file and skipCommit can mean that the user // skipVersionFile can mean there is no version file and skipCommit can mean that the user
// is only interested in tags // is only interested in tags
if (skipVersionFile || skipCommit) { if (skipVersionFile || skipCommit) {
core.info('Using GIT to determine the new version'); core.info('Using GIT to determine the new version')
const versioning = await handleVersioningByExtension('git', versionFile, versionPath, recommendation.releaseType) const versioning = await handleVersioningByExtension(
'git',
versionFile,
versionPath,
recommendation.releaseType
)
newVersion = versioning.newVersion newVersion = versioning.newVersion
} else { } else {
const files = versionFile.split(',').map(f => f.trim()) const files = versionFile.split(',').map((f) => f.trim())
core.info(`Files to bump: ${files.join(', ')}`) core.info(`Files to bump: ${files.join(', ')}`)
const versioning = await Promise.all(files.map((file) => { const versioning = await Promise.all(
const fileExtension = file.split('.').pop() files.map((file) => {
core.info(`Bumping version to file "${file}" with extension "${fileExtension}"`) const fileExtension = file.split('.').pop()
return handleVersioningByExtension(fileExtension, file, versionPath, recommendation.releaseType) core.info(`Bumping version to file "${file}" with extension "${fileExtension}"`)
})); return handleVersioningByExtension(fileExtension, file, versionPath, recommendation.releaseType)
})
)
newVersion = versioning[0].newVersion newVersion = versioning[0].newVersion
} }
const gitTag = `${tagPrefix}${newVersion}`
if (preChangelogGeneration) {
newVersion = await require(path.resolve(preChangelogGeneration)).preChangelogGeneration({
tag: gitTag,
version: newVersion,
})
}
// Generate the string changelog // Generate the string changelog
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config) const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config)
@ -122,8 +141,6 @@ async function run() {
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config) await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config)
} }
const gitTag = `${tagPrefix}${newVersion}`
if (!skipCommit) { if (!skipCommit) {
// Add changed files to git // Add changed files to git
if (preCommit) { if (preCommit) {
@ -153,7 +170,6 @@ async function run() {
core.setOutput('tag', gitTag) core.setOutput('tag', gitTag)
core.setOutput('skipped', 'false') core.setOutput('skipped', 'false')
}) })
} catch (error) { } catch (error) {
core.setFailed(error.message) core.setFailed(error.message)
} }

View File

@ -0,0 +1,16 @@
const fs = require('fs')
const t = require('assert')
exports.preChangelogGeneration = (props) => {
const { GITHUB_WORKSPACE } = process.env
t.ok(GITHUB_WORKSPACE, 'GITHUB_WORKSPACE should not be empty')
t.ok(props.tag, 'tag should not be empty')
t.ok(props.version, 'version should not be empty')
const newVersion = '1.0.100'
fs.writeFileSync('test-version', newVersion)
return newVersion
}