diff --git a/src/functions.ts b/src/functions.ts index 34332e6..a39138c 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -1,11 +1,16 @@ import * as core from '@actions/core' import * as fs from 'fs' -import retry = require('async-retry') -import semver = require('semver') +import * as tc from '@actions/tool-cache' +import {GitHub} from '@actions/github/lib/utils' +import retry from 'async-retry' +import semver from 'semver' const NEXTFLOW_REPO = {owner: 'nextflow-io', repo: 'nextflow'} -async function all_nf_releases(ok) { +// HACK Private but I want to test this +export async function all_nf_releases( + ok: InstanceType +): Promise { return await ok.paginate( ok.rest.repos.listReleases, NEXTFLOW_REPO, @@ -13,7 +18,10 @@ async function all_nf_releases(ok) { ) } -async function latest_stable_release_data(ok) { +// HACK Private but I want to test this +export async function latest_stable_release_data( + ok: InstanceType +): Promise { const {data: stable_release} = await ok.rest.repos.getLatestRelease( NEXTFLOW_REPO ) @@ -21,9 +29,12 @@ async function latest_stable_release_data(ok) { return stable_release } -export async function release_data(version, ok) { +export async function release_data( + version: string, + ok: InstanceType +): Promise { // Setup tag-based filtering - let filter = r => { + let filter = (r: object): boolean => { return semver.satisfies(r.tag_name, version, true) } @@ -32,7 +43,8 @@ export async function release_data(version, ok) { if (version.includes('latest')) { if (version.includes('-everything')) { // No filtering - filter = r => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + filter = (r: object) => { return true } } else if (version.includes('-edge')) { @@ -50,7 +62,7 @@ export async function release_data(version, ok) { // Get all the releases const all_releases = await all_nf_releases(ok) - let matching_releases = all_releases.filter(filter) + const matching_releases = all_releases.filter(filter) matching_releases.sort(function (x, y) { semver.compare(x.tag_name, y.tag_name, true) @@ -59,13 +71,13 @@ export async function release_data(version, ok) { return matching_releases[0] } -export function nextflow_bin_url(release, get_all) { +export function nextflow_bin_url(release, get_all: boolean): string { const release_assets = release.assets const all_asset = release_assets.filter(a => { return a.browser_download_url.endsWith('-all') })[0] const regular_asset = release_assets.filter(a => { - return a.name == 'nextflow' + return a.name === 'nextflow' })[0] const dl_asset = get_all ? all_asset : regular_asset @@ -73,9 +85,13 @@ export function nextflow_bin_url(release, get_all) { return dl_asset.browser_download_url } -export async function install_nextflow(url, version) { +export async function install_nextflow( + url: string, + version: string +): Promise { core.debug(`Downloading Nextflow from ${url}`) const nf_dl_path = await retry( + // eslint-disable-next-line @typescript-eslint/no-unused-vars async bail => { return await tc.downloadTool(url) }, diff --git a/src/main.ts b/src/main.ts index 495a20d..a141779 100644 --- a/src/main.ts +++ b/src/main.ts @@ -3,9 +3,9 @@ import * as exec from '@actions/exec' import * as fs from 'fs' import * as github from '@actions/github' import * as tc from '@actions/tool-cache' -import {release_data, nextflow_bin_url, install_nextflow} from './functions' +import {install_nextflow, nextflow_bin_url, release_data} from './functions' -async function run() { +async function run(): Promise { // Set environment variables core.exportVariable('CAPSULE_LOG', 'none') @@ -20,19 +20,19 @@ async function run() { let octokit = {} try { octokit = github.getOctokit(token) - } catch (e: any) { + } catch (e) { core.setFailed( `Could not authenticate to GitHub Releases API with provided token\n${e.message}` ) } // Get the release info for the desired release - let release: any = {} + let release = {} try { release = await release_data(version, octokit) resolved_version = release.tag_name core.info(`Input version '${version}' resolved to Nextflow ${release.name}`) - } catch (e: any) { + } catch (e) { core.setFailed( `Could not retrieve Nextflow release matching ${version}.\n${e.message}` ) @@ -43,7 +43,7 @@ async function run() { try { url = nextflow_bin_url(release, get_all) core.info(`Preparing to download from ${url}`) - } catch (e: any) { + } catch (e) { core.setFailed(`Could not parse the download URL\n${e.message}`) } try { @@ -66,14 +66,14 @@ async function run() { core.addPath(nf_path) core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`) - } catch (e: any) { + } catch (e) { core.setFailed(e.message) } // Run Nextflow so it downloads its dependencies try { - const nf_exit_code = await exec.exec('nextflow', ['help']) - } catch (e: any) { + await exec.exec('nextflow', ['help']) + } catch (e) { core.warning( 'Nextflow appears to have installed correctly, but an error was thrown while running it.' )