commit
4debc6bc75
|
@ -87,6 +87,27 @@ jobs:
|
|||
- run: test -f pre-commit.test.json || (echo should be here && exit 1)
|
||||
- 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 pre-changelog-generation.test.json && (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'
|
||||
|
||||
- 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:
|
||||
|
|
21
README.md
21
README.md
|
@ -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.
|
||||
|
||||
### 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 same output 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): Props {}
|
||||
```
|
||||
|
||||
### 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.
|
||||
|
||||
|
@ -206,6 +224,9 @@ $ act -j multiple-files -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s
|
|||
|
||||
# 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
|
||||
|
||||
# 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)
|
||||
|
|
|
@ -91,6 +91,10 @@ inputs:
|
|||
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'
|
||||
required: false
|
||||
|
||||
|
||||
outputs:
|
||||
changelog:
|
||||
|
|
|
@ -1410,9 +1410,9 @@
|
|||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"ini": {
|
||||
"version": "1.3.5",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz",
|
||||
"integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw=="
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz",
|
||||
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew=="
|
||||
},
|
||||
"interpret": {
|
||||
"version": "1.4.0",
|
||||
|
|
|
@ -127,7 +127,12 @@ module.exports = new (class Git {
|
|||
isShallow = async () => {
|
||||
const isShallow = await this.exec('rev-parse --is-shallow-repository')
|
||||
|
||||
return isShallow.trim().replace('\n', '') === 'true'
|
||||
// isShallow does not return anything on local machine
|
||||
if (isShallow) {
|
||||
return isShallow.trim().replace('\n', '') === 'true'
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
50
src/index.js
50
src/index.js
|
@ -5,7 +5,6 @@ const path = require('path')
|
|||
const getVersioning = require('./version')
|
||||
const git = require('./helpers/git')
|
||||
const changelog = require('./helpers/generateChangelog')
|
||||
const resolve = require('path').resolve
|
||||
|
||||
async function handleVersioningByExtension(ext, file, versionPath, releaseType) {
|
||||
const versioning = getVersioning(ext)
|
||||
|
@ -39,6 +38,7 @@ async function run() {
|
|||
const skipCommit = core.getInput('skip-commit').toLowerCase() === 'true'
|
||||
const skipEmptyRelease = core.getInput('skip-on-empty').toLowerCase() === 'true'
|
||||
const conventionalConfigFile = core.getInput('config-file-path')
|
||||
const preChangelogGeneration = core.getInput('pre-changelog-generation')
|
||||
|
||||
core.info(`Using "${preset}" preset`)
|
||||
core.info(`Using "${gitCommitMessage}" as commit message`)
|
||||
|
@ -55,13 +55,17 @@ async function run() {
|
|||
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 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()
|
||||
|
||||
const config = conventionalConfigFile && require(resolve(process.cwd(), conventionalConfigFile));
|
||||
const config = conventionalConfigFile && require(path.resolve(process.cwd(), conventionalConfigFile))
|
||||
|
||||
conventionalRecommendedBump({ preset, tagPrefix, config }, async (error, recommendation) => {
|
||||
if (error) {
|
||||
|
@ -82,23 +86,42 @@ async function run() {
|
|||
// skipVersionFile can mean there is no version file and skipCommit can mean that the user
|
||||
// is only interested in tags
|
||||
if (skipVersionFile || skipCommit) {
|
||||
core.info('Using GIT to determine the new version');
|
||||
const versioning = await handleVersioningByExtension('git', versionFile, versionPath, recommendation.releaseType)
|
||||
core.info('Using GIT to determine the new version')
|
||||
const versioning = await handleVersioningByExtension(
|
||||
'git',
|
||||
versionFile,
|
||||
versionPath,
|
||||
recommendation.releaseType
|
||||
)
|
||||
newVersion = versioning.newVersion
|
||||
|
||||
} else {
|
||||
const files = versionFile.split(',').map(f => f.trim())
|
||||
const files = versionFile.split(',').map((f) => f.trim())
|
||||
core.info(`Files to bump: ${files.join(', ')}`)
|
||||
|
||||
const versioning = await Promise.all(files.map((file) => {
|
||||
const fileExtension = file.split('.').pop()
|
||||
core.info(`Bumping version to file "${file}" with extension "${fileExtension}"`)
|
||||
return handleVersioningByExtension(fileExtension, file, versionPath, recommendation.releaseType)
|
||||
}));
|
||||
const versioning = await Promise.all(
|
||||
files.map((file) => {
|
||||
const fileExtension = file.split('.').pop()
|
||||
core.info(`Bumping version to file "${file}" with extension "${fileExtension}"`)
|
||||
return handleVersioningByExtension(fileExtension, file, versionPath, recommendation.releaseType)
|
||||
})
|
||||
)
|
||||
|
||||
newVersion = versioning[0].newVersion
|
||||
}
|
||||
|
||||
let gitTag = `${tagPrefix}${newVersion}`
|
||||
|
||||
if (preChangelogGeneration) {
|
||||
const newVersionAndTag = await require(path.resolve(process.cwd(), preChangelogGeneration)).preChangelogGeneration({
|
||||
tag: gitTag,
|
||||
version: newVersion,
|
||||
})
|
||||
|
||||
if (newVersionAndTag) {
|
||||
if (newVersionAndTag.tag) gitTag = newVersionAndTag.tag
|
||||
if (newVersionAndTag.version) newVersion = newVersionAndTag.version
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the string changelog
|
||||
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1, config)
|
||||
|
@ -122,12 +145,10 @@ async function run() {
|
|||
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount, config)
|
||||
}
|
||||
|
||||
const gitTag = `${tagPrefix}${newVersion}`
|
||||
|
||||
if (!skipCommit) {
|
||||
// Add changed files to git
|
||||
if (preCommit) {
|
||||
await require(path.resolve(preCommit)).preCommit({
|
||||
await require(path.resolve(process.cwd(), preCommit)).preCommit({
|
||||
tag: gitTag,
|
||||
version: newVersion,
|
||||
})
|
||||
|
@ -153,7 +174,6 @@ async function run() {
|
|||
core.setOutput('tag', gitTag)
|
||||
core.setOutput('skipped', 'false')
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
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'
|
||||
const newTag = 'v1.0.100'
|
||||
|
||||
const body = {
|
||||
version: newVersion,
|
||||
tag: newTag,
|
||||
}
|
||||
|
||||
fs.writeFileSync('pre-changelog-generation.test.json', JSON.stringify(body, null, 2))
|
||||
|
||||
return body
|
||||
}
|
Loading…
Reference in New Issue