mirror of
https://github.com/erlef/setup-beam.git
synced 2026-07-31 12:10:48 +00:00
Support mise.toml (#415)
* add support for mise.toml version file type * changes from review * Keep versioning consistent * fix default value for version-file-type input * Use single `version-file`, autodetect type * Update src/setup-beam.js Co-authored-by: Paulo F. Oliveira <paulo.ferraz.oliveira@gmail.com> * Improve log output for mise version files * Rebuild dist * Run build-dist * add support for mise.toml version file type * changes from review * Keep versioning consistent * fix default value for version-file-type input * Use single `version-file`, autodetect type * Update src/setup-beam.js Co-authored-by: Paulo F. Oliveira <paulo.ferraz.oliveira@gmail.com> * Improve log output for mise version files * Rebuild dist * Run build-dist --------- Co-authored-by: Michael Ruoss <michael.ruoss@cradle.bio> Co-authored-by: Michael Ruoss <michael@michaelruoss.ch> Co-authored-by: Paulo F. Oliveira <paulo.ferraz.oliveira@gmail.com>
This commit is contained in:
co-authored by
Michael Ruoss
Michael Ruoss
Paulo F. Oliveira
parent
0f13bcf18a
commit
98c13a9ed3
+44
-16
@@ -8,10 +8,12 @@ import * as tc from '@actions/tool-cache'
|
||||
import * as semver from 'semver'
|
||||
import * as csv from 'csv-parse/sync'
|
||||
import _ from 'lodash'
|
||||
import toml from 'toml'
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
||||
|
||||
const MAX_HTTP_RETRIES = 3
|
||||
const APPS = ['erlang', 'elixir', 'gleam', 'rebar']
|
||||
|
||||
if (process.env.NODE_ENV !== 'test') {
|
||||
main().catch((err) => {
|
||||
@@ -802,28 +804,14 @@ alongside ${alternativeName}=${alternativeValue} \
|
||||
return input
|
||||
}
|
||||
|
||||
function parseVersionFile(versionFilePath0) {
|
||||
const versionFilePath = path.resolve(
|
||||
process.env.GITHUB_WORKSPACE,
|
||||
versionFilePath0,
|
||||
)
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(
|
||||
`The specified version file, ${versionFilePath0}, does not exist`,
|
||||
)
|
||||
}
|
||||
|
||||
core.startGroup(`Parsing version file at ${versionFilePath0}`)
|
||||
function parseToolVersionsFile(versionFilePath) {
|
||||
const appVersions = new Map()
|
||||
const versions = fs.readFileSync(versionFilePath, 'utf8')
|
||||
// For the time being we parse .tool-versions
|
||||
// If we ever start parsing something else, this should
|
||||
// become default in a new option named e.g. version-file-type
|
||||
versions.split(/\r?\n/).forEach((line) => {
|
||||
const appVersion = line.match(/^([^ ]+)[ ]+(ref:v?)?([^ #]+)/)
|
||||
if (appVersion) {
|
||||
const app = appVersion[1]
|
||||
if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) {
|
||||
if (APPS.includes(app)) {
|
||||
const [, , , version] = appVersion
|
||||
core.info(`Consuming ${app} at version ${version}`)
|
||||
appVersions.set(app, version)
|
||||
@@ -840,6 +828,46 @@ function parseVersionFile(versionFilePath0) {
|
||||
return appVersions
|
||||
}
|
||||
|
||||
function parseMiseTomlFile(versionFilePath) {
|
||||
const appVersions = new Map()
|
||||
const miseToml = fs.readFileSync(versionFilePath, 'utf8')
|
||||
const miseTomlParsed = toml.parse(miseToml)
|
||||
for (const app in miseTomlParsed.tools) {
|
||||
if (APPS.includes(app)) {
|
||||
const appVersion = miseTomlParsed.tools[app]
|
||||
const version =
|
||||
typeof appVersion == 'object' ? appVersion.version : appVersion
|
||||
|
||||
core.info(`Consuming ${app} at version ${version}`)
|
||||
appVersions.set(app, version)
|
||||
}
|
||||
}
|
||||
|
||||
return appVersions
|
||||
}
|
||||
|
||||
function parseVersionFile(versionFilePath0) {
|
||||
const versionFilePath = path.resolve(
|
||||
process.env.GITHUB_WORKSPACE,
|
||||
versionFilePath0,
|
||||
)
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(
|
||||
`The specified version file, ${versionFilePath0}, does not exist`,
|
||||
)
|
||||
}
|
||||
|
||||
if (versionFilePath0.endsWith('.toml')) {
|
||||
core.startGroup(
|
||||
`Parsing ${path.basename(versionFilePath0)} file at ${versionFilePath0}`,
|
||||
)
|
||||
return parseMiseTomlFile(versionFilePath)
|
||||
}
|
||||
|
||||
core.startGroup(`Parsing .tool-versions file at ${versionFilePath0}`)
|
||||
return parseToolVersionsFile(versionFilePath)
|
||||
}
|
||||
|
||||
function debugLog(groupName, message) {
|
||||
const group = `Debugging for ${groupName}`
|
||||
core.debug(
|
||||
|
||||
Reference in New Issue
Block a user