Skip to content

Commit

Permalink
refactor: Change mix implementation to regex matching
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Dec 28, 2023
1 parent efa2fbf commit beb05a3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 47 deletions.
40 changes: 17 additions & 23 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23639,6 +23639,9 @@ module.exports = new (class Git {
/***/ 5573:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

/**
* Skips loading of the "angular" preset as that one is compiled with this action
*/
module.exports.loadPreset = async(preset) => {
if (preset === 'angular') {
return null
Expand All @@ -23647,6 +23650,10 @@ module.exports.loadPreset = async(preset) => {
return preset
}

/**
* Loads the "angular" preset, so it works with ncc compiled dist, if user provided own config
* that one will be used instead
*/
module.exports.loadPresetConfig = async(preset, providedConfig = {}) => {
if (providedConfig && typeof providedConfig === 'object') {
return providedConfig
Expand Down Expand Up @@ -23888,9 +23895,6 @@ module.exports = class Json extends BaseVersioning {
/***/ 2254:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

const exec = __nccwpck_require__(2173)
const path = __nccwpck_require__(1017)

const BaseVersioning = __nccwpck_require__(4165)
const bumpVersion = __nccwpck_require__(7365)

Expand All @@ -23901,34 +23905,24 @@ module.exports = class Mix extends BaseVersioning {
* @param {!string} releaseType - The type of release
* @return {*}
*/
bump = async (releaseType) => {
// elixir is very structured and assumes a specific file name (mix.exs)
const mixDirectory = path.dirname(this.fileLocation)

let execOutput = ''
const options = {
cwd: mixDirectory,
listeners: {
stdout: (data) => {
execOutput += data.toString()
},
},
}
bump = async(releaseType) => {
// Read the file
const fileContent = this.read()

const exitCode = await exec.exec(`mix run -e "IO.puts Mix.Project.config()[:version]"`, null, options)
const [_, oldVersion] = fileContent.match(/version: "([0-9.]+)"/i)
this.oldVersion = oldVersion

if (exitCode !== 0) {
throw new Error(`Failed to extract mix project version exited with code ${exitCode}.`)
if (!this.oldVersion) {
throw new Error(`Failed to extract mix project version.`)
}

this.oldVersion = execOutput.trim()
console.log(this.oldVersion)

this.newVersion = await bumpVersion(
releaseType,
this.oldVersion,
this.oldVersion
)

const fileContent = this.read()
this.update(
fileContent.replace(`version: "${this.oldVersion}"`, `version: "${this.newVersion}"`)
)
Expand Down Expand Up @@ -34357,7 +34351,7 @@ const { loadPreset, loadPresetConfig } = __nccwpck_require__(5573)
async function handleVersioningByExtension(ext, file, versionPath, releaseType) {
const versioning = getVersioning(ext)

// File type not supported
// File type isn't supported
if (versioning === null) {
throw new Error(`File extension "${ext}" from file "${file}" is not supported`)
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { loadPreset, loadPresetConfig } = require('./helpers/load-preset')
async function handleVersioningByExtension(ext, file, versionPath, releaseType) {
const versioning = getVersioning(ext)

// File type not supported
// File type isn't supported
if (versioning === null) {
throw new Error(`File extension "${ext}" from file "${file}" is not supported`)
}
Expand Down
31 changes: 8 additions & 23 deletions src/version/mix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
const exec = require('@actions/exec')
const path = require('path')

const BaseVersioning = require('./base')
const bumpVersion = require('../helpers/bumpVersion')

Expand All @@ -11,34 +8,22 @@ module.exports = class Mix extends BaseVersioning {
* @param {!string} releaseType - The type of release
* @return {*}
*/
bump = async (releaseType) => {
// elixir is very structured and assumes a specific file name (mix.exs)
const mixDirectory = path.dirname(this.fileLocation)

let execOutput = ''
const options = {
cwd: mixDirectory,
listeners: {
stdout: (data) => {
execOutput += data.toString()
},
},
}
bump = async(releaseType) => {
// Read the file
const fileContent = this.read()

const exitCode = await exec.exec(`mix run -e "IO.puts Mix.Project.config()[:version]"`, null, options)
const [_, oldVersion] = fileContent.match(/version: "([0-9.]+)"/i)
this.oldVersion = oldVersion

if (exitCode !== 0) {
throw new Error(`Failed to extract mix project version exited with code ${exitCode}.`)
if (!this.oldVersion) {
throw new Error(`Failed to extract mix project version.`)
}

this.oldVersion = execOutput.trim()

this.newVersion = await bumpVersion(
releaseType,
this.oldVersion,
this.oldVersion
)

const fileContent = this.read()
this.update(
fileContent.replace(`version: "${this.oldVersion}"`, `version: "${this.newVersion}"`)
)
Expand Down

0 comments on commit beb05a3

Please sign in to comment.