2022-11-13 05:00:23 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import * as fs from 'fs'
|
2022-11-13 21:56:49 +00:00
|
|
|
import * as tc from '@actions/tool-cache'
|
|
|
|
import {GitHub} from '@actions/github/lib/utils'
|
|
|
|
import retry from 'async-retry'
|
|
|
|
import semver from 'semver'
|
2022-11-13 05:00:23 +00:00
|
|
|
|
|
|
|
const NEXTFLOW_REPO = {owner: 'nextflow-io', repo: 'nextflow'}
|
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
// HACK Private but I want to test this
|
|
|
|
export async function all_nf_releases(
|
|
|
|
ok: InstanceType<typeof GitHub>
|
2022-11-14 02:19:06 +00:00
|
|
|
): Promise<object[]> {
|
2022-11-13 05:00:23 +00:00
|
|
|
return await ok.paginate(
|
|
|
|
ok.rest.repos.listReleases,
|
|
|
|
NEXTFLOW_REPO,
|
|
|
|
response => response.data
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
// HACK Private but I want to test this
|
|
|
|
export async function latest_stable_release_data(
|
|
|
|
ok: InstanceType<typeof GitHub>
|
|
|
|
): Promise<object> {
|
2022-11-13 05:00:23 +00:00
|
|
|
const {data: stable_release} = await ok.rest.repos.getLatestRelease(
|
|
|
|
NEXTFLOW_REPO
|
|
|
|
)
|
|
|
|
|
|
|
|
return stable_release
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
export async function release_data(
|
|
|
|
version: string,
|
|
|
|
ok: InstanceType<typeof GitHub>
|
|
|
|
): Promise<object> {
|
2022-11-13 05:00:23 +00:00
|
|
|
// Setup tag-based filtering
|
2022-11-13 21:56:49 +00:00
|
|
|
let filter = (r: object): boolean => {
|
2022-11-13 23:09:09 +00:00
|
|
|
return semver.satisfies(r['tag_name'], version, true)
|
2022-11-13 05:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the user passed a 'latest*' tag, and override filtering
|
|
|
|
// accordingly
|
|
|
|
if (version.includes('latest')) {
|
|
|
|
if (version.includes('-everything')) {
|
|
|
|
// No filtering
|
2022-11-13 21:56:49 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
filter = (r: object) => {
|
2022-11-13 05:00:23 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
} else if (version.includes('-edge')) {
|
|
|
|
filter = r => {
|
2022-11-13 23:09:09 +00:00
|
|
|
return r['tag_name'].endsWith('-edge')
|
2022-11-13 05:00:23 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is special: passing 'latest' or 'latest-stable' allows us to use
|
|
|
|
// the latest stable GitHub release direct from the API
|
|
|
|
const stable_release = await latest_stable_release_data(ok)
|
|
|
|
return stable_release
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get all the releases
|
2022-11-14 02:19:06 +00:00
|
|
|
const all_releases: object[] = await all_nf_releases(ok)
|
2022-11-13 05:00:23 +00:00
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
const matching_releases = all_releases.filter(filter)
|
2022-11-13 05:00:23 +00:00
|
|
|
|
2022-11-14 02:19:06 +00:00
|
|
|
matching_releases.sort((x, y) => {
|
|
|
|
// HACK IDK why the value flip is necessary with the return
|
|
|
|
return semver.compare(x['tag_name'], y['tag_name'], true) * -1
|
2022-11-13 05:00:23 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return matching_releases[0]
|
|
|
|
}
|
|
|
|
|
2022-11-13 23:09:09 +00:00
|
|
|
export function nextflow_bin_url(release: object, get_all: boolean): string {
|
|
|
|
const release_assets = release['assets']
|
|
|
|
const all_asset = release_assets.filter((a: object) => {
|
|
|
|
return a['browser_download_url'].endsWith('-all')
|
2022-11-13 05:00:23 +00:00
|
|
|
})[0]
|
2022-11-13 23:09:09 +00:00
|
|
|
const regular_asset = release_assets.filter((a: object) => {
|
|
|
|
return a['name'] === 'nextflow'
|
2022-11-13 05:00:23 +00:00
|
|
|
})[0]
|
|
|
|
|
|
|
|
const dl_asset = get_all ? all_asset : regular_asset
|
|
|
|
|
|
|
|
return dl_asset.browser_download_url
|
|
|
|
}
|
|
|
|
|
2022-11-13 21:56:49 +00:00
|
|
|
export async function install_nextflow(
|
|
|
|
url: string,
|
|
|
|
version: string
|
|
|
|
): Promise<string> {
|
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`
|
|
|
|
|
|
|
|
fs.renameSync(nf_dl_path, nf_path)
|
|
|
|
fs.chmodSync(nf_path, '0711')
|
|
|
|
|
|
|
|
return temp_install_dir
|
|
|
|
}
|