Skip to content

Commit

Permalink
Act on self-review: cache-tool prefers semver
Browse files Browse the repository at this point in the history
... so we turn YYYY-MM-DD_N into YYYY.MM.DD+N
  • Loading branch information
paulo-ferraz-oliveira committed Jun 20, 2024
1 parent f60191b commit 7b2b416
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 18 deletions.
35 changes: 26 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, {
Expand Down
35 changes: 26 additions & 9 deletions src/setup-elp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 7b2b416

Please sign in to comment.