Skip to content

Commit a50811f

Browse files
committed
fix default value for version-file-type input
1 parent 1303656 commit a50811f

File tree

3 files changed

+60
-19
lines changed

3 files changed

+60
-19
lines changed

dist/index.js

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -80470,10 +80470,12 @@ var lodash = __nccwpck_require__(2356);
8047080470

8047180471

8047280472

80473+
const toml = require('toml')
8047380474

8047480475
const setup_beam_dirname = external_node_path_namespaceObject.dirname((0,external_node_url_.fileURLToPath)(import.meta.url))
8047580476

8047680477
const MAX_HTTP_RETRIES = 3
80478+
const APPS = ['erlang', 'elixir', 'gleam', 'rebar']
8047780479

8047880480
if (process.env.NODE_ENV !== 'test') {
8047980481
main().catch((err) => {
@@ -80492,7 +80494,10 @@ async function main() {
8049280494
"you have to set version-type=strict if you're using version-file",
8049380495
)
8049480496
}
80495-
versions = parseVersionFile(versionFilePath)
80497+
80498+
const versionFileType =
80499+
setup_beam_getInput('version-file-type', false) || '.tool-versions'
80500+
versions = parseVersionFile(versionFilePath, versionFileType)
8049680501
}
8049780502

8049880503
const otpSpec = setup_beam_getInput('otp-version', true, 'erlang', versions)
@@ -81263,28 +81268,14 @@ alongside ${alternativeName}=${alternativeValue} \
8126381268
return input
8126481269
}
8126581270

81266-
function parseVersionFile(versionFilePath0) {
81267-
const versionFilePath = external_node_path_namespaceObject.resolve(
81268-
process.env.GITHUB_WORKSPACE,
81269-
versionFilePath0,
81270-
)
81271-
if (!external_node_fs_namespaceObject.existsSync(versionFilePath)) {
81272-
throw new Error(
81273-
`The specified version file, ${versionFilePath0}, does not exist`,
81274-
)
81275-
}
81276-
81277-
lib_core.startGroup(`Parsing version file at ${versionFilePath0}`)
81271+
function parseToolVersionsFile(versionFilePath) {
8127881272
const appVersions = new Map()
8127981273
const versions = external_node_fs_namespaceObject.readFileSync(versionFilePath, 'utf8')
81280-
// For the time being we parse .tool-versions
81281-
// If we ever start parsing something else, this should
81282-
// become default in a new option named e.g. version-file-type
8128381274
versions.split(/\r?\n/).forEach((line) => {
8128481275
const appVersion = line.match(/^([^ ]+)[ ]+(ref:v?)?([^ #]+)/)
8128581276
if (appVersion) {
8128681277
const app = appVersion[1]
81287-
if (['erlang', 'elixir', 'gleam', 'rebar'].includes(app)) {
81278+
if (APPS.includes(app)) {
8128881279
const [, , , version] = appVersion
8128981280
lib_core.info(`Consuming ${app} at version ${version}`)
8129081281
appVersions.set(app, version)
@@ -81301,6 +81292,44 @@ function parseVersionFile(versionFilePath0) {
8130181292
return appVersions
8130281293
}
8130381294

81295+
function parseMiseTomlFile(versionFilePath) {
81296+
const appVersions = new Map()
81297+
const miseToml = external_node_fs_namespaceObject.readFileSync(versionFilePath, 'utf8')
81298+
const miseTomlParsed = toml.parse(miseToml)
81299+
for (const app in miseTomlParsed.tools) {
81300+
if (APPS.includes(app)) {
81301+
const appVersion = miseTomlParsed.tools[app]
81302+
const version =
81303+
typeof appVersion == 'object' ? appVersion.version : appVersion
81304+
81305+
lib_core.info(`Consuming ${app} at version ${version}`)
81306+
appVersions.set(app, version)
81307+
}
81308+
}
81309+
81310+
return appVersions
81311+
}
81312+
81313+
function parseVersionFile(versionFilePath0, versionFileType) {
81314+
const versionFilePath = external_node_path_namespaceObject.resolve(
81315+
process.env.GITHUB_WORKSPACE,
81316+
versionFilePath0,
81317+
)
81318+
if (!external_node_fs_namespaceObject.existsSync(versionFilePath)) {
81319+
throw new Error(
81320+
`The specified version file, ${versionFilePath0}, does not exist`,
81321+
)
81322+
}
81323+
lib_core.startGroup(`Parsing ${versionFileType} file at ${versionFilePath0}`)
81324+
81325+
switch (versionFileType) {
81326+
case '.tool-versions':
81327+
return parseToolVersionsFile(versionFilePath)
81328+
case 'mise.toml':
81329+
return parseMiseTomlFile(versionFilePath)
81330+
}
81331+
}
81332+
8130481333
function debugLog(groupName, message) {
8130581334
const group = `Debugging for ${groupName}`
8130681335
lib_core.debug(

package-lock.json

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/setup-beam.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ async function main() {
3333
)
3434
}
3535

36-
const versionFileType = getInput('version-file-type', '.tool-versions')
36+
const versionFileType =
37+
getInput('version-file-type', false) || '.tool-versions'
3738
versions = parseVersionFile(versionFilePath, versionFileType)
3839
}
3940

0 commit comments

Comments
 (0)