fix: Use fallback if it's not a valid JSON-File

releases/v3
Jayrgo 2020-08-11 20:30:55 +02:00
parent 9a324dbd51
commit 97f1bb3543
No known key found for this signature in database
GPG Key ID: 498EE77E1F8E0A1E
5 changed files with 22 additions and 1 deletions

View File

@ -51,6 +51,8 @@ jobs:
with:
path: "./"
- run: touch ./test-file-empty.json
- name: Generate changelog
id: changelog
uses: ./
@ -147,6 +149,8 @@ jobs:
with:
path: "./"
- run: touch ./test-file-empty.yaml
- name: Generate changelog
id: changelog
uses: ./
@ -225,6 +229,8 @@ jobs:
with:
path: "./"
- run: touch ./test-file-empty.toml
- name: Generate changelog
id: changelog
uses: ./

View File

@ -1,3 +1,4 @@
const core = require('@actions/core')
const objectPath = require('object-path')
const BaseVersioning = require('./base')
@ -14,7 +15,21 @@ module.exports = new (class Json extends BaseVersioning {
bump = (releaseType) => {
// Read the file
const fileContent = this.read()
const jsonContent = JSON.parse(fileContent)
// Parse the file
let jsonContent
try {
jsonContent = JSON.parse(fileContent)
} catch (error) {
core.startGroup(`Error when parsing the file '${this.fileLocation}'`)
core.info(`File-Content: ${fileContent}`)
core.info(error) // should be 'warning' ?
core.endGroup()
jsonContent = {}
}
// Get the old version
const oldVersion = objectPath.get(jsonContent, this.versionPath, null)
// Get the new version