2022-11-13 04:07:59 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as exec from '@actions/exec'
|
|
|
|
import * as fs from 'fs'
|
|
|
|
import * as github from '@actions/github'
|
|
|
|
import * as tc from '@actions/tool-cache'
|
2022-11-13 05:00:23 +00:00
|
|
|
import {release_data, nextflow_bin_url, install_nextflow} from './functions'
|
2022-06-13 20:07:53 +00:00
|
|
|
|
2022-06-13 18:29:56 +00:00
|
|
|
async function run() {
|
2022-07-13 21:09:19 +00:00
|
|
|
// Set environment variables
|
2022-11-13 04:07:59 +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-13 04:07:59 +00:00
|
|
|
const token = core.getInput('token')
|
|
|
|
const version = core.getInput('version')
|
|
|
|
const get_all = core.getBooleanInput('all')
|
2022-06-13 20:07:53 +00:00
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
let resolved_version = ''
|
2022-06-13 20:34:37 +00:00
|
|
|
|
2022-06-13 18:29:56 +00:00
|
|
|
// Setup the API
|
2022-11-13 04:07:59 +00:00
|
|
|
let octokit = {}
|
2022-06-13 18:29:56 +00:00
|
|
|
try {
|
2022-11-13 04:07:59 +00:00
|
|
|
octokit = github.getOctokit(token)
|
2022-06-15 16:29:30 +00:00
|
|
|
} catch (e: any) {
|
2022-06-13 18:29:56 +00:00
|
|
|
core.setFailed(
|
|
|
|
`Could not authenticate to GitHub Releases API with provided token\n${e.message}`
|
2022-11-13 04:07:59 +00:00
|
|
|
)
|
2022-06-13 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the release info for the desired release
|
2022-11-13 04:07:59 +00:00
|
|
|
let release: any = {}
|
2022-06-13 18:29:56 +00:00
|
|
|
try {
|
2022-11-13 04:07:59 +00:00
|
|
|
release = await release_data(version, octokit)
|
|
|
|
resolved_version = release.tag_name
|
|
|
|
core.info(`Input version '${version}' resolved to Nextflow ${release.name}`)
|
2022-06-15 16:29:30 +00:00
|
|
|
} catch (e: any) {
|
2022-06-13 18:29:56 +00:00
|
|
|
core.setFailed(
|
|
|
|
`Could not retrieve Nextflow release matching ${version}.\n${e.message}`
|
2022-11-13 04:07:59 +00:00
|
|
|
)
|
2022-06-13 18:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the download url for the desired release
|
2022-11-13 04:07:59 +00:00
|
|
|
let url = ''
|
2022-06-13 18:29:56 +00:00
|
|
|
try {
|
2022-11-13 04:07:59 +00:00
|
|
|
url = nextflow_bin_url(release, get_all)
|
|
|
|
core.info(`Preparing to download from ${url}`)
|
2022-06-15 16:29:30 +00:00
|
|
|
} catch (e: any) {
|
2022-11-13 04:07:59 +00:00
|
|
|
core.setFailed(`Could not parse the download URL\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
|
2022-11-13 04:07:59 +00:00
|
|
|
let nf_path = ''
|
|
|
|
nf_path = tc.find('nextflow', resolved_version)
|
2022-06-13 20:07:53 +00:00
|
|
|
|
|
|
|
if (!nf_path) {
|
2022-11-13 04:07:59 +00:00
|
|
|
core.debug(`Could not find Nextflow ${resolved_version} in cache`)
|
|
|
|
const nf_install_path = await install_nextflow(url, resolved_version)
|
2022-06-13 20:34:37 +00:00
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
nf_path = await tc.cacheDir(nf_install_path, 'nextflow', resolved_version)
|
|
|
|
core.debug(`Added Nextflow to cache: ${nf_path}`)
|
2022-06-13 20:07:53 +00:00
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
fs.rmdirSync(nf_install_path, {recursive: true})
|
2022-06-13 20:07:53 +00:00
|
|
|
} else {
|
2022-11-13 04:07:59 +00:00
|
|
|
core.debug(`Using cached version of Nextflow: ${nf_path}`)
|
2022-06-13 20:07:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
core.addPath(nf_path)
|
2022-06-13 18:29:56 +00:00
|
|
|
|
2022-11-13 04:07:59 +00:00
|
|
|
core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`)
|
2022-06-15 16:29:30 +00:00
|
|
|
} catch (e: any) {
|
2022-11-13 04:07:59 +00:00
|
|
|
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-13 04:07:59 +00:00
|
|
|
const nf_exit_code = await exec.exec('nextflow', ['help'])
|
2022-06-15 16:29:30 +00:00
|
|
|
} catch (e: any) {
|
2022-11-13 04:07:59 +00:00
|
|
|
core.warning(
|
|
|
|
'Nextflow appears to have installed correctly, but an error was thrown while running it.'
|
|
|
|
)
|
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()
|