Skip to content

Commit 8a11f0a

Browse files
Act on self-review: cache-tool prefers semver
... so we turn YYYY-MM-DD_N into YYYY.MM.DD+N
1 parent f60191b commit 8a11f0a

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

dist/index.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -30710,26 +30710,36 @@ main().catch((error) => {
3071030710
})
3071130711

3071230712
async function installElp(elpVersion) {
30713+
// We to this because tool-cache only likes semver
30714+
elpVersionForCache = semverFromELPVersion(elpVersion)
30715+
3071330716
const toolName = 'elp'
30714-
let cachePath = toolCache.find(toolName, elpVersion)
30717+
let cachePath = toolCache.find(toolName, elpVersionForCache)
3071530718

3071630719
if (cachePath === '') {
30717-
core.debug(`ELP ${elpVersion} is not cached as a tool`)
30718-
const elpTarGzFile0 = await elpTarGzFile()
30719-
const repo = 'https://github.com/WhatsApp/erlang-language-platform'
30720-
const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}`
30721-
core.debug(`ELP download URL is '${elpTarGz}'`)
30722-
const file = await toolCache.downloadTool(elpTarGz)
30720+
core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is not cached as a tool`)
30721+
const elpTarGzUrl = await elpTarGz(elpVersion)
30722+
const file = await toolCache.downloadTool(elpTarGzUrl)
3072330723
const targetDir = await toolCache.extractTar(file)
30724-
cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersion)
30724+
cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersionForCache)
3072530725
} else {
30726-
core.debug(`ELP ${elpVersion} is cached as a tool`)
30726+
core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is cached as a tool`)
3072730727
}
3072830728

30729+
// We want a deterministic name per runner (helpful for self-hosted, for example)
3072930730
const runnerToolPath = path.join(process.env.RUNNER_TEMP, '.setup-elp', 'elp')
3073030731
await fs.cp(cachePath, runnerToolPath, { recursive: true })
3073130732
core.addPath(runnerToolPath)
3073230733

30734+
reportInstalledELPVersion()
30735+
}
30736+
30737+
function semverFromELPVersion(elpVersion) {
30738+
let [major, minor, patch, build] = elpVersion.split(/[-_]/).slice(0, 4)
30739+
return `${Number(major)}.${Number(minor)}.${Number(patch)}+${Number(build) || 1}`
30740+
}
30741+
30742+
async function reportInstalledELPVersion() {
3073330743
const cmd = 'elp'
3073430744
const args = ['version']
3073530745
const version = await exec_(cmd, args)
@@ -30828,6 +30838,14 @@ async function elpTarGzFile() {
3082830838
return elpTarGzFile
3082930839
}
3083030840

30841+
async function elpTarGz(elpVersion) {
30842+
const elpTarGzFile0 = await elpTarGzFile()
30843+
const repo = 'https://github.com/WhatsApp/erlang-language-platform'
30844+
const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}`
30845+
core.debug(`ELP download URL is '${elpTarGz}'`)
30846+
return elpTarGz
30847+
}
30848+
3083130849
async function exec_(cmd, args) {
3083230850
let output = ''
3083330851
await exec.exec(cmd, args, {

src/setup-elp.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,36 @@ main().catch((error) => {
1616
})
1717

1818
async function installElp(elpVersion) {
19+
// We to this because tool-cache only likes semver
20+
elpVersionForCache = semverFromELPVersion(elpVersion)
21+
1922
const toolName = 'elp'
20-
let cachePath = toolCache.find(toolName, elpVersion)
23+
let cachePath = toolCache.find(toolName, elpVersionForCache)
2124

2225
if (cachePath === '') {
23-
core.debug(`ELP ${elpVersion} is not cached as a tool`)
24-
const elpTarGzFile0 = await elpTarGzFile()
25-
const repo = 'https://github.com/WhatsApp/erlang-language-platform'
26-
const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}`
27-
core.debug(`ELP download URL is '${elpTarGz}'`)
28-
const file = await toolCache.downloadTool(elpTarGz)
26+
core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is not cached as a tool`)
27+
const elpTarGzUrl = await elpTarGz(elpVersion)
28+
const file = await toolCache.downloadTool(elpTarGzUrl)
2929
const targetDir = await toolCache.extractTar(file)
30-
cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersion)
30+
cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersionForCache)
3131
} else {
32-
core.debug(`ELP ${elpVersion} is cached as a tool`)
32+
core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is cached as a tool`)
3333
}
3434

35+
// We want a deterministic name per runner (helpful for self-hosted, for example)
3536
const runnerToolPath = path.join(process.env.RUNNER_TEMP, '.setup-elp', 'elp')
3637
await fs.cp(cachePath, runnerToolPath, { recursive: true })
3738
core.addPath(runnerToolPath)
3839

40+
reportInstalledELPVersion()
41+
}
42+
43+
function semverFromELPVersion(elpVersion) {
44+
let [major, minor, patch, build] = elpVersion.split(/[-_]/).slice(0, 4)
45+
return `${Number(major)}.${Number(minor)}.${Number(patch)}+${Number(build) || 1}`
46+
}
47+
48+
async function reportInstalledELPVersion() {
3949
const cmd = 'elp'
4050
const args = ['version']
4151
const version = await exec_(cmd, args)
@@ -134,6 +144,14 @@ async function elpTarGzFile() {
134144
return elpTarGzFile
135145
}
136146

147+
async function elpTarGz(elpVersion) {
148+
const elpTarGzFile0 = await elpTarGzFile()
149+
const repo = 'https://github.com/WhatsApp/erlang-language-platform'
150+
const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}`
151+
core.debug(`ELP download URL is '${elpTarGz}'`)
152+
return elpTarGz
153+
}
154+
137155
async function exec_(cmd, args) {
138156
let output = ''
139157
await exec.exec(cmd, args, {

0 commit comments

Comments
 (0)