Skip to content

Commit

Permalink
refactor: Small changes with more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 16, 2020
1 parent 2a80eb3 commit 29d9414
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 3 deletions.
36 changes: 35 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/version/base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const core = require('@actions/core')
const fs = require('fs')

module.exports = class BaseVersioning {
Expand Down Expand Up @@ -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 ''
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/version/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions src/version/toml.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const core = require('@actions/core')
const objectPath = require('object-path')
const toml = require('@iarna/toml')

Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions test-file.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
title = "test"
version = "1.4.5"

# Comment
[package]
Expand Down

0 comments on commit 29d9414

Please sign in to comment.