refactor: Small changes with more logging

releases/v3
Tycho Bokdam 2020-12-16 16:32:53 +01:00
parent 2a80eb3e4a
commit 29d941434b
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
6 changed files with 50 additions and 3 deletions

View File

@ -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

View File

@ -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)

View File

@ -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 ''
}
/**

View File

@ -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)

View File

@ -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(

View File

@ -1,4 +1,5 @@
title = "test"
version = "1.4.5"
# Comment
[package]