2022-11-15 15:57:34 +00:00
|
|
|
import * as core from "@actions/core"
|
|
|
|
import * as exec from "@actions/exec"
|
|
|
|
import * as tc from "@actions/tool-cache"
|
|
|
|
import * as fs from "fs"
|
2023-05-16 23:15:48 +00:00
|
|
|
import semver from "semver"
|
2022-11-14 03:22:12 +00:00
|
|
|
|
2023-05-16 23:15:48 +00:00
|
|
|
import {
|
|
|
|
check_cache,
|
2023-12-23 17:45:04 +00:00
|
|
|
get_nextflow_release,
|
|
|
|
install_nextflow
|
2023-05-16 23:15:48 +00:00
|
|
|
} from "./functions"
|
2024-01-09 12:28:07 +00:00
|
|
|
import { NextflowRelease } from "./nextflow-release"
|
2024-01-26 04:19:34 +00:00
|
|
|
import {
|
|
|
|
pull_latest_stable_release,
|
2024-01-26 22:45:19 +00:00
|
|
|
pull_releases,
|
|
|
|
setup_octokit
|
2024-01-26 04:19:34 +00:00
|
|
|
} from "./octokit-wrapper"
|
2022-06-13 20:07:53 +00:00
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
async function run(): Promise<void> {
|
2023-12-23 17:45:34 +00:00
|
|
|
// CAPSULE_LOG leads to a bunch of boilerplate being output to the logs: turn
|
|
|
|
// it off
|
2022-11-15 15:57:34 +00:00
|
|
|
core.exportVariable("CAPSULE_LOG", "none")
|
2022-07-13 21:09:19 +00:00
|
|
|
|
2022-06-13 20:07:53 +00:00
|
|
|
// Read in the arguments
|
2022-11-15 15:57:34 +00:00
|
|
|
const token = core.getInput("token")
|
|
|
|
const version = core.getInput("version")
|
|
|
|
const get_all = core.getBooleanInput("all")
|
2024-01-15 03:40:32 +00:00
|
|
|
const cooldown = Number(core.getInput("cooldown"))
|
|
|
|
const max_retries = Number(core.getInput("max-retries"))
|
2022-06-13 20:07:53 +00:00
|
|
|
|
2023-05-16 23:15:48 +00:00
|
|
|
// Check the cache for the Nextflow version that matched last time
|
|
|
|
if (check_cache(version)) {
|
|
|
|
return
|
|
|
|
}
|
2022-06-13 20:34:37 +00:00
|
|
|
|
2022-06-13 18:29:56 +00:00
|
|
|
// Setup the API
|
2024-01-15 03:40:32 +00:00
|
|
|
const octokit = await setup_octokit(token, cooldown, max_retries)
|
2023-12-23 17:46:15 +00:00
|
|
|
|
2022-06-13 18:29:56 +00:00
|
|
|
// Get the release info for the desired release
|
2023-12-23 17:48:02 +00:00
|
|
|
let release = {} as NextflowRelease
|
2023-05-16 23:15:48 +00:00
|
|
|
let resolved_version = ""
|
2022-06-13 18:29:56 +00:00
|
|
|
try {
|
2024-01-26 04:19:34 +00:00
|
|
|
if (version === "latest" || version === "latest-stable") {
|
|
|
|
release = await pull_latest_stable_release(octokit)
|
|
|
|
} else {
|
2024-01-26 22:45:19 +00:00
|
|
|
const release_iterator = pull_releases(octokit)
|
2024-01-26 21:52:06 +00:00
|
|
|
release = await get_nextflow_release(version, release_iterator)
|
2024-01-26 04:19:34 +00:00
|
|
|
}
|
2023-12-23 17:48:02 +00:00
|
|
|
resolved_version = release.versionNumber
|
2022-11-13 23:09:09 +00:00
|
|
|
core.info(
|
2022-11-15 15:57:34 +00:00
|
|
|
`Input version '${version}' resolved to Nextflow ${release["name"]}`
|
2022-11-13 23:09:09 +00:00
|
|
|
)
|
2022-11-13 23:02:40 +00:00
|
|
|
} catch (e: unknown) {
|
|
|
|
if (e instanceof Error) {
|
|
|
|
core.setFailed(
|
|
|
|
`Could not retrieve Nextflow release matching ${version}.\n${e.message}`
|
|
|
|
)
|
|
|
|
}
|
2022-06-13 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-06-13 20:07:53 +00:00
|
|
|
// Download Nextflow and add it to path
|
2023-05-16 23:15:48 +00:00
|
|
|
if (!check_cache(resolved_version)) {
|
2023-12-23 17:48:02 +00:00
|
|
|
const nf_install_path = await install_nextflow(release, get_all)
|
2023-05-16 23:15:48 +00:00
|
|
|
const cleaned_version = String(semver.clean(resolved_version, true))
|
|
|
|
const nf_path = await tc.cacheDir(
|
|
|
|
nf_install_path,
|
|
|
|
"nextflow",
|
|
|
|
cleaned_version
|
|
|
|
)
|
|
|
|
core.addPath(nf_path)
|
|
|
|
core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`)
|
2022-11-13 04:07:59 +00:00
|
|
|
core.debug(`Added Nextflow to cache: ${nf_path}`)
|
2022-11-14 02:29:05 +00:00
|
|
|
fs.rmdirSync(nf_install_path, { recursive: true })
|
2022-06-13 20:07:53 +00:00
|
|
|
}
|
2022-11-13 23:02:40 +00:00
|
|
|
} catch (e: unknown) {
|
|
|
|
if (e instanceof Error) {
|
|
|
|
core.setFailed(e.message)
|
|
|
|
}
|
2022-06-13 18:29:56 +00:00
|
|
|
}
|
2022-06-13 21:38:31 +00:00
|
|
|
|
|
|
|
// Run Nextflow so it downloads its dependencies
|
|
|
|
try {
|
2022-11-15 15:57:34 +00:00
|
|
|
await exec.exec("nextflow", ["help"])
|
2022-11-13 23:02:40 +00:00
|
|
|
} catch (e: unknown) {
|
|
|
|
if (e instanceof Error) {
|
2023-10-11 14:29:12 +00:00
|
|
|
// fail workflow if Nextflow run does not succeed
|
|
|
|
core.setFailed(`Could not run 'nextflow help'. Error: ${e.message}`)
|
2022-11-13 23:02:40 +00:00
|
|
|
}
|
2022-06-13 21:38:31 +00:00
|
|
|
}
|
2022-06-13 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
run()
|