feat(yml): Added support for no quotes and double quotes

releases/v3
Tycho Bokdam 2020-12-16 16:32:28 +01:00
parent b985fd640a
commit 2a80eb3e4a
No known key found for this signature in database
GPG Key ID: A0FAE77C8CDF33C7
2 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,4 @@
const core = require('@actions/core')
const objectPath = require('object-path')
const yaml = require('yaml')
@ -29,11 +30,20 @@ module.exports = new (class Yaml 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
// Replace if version was used with single quotes
fileContent.replace(
`${versionName}: '${oldVersion}'`,
`${versionName}: '${this.newVersion}'`,
).replace( // Replace if version was used with double quotes
`${versionName}: "${oldVersion}"`,
`${versionName}: "${this.newVersion}"`,
).replace( // Replace if version was used with no quotes
`${versionName}: ${oldVersion}`,
`${versionName}: ${this.newVersion}`,
),
)
} else {

View File

@ -1,5 +1,9 @@
version: '1.10.50'
package:
version: '9.4.5'
no-quotes-version: 9.5.50
double-quotes-version: "9.6.33"
# Comment
different: