Merge pull request #44 from thedigbee/feature/support-comma-separated-version-file-paths
Feature/support comma separated version file pathsreleases/v3
commit
ca16f2de01
|
@ -96,3 +96,20 @@ jobs:
|
||||||
github-token: ${{ secrets.github_token }}
|
github-token: ${{ secrets.github_token }}
|
||||||
version-file: 'test-file.toml'
|
version-file: 'test-file.toml'
|
||||||
version-path: 'package.version'
|
version-path: 'package.version'
|
||||||
|
|
||||||
|
test-multiple-files:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
path: "./"
|
||||||
|
|
||||||
|
- name: Generate changelog
|
||||||
|
id: changelog
|
||||||
|
uses: ./
|
||||||
|
env:
|
||||||
|
ENV: 'dont-use-git'
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.github_token }}
|
||||||
|
version-file: 'package.json, package-lock.json'
|
||||||
|
|
|
@ -172,6 +172,9 @@ $ act -j test-toml -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s gith
|
||||||
|
|
||||||
# To run pre-commit test
|
# To run pre-commit test
|
||||||
$ act -j test-pre-commit -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
$ act -j test-pre-commit -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||||
|
|
||||||
|
# To run / multiple files test
|
||||||
|
$ act -j multiple-files -P ubuntu-latest=nektos/act-environments-ubuntu:18.04 -s github_token=fake-token
|
||||||
```
|
```
|
||||||
|
|
||||||
## [License](./LICENSE)
|
## [License](./LICENSE)
|
||||||
|
|
|
@ -55,7 +55,7 @@ inputs:
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
version-file:
|
version-file:
|
||||||
description: 'The path to the file that contains the version to bump'
|
description: 'The path to the file that contains the version to bump (supports comma-separated list of file paths)'
|
||||||
default: './package.json'
|
default: './package.json'
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
|
|
57
src/index.js
57
src/index.js
|
@ -6,6 +6,22 @@ const getVersioning = require('./version')
|
||||||
const git = require('./helpers/git')
|
const git = require('./helpers/git')
|
||||||
const changelog = require('./helpers/generateChangelog')
|
const changelog = require('./helpers/generateChangelog')
|
||||||
|
|
||||||
|
async function handleVersioningByExtension(ext, file, versionPath, releaseType) {
|
||||||
|
const versioning = getVersioning(ext)
|
||||||
|
|
||||||
|
// File type not supported
|
||||||
|
if (versioning === null) {
|
||||||
|
throw new Error(`File extension "${ext}" from file "${x}" is not supported`)
|
||||||
|
}
|
||||||
|
|
||||||
|
versioning.init(path.resolve(file), versionPath)
|
||||||
|
|
||||||
|
// Bump the version in the package.json
|
||||||
|
await versioning.bump(releaseType)
|
||||||
|
|
||||||
|
return versioning
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
const gitCommitMessage = core.getInput('git-message')
|
const gitCommitMessage = core.getInput('git-message')
|
||||||
|
@ -55,29 +71,32 @@ async function run() {
|
||||||
core.info(`Because: ${recommendation.reason}`)
|
core.info(`Because: ${recommendation.reason}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let newVersion
|
||||||
|
|
||||||
// If skipVersionFile or skipCommit is true we use GIT to determine the new version because
|
// If skipVersionFile or skipCommit is true we use GIT to determine the new version because
|
||||||
// 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
|
||||||
const fileExtension = skipVersionFile || skipCommit
|
if (skipVersionFile || skipCommit) {
|
||||||
? 'git'
|
core.info('Using GIT to determine the new version');
|
||||||
: versionFile.split('.').pop()
|
const versioning = await handleVersioningByExtension('git', versionFile, versionPath, recommendation.releaseType)
|
||||||
|
newVersion = versioning.newVersion
|
||||||
|
|
||||||
const versioning = getVersioning(fileExtension)
|
} else {
|
||||||
|
const files = versionFile.split(',').map(f => f.trim())
|
||||||
|
core.info(`Files to bump: ${files.join(', ')}`)
|
||||||
|
|
||||||
// File type not supported
|
const versioning = await Promise.all(files.map((file) => {
|
||||||
if (versioning === null) {
|
const fileExtension = file.split('.').pop()
|
||||||
throw new Error(`File extension "${fileExtension}" from file "${versionFile}" is not supported`)
|
core.info(`Bumping version to file "${file}" with extension "${fileExtension}"`)
|
||||||
|
return handleVersioningByExtension(fileExtension, file, versionPath, recommendation.releaseType)
|
||||||
|
}));
|
||||||
|
|
||||||
|
newVersion = versioning[0].newVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
versioning.init(path.resolve(versionFile), versionPath)
|
|
||||||
|
|
||||||
// Bump the version in the package.json
|
|
||||||
await versioning.bump(
|
|
||||||
recommendation.releaseType,
|
|
||||||
)
|
|
||||||
|
|
||||||
// Generate the string changelog
|
// Generate the string changelog
|
||||||
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, versioning.newVersion, 1)
|
const stringChangelog = await changelog.generateStringChangelog(tagPrefix, preset, newVersion, 1)
|
||||||
core.info('Changelog generated')
|
core.info('Changelog generated')
|
||||||
core.info(stringChangelog)
|
core.info(stringChangelog)
|
||||||
|
|
||||||
|
@ -90,22 +109,22 @@ async function run() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`New version: ${versioning.newVersion}`)
|
core.info(`New version: ${newVersion}`)
|
||||||
|
|
||||||
// If output file === 'false' we don't write it to file
|
// If output file === 'false' we don't write it to file
|
||||||
if (outputFile !== 'false') {
|
if (outputFile !== 'false') {
|
||||||
// Generate the changelog
|
// Generate the changelog
|
||||||
await changelog.generateFileChangelog(tagPrefix, preset, versioning.newVersion, outputFile, releaseCount)
|
await changelog.generateFileChangelog(tagPrefix, preset, newVersion, outputFile, releaseCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
const gitTag = `${tagPrefix}${versioning.newVersion}`
|
const gitTag = `${tagPrefix}${newVersion}`
|
||||||
|
|
||||||
if (!skipCommit) {
|
if (!skipCommit) {
|
||||||
// Add changed files to git
|
// Add changed files to git
|
||||||
if (preCommit) {
|
if (preCommit) {
|
||||||
await require(path.resolve(preCommit)).preCommit({
|
await require(path.resolve(preCommit)).preCommit({
|
||||||
tag: gitTag,
|
tag: gitTag,
|
||||||
version: versioning.newVersion,
|
version: newVersion,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
await git.add('.')
|
await git.add('.')
|
||||||
|
@ -125,7 +144,7 @@ async function run() {
|
||||||
// Set outputs so other actions (for example actions/create-release) can use it
|
// Set outputs so other actions (for example actions/create-release) can use it
|
||||||
core.setOutput('changelog', stringChangelog)
|
core.setOutput('changelog', stringChangelog)
|
||||||
core.setOutput('clean_changelog', cleanChangelog)
|
core.setOutput('clean_changelog', cleanChangelog)
|
||||||
core.setOutput('version', versioning.newVersion)
|
core.setOutput('version', newVersion)
|
||||||
core.setOutput('tag', gitTag)
|
core.setOutput('tag', gitTag)
|
||||||
core.setOutput('skipped', 'false')
|
core.setOutput('skipped', 'false')
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue