refactor: Small changes with more logging
parent
2a80eb3e4a
commit
29d941434b
|
@ -184,6 +184,26 @@ jobs:
|
|||
version-file: 'test-file.yaml'
|
||||
version-path: 'package.version'
|
||||
|
||||
- name: Generate changelog
|
||||
uses: ./
|
||||
env:
|
||||
ENV: 'dont-use-git'
|
||||
EXPECTED_TAG: 'v9.6.0'
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
version-file: 'test-file.yaml'
|
||||
version-path: 'package.no-quotes-version'
|
||||
|
||||
- name: Generate changelog
|
||||
uses: ./
|
||||
env:
|
||||
ENV: 'dont-use-git'
|
||||
EXPECTED_TAG: 'v9.7.0'
|
||||
with:
|
||||
github-token: ${{ secrets.github_token }}
|
||||
version-file: 'test-file.yaml'
|
||||
version-path: 'package.double-quotes-version'
|
||||
|
||||
- name: Show file
|
||||
run: |
|
||||
echo "$(<test-file.yaml)"
|
||||
|
@ -195,6 +215,20 @@ jobs:
|
|||
EXPECTED_VERSION: '9.5.0'
|
||||
EXPECTED_VERSION_PATH: 'package.version'
|
||||
|
||||
- name: Test output
|
||||
run: node ./test-output.js
|
||||
env:
|
||||
FILES: 'test-file.yaml'
|
||||
EXPECTED_VERSION: '9.6.0'
|
||||
EXPECTED_VERSION_PATH: 'package.no-quotes-version'
|
||||
|
||||
- name: Test output
|
||||
run: node ./test-output.js
|
||||
env:
|
||||
FILES: 'test-file.yaml'
|
||||
EXPECTED_VERSION: '9.7.0'
|
||||
EXPECTED_VERSION_PATH: 'package.double-quotes-version'
|
||||
|
||||
test-yaml-new:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
@ -482,7 +516,7 @@ jobs:
|
|||
run: node ./test-output.js
|
||||
env:
|
||||
FILES: 'test-file.json, test-file.toml, test-file.yaml'
|
||||
EXPECTED_VERSION: '1.5.0, 0.1.0, 0.1.0'
|
||||
EXPECTED_VERSION: '1.5.0, 1.5.0, 1.11.0'
|
||||
|
||||
test-config-file-path:
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -15,7 +15,7 @@ async function handleVersioningByExtension(ext, file, versionPath, releaseType)
|
|||
throw new Error(`File extension "${ext}" from file "${file}" is not supported`)
|
||||
}
|
||||
|
||||
versioning.init(path.resolve(file), versionPath)
|
||||
versioning.init(path.resolve(process.cwd(), file), versionPath)
|
||||
|
||||
// Bump the version in the package.json
|
||||
await versioning.bump(releaseType)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const core = require('@actions/core')
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = class BaseVersioning {
|
||||
|
@ -25,7 +26,13 @@ module.exports = class BaseVersioning {
|
|||
* @return {string}
|
||||
*/
|
||||
read = () => {
|
||||
return fs.existsSync(this.fileLocation) ? fs.readFileSync(this.fileLocation, 'utf8') : ''
|
||||
if (fs.existsSync(this.fileLocation)) {
|
||||
return fs.readFileSync(this.fileLocation, 'utf8')
|
||||
}
|
||||
|
||||
core.warning(`Tried to read "${this.fileLocation}" but file does not exist!`)
|
||||
|
||||
return ''
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,8 @@ module.exports = new (class Json extends BaseVersioning {
|
|||
oldVersion,
|
||||
)
|
||||
|
||||
core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`)
|
||||
|
||||
// Update the content with the new version
|
||||
objectPath.set(jsonContent, this.versionPath, this.newVersion)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
const core = require('@actions/core')
|
||||
const objectPath = require('object-path')
|
||||
const toml = require('@iarna/toml')
|
||||
|
||||
|
@ -29,6 +30,8 @@ module.exports = new (class Toml extends BaseVersioning {
|
|||
// Get the name of where the version is in
|
||||
const versionName = this.versionPath.split('.').pop()
|
||||
|
||||
core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`)
|
||||
|
||||
this.update(
|
||||
// We use replace instead of yaml.stringify so we can preserve white spaces and comments
|
||||
fileContent.replace(
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
title = "test"
|
||||
version = "1.4.5"
|
||||
|
||||
# Comment
|
||||
[package]
|
||||
|
|
Loading…
Reference in New Issue