From 7b2b41638c148701914d86feb0478a7f835550ed Mon Sep 17 00:00:00 2001 From: "Paulo F. Oliveira" Date: Thu, 20 Jun 2024 01:14:03 +0100 Subject: [PATCH] Act on self-review: cache-tool prefers semver ... so we turn YYYY-MM-DD_N into YYYY.MM.DD+N --- dist/index.js | 35 ++++++++++++++++++++++++++--------- src/setup-elp.js | 35 ++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index ca1a4ac..c4d767d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -30709,27 +30709,36 @@ main().catch((error) => { core.setFailed(error.message) }) +function semverFromELPVersion(elpVersion) { + let [major, minor, patch, build] = elpVersion.split(/[-_]/).slice(0, 4) + return `${Number(major)}.${Number(minor)}.${Number(patch)}+${Number(build) || 1}` +} async function installElp(elpVersion) { + // We to this because tool-cache only likes semver + elpVersionForCache = semverFromELPVersion(elpVersion) + const toolName = 'elp' - let cachePath = toolCache.find(toolName, elpVersion) + let cachePath = toolCache.find(toolName, elpVersionForCache) if (cachePath === '') { - core.debug(`ELP ${elpVersion} is not cached as a tool`) - const elpTarGzFile0 = await elpTarGzFile() - const repo = 'https://github.com/WhatsApp/erlang-language-platform' - const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}` - core.debug(`ELP download URL is '${elpTarGz}'`) - const file = await toolCache.downloadTool(elpTarGz) + core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is not cached as a tool`) + const elpTarGzUrl = await elpTarGz(elpVersion) + const file = await toolCache.downloadTool(elpTarGzUrl) const targetDir = await toolCache.extractTar(file) - cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersion) + cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersionForCache) } else { - core.debug(`ELP ${elpVersion} is cached as a tool`) + core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is cached as a tool`) } + // We want a deterministic name per runner (helpful for self-hosted, for example) const runnerToolPath = path.join(process.env.RUNNER_TEMP, '.setup-elp', 'elp') await fs.cp(cachePath, runnerToolPath, { recursive: true }) core.addPath(runnerToolPath) + reportInstalledELPVersion() +} + +async function reportInstalledELPVersion() { const cmd = 'elp' const args = ['version'] const version = await exec_(cmd, args) @@ -30828,6 +30837,14 @@ async function elpTarGzFile() { return elpTarGzFile } +async function elpTarGz(elpVersion) { + const elpTarGzFile0 = await elpTarGzFile() + const repo = 'https://github.com/WhatsApp/erlang-language-platform' + const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}` + core.debug(`ELP download URL is '${elpTarGz}'`) + return elpTarGz +} + async function exec_(cmd, args) { let output = '' await exec.exec(cmd, args, { diff --git a/src/setup-elp.js b/src/setup-elp.js index 145b981..2bd3477 100644 --- a/src/setup-elp.js +++ b/src/setup-elp.js @@ -15,27 +15,36 @@ main().catch((error) => { core.setFailed(error.message) }) +function semverFromELPVersion(elpVersion) { + let [major, minor, patch, build] = elpVersion.split(/[-_]/).slice(0, 4) + return `${Number(major)}.${Number(minor)}.${Number(patch)}+${Number(build) || 1}` +} async function installElp(elpVersion) { + // We to this because tool-cache only likes semver + elpVersionForCache = semverFromELPVersion(elpVersion) + const toolName = 'elp' - let cachePath = toolCache.find(toolName, elpVersion) + let cachePath = toolCache.find(toolName, elpVersionForCache) if (cachePath === '') { - core.debug(`ELP ${elpVersion} is not cached as a tool`) - const elpTarGzFile0 = await elpTarGzFile() - const repo = 'https://github.com/WhatsApp/erlang-language-platform' - const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}` - core.debug(`ELP download URL is '${elpTarGz}'`) - const file = await toolCache.downloadTool(elpTarGz) + core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is not cached as a tool`) + const elpTarGzUrl = await elpTarGz(elpVersion) + const file = await toolCache.downloadTool(elpTarGzUrl) const targetDir = await toolCache.extractTar(file) - cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersion) + cachePath = await toolCache.cacheDir(targetDir, toolName, elpVersionForCache) } else { - core.debug(`ELP ${elpVersion} is cached as a tool`) + core.debug(`ELP ${elpVersion} (cache version: '${elpVersionForCache}') is cached as a tool`) } + // We want a deterministic name per runner (helpful for self-hosted, for example) const runnerToolPath = path.join(process.env.RUNNER_TEMP, '.setup-elp', 'elp') await fs.cp(cachePath, runnerToolPath, { recursive: true }) core.addPath(runnerToolPath) + reportInstalledELPVersion() +} + +async function reportInstalledELPVersion() { const cmd = 'elp' const args = ['version'] const version = await exec_(cmd, args) @@ -134,6 +143,14 @@ async function elpTarGzFile() { return elpTarGzFile } +async function elpTarGz(elpVersion) { + const elpTarGzFile0 = await elpTarGzFile() + const repo = 'https://github.com/WhatsApp/erlang-language-platform' + const elpTarGz = `${repo}/releases/download/${elpVersion}/${elpTarGzFile0}` + core.debug(`ELP download URL is '${elpTarGz}'`) + return elpTarGz +} + async function exec_(cmd, args) { let output = '' await exec.exec(cmd, args, {