2022-11-15 15:57:34 +00:00
|
|
|
import * as core from "@actions/core"
|
|
|
|
import * as tc from "@actions/tool-cache"
|
|
|
|
import retry from "async-retry"
|
|
|
|
import * as fs from "fs"
|
|
|
|
import semver from "semver"
|
2022-11-13 05:00:23 +00:00
|
|
|
|
2024-01-09 12:28:07 +00:00
|
|
|
import { NextflowRelease } from "./nextflow-release"
|
2022-11-13 05:00:23 +00:00
|
|
|
|
2023-12-23 17:42:54 +00:00
|
|
|
export async function get_nextflow_release(
|
|
|
|
version: string,
|
2024-02-02 16:42:29 +00:00
|
|
|
releases: NextflowRelease[] | AsyncGenerator<NextflowRelease>
|
2023-12-23 17:42:54 +00:00
|
|
|
): Promise<NextflowRelease> {
|
2024-01-26 21:52:06 +00:00
|
|
|
// The releases are sent in reverse chronological order
|
|
|
|
// If we are sent a numbered tag, then back through the list until we find
|
|
|
|
// a release that fulfils the requested version number
|
|
|
|
for await (const release of releases) {
|
|
|
|
if (semver.satisfies(release.versionNumber, version, true)) {
|
|
|
|
return release
|
|
|
|
}
|
|
|
|
}
|
2022-11-13 05:00:23 +00:00
|
|
|
|
2024-01-26 21:52:06 +00:00
|
|
|
// We should never get here, but just in case
|
|
|
|
return {} as NextflowRelease
|
2022-11-13 05:00:23 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
export async function install_nextflow(
|
2023-12-23 17:43:41 +00:00
|
|
|
release: NextflowRelease,
|
|
|
|
get_all: boolean
|
2022-11-13 21:56:49 +00:00
|
|
|
): Promise<string> {
|
2023-12-23 17:43:41 +00:00
|
|
|
const url = get_all ? release.allBinaryURL : release.binaryURL
|
|
|
|
const version = release.versionNumber
|
|
|
|
|
2022-11-13 05:00:23 +00:00
|
|
|
core.debug(`Downloading Nextflow from ${url}`)
|
|
|
|
const nf_dl_path = await retry(
|
2022-11-13 21:56:49 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2022-11-13 05:00:23 +00:00
|
|
|
async bail => {
|
|
|
|
return await tc.downloadTool(url)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
onRetry: err => {
|
|
|
|
core.debug(`Download of ${url} failed, trying again. Error ${err}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
const temp_install_dir = fs.mkdtempSync(`nxf-${version}`)
|
|
|
|
const nf_path = `${temp_install_dir}/nextflow`
|
|
|
|
|
2023-06-22 07:18:37 +00:00
|
|
|
try {
|
|
|
|
fs.renameSync(nf_dl_path, nf_path)
|
|
|
|
} catch (err: unknown) {
|
|
|
|
core.debug(`Failed to rename file: ${err}`)
|
|
|
|
fs.copyFileSync(nf_dl_path, nf_path)
|
|
|
|
fs.unlinkSync(nf_dl_path)
|
|
|
|
}
|
2022-11-15 15:57:34 +00:00
|
|
|
fs.chmodSync(nf_path, "0711")
|
2022-11-13 05:00:23 +00:00
|
|
|
|
|
|
|
return temp_install_dir
|
|
|
|
}
|
2023-05-16 23:13:04 +00:00
|
|
|
|
|
|
|
export function check_cache(version: string): boolean {
|
2024-01-06 16:08:13 +00:00
|
|
|
// A 'latest*' version indicates that a cached version would be invalid until
|
|
|
|
// the version is resolved: abort
|
|
|
|
if (version.includes("latest")) {
|
|
|
|
return false
|
|
|
|
}
|
2023-05-16 23:13:04 +00:00
|
|
|
const cleaned_version = semver.clean(version, true)
|
|
|
|
if (cleaned_version === null) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const resolved_version = String(cleaned_version)
|
|
|
|
|
|
|
|
const nf_path = tc.find("nextflow", resolved_version)
|
|
|
|
if (!nf_path) {
|
|
|
|
core.debug(`Could not find Nextflow ${resolved_version} in the tool cache`)
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
core.debug(`Found Nextflow ${resolved_version} at path '${nf_path}'`)
|
|
|
|
core.debug(`Adding '${nf_path}' to PATH`)
|
|
|
|
core.addPath(nf_path)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|