diff --git a/src/version/base.js b/src/version/base.js index f26441f..dc341cb 100644 --- a/src/version/base.js +++ b/src/version/base.js @@ -9,6 +9,7 @@ module.exports = class BaseVersioning { newVersion = null + oldVersion = null /** * Set some basic configurations * diff --git a/src/version/git.js b/src/version/git.js index 40e95f9..4057434 100644 --- a/src/version/git.js +++ b/src/version/git.js @@ -12,12 +12,12 @@ module.exports = class Git extends BaseVersioning { const prerelease = core.getBooleanInput('pre-release') gitSemverTags({ tagPrefix, skipUnstable: !prerelease }, async (err, tags) => { - const currentVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null + this.oldVersion = tags.length > 0 ? tags.shift().replace(tagPrefix, '') : null // Get the new version this.newVersion = await bumpVersion( releaseType, - currentVersion, + oldVersion, ) // We are done diff --git a/src/version/json.js b/src/version/json.js index bc571c4..f083b67 100644 --- a/src/version/json.js +++ b/src/version/json.js @@ -30,12 +30,12 @@ module.exports = class Json extends BaseVersioning { } // Get the old version - const oldVersion = objectPath.get(jsonContent, this.versionPath, null) + this.oldVersion = objectPath.get(jsonContent, this.versionPath, null) // Get the new version this.newVersion = await bumpVersion( releaseType, - oldVersion, + this.oldVersion, ) core.info(`Bumped file "${this.fileLocation}" from "${oldVersion}" to "${this.newVersion}"`) diff --git a/src/version/toml.js b/src/version/toml.js index 699be32..a40ffc6 100644 --- a/src/version/toml.js +++ b/src/version/toml.js @@ -17,16 +17,16 @@ module.exports = class Toml extends BaseVersioning { // Read the file const fileContent = this.read() const tomlContent = toml.parse(fileContent) - const oldVersion = objectPath.get(tomlContent, this.versionPath, null) + this.oldVersion = objectPath.get(tomlContent, this.versionPath, null) // Get the new version this.newVersion = await bumpVersion( releaseType, - oldVersion, + this.oldVersion, ) // Update the file - if (oldVersion) { + if (this.oldVersion) { // Get the name of where the version is in const versionName = this.versionPath.split('.').pop() @@ -35,7 +35,7 @@ module.exports = class Toml extends BaseVersioning { this.update( // We use replace instead of yaml.stringify so we can preserve white spaces and comments fileContent.replace( - `${versionName} = "${oldVersion}"`, + `${versionName} = "${this.oldVersion}"`, `${versionName} = "${this.newVersion}"`, ), ) diff --git a/src/version/yaml.js b/src/version/yaml.js index 606c860..127f7ec 100644 --- a/src/version/yaml.js +++ b/src/version/yaml.js @@ -17,16 +17,16 @@ module.exports = class Yaml extends BaseVersioning { // Read the file const fileContent = this.read() const yamlContent = yaml.parse(fileContent) || {} - const oldVersion = objectPath.get(yamlContent, this.versionPath, null) + this.oldVersion = objectPath.get(yamlContent, this.versionPath, null) // Get the new version this.newVersion = await bumpVersion( releaseType, - oldVersion, + this.oldVersion, ) // Update the file - if (oldVersion) { + if (this.oldVersion) { // Get the name of where the version is in const versionName = this.versionPath.split('.').pop() @@ -36,13 +36,13 @@ module.exports = class Yaml extends BaseVersioning { // 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.oldVersion}'`, `${versionName}: '${this.newVersion}'`, ).replace( // Replace if version was used with double quotes - `${versionName}: "${oldVersion}"`, + `${versionName}: "${this.oldVersion}"`, `${versionName}: "${this.newVersion}"`, ).replace( // Replace if version was used with no quotes - `${versionName}: ${oldVersion}`, + `${versionName}: ${this.oldVersion}`, `${versionName}: ${this.newVersion}`, ), )