style: Run prettier

This commit is contained in:
Edmund Miller 2022-11-12 22:07:59 -06:00 committed by Thomas A. Christensen II
parent 9ec3bc304f
commit 147da60f8f
3 changed files with 104 additions and 108 deletions

View file

@ -1,22 +1,22 @@
name: "Setup Nextflow" name: 'Setup Nextflow'
description: "Install Nextflow and add it to the PATH" description: 'Install Nextflow and add it to the PATH'
author: "nf-core" author: 'nf-core'
inputs: inputs:
version: version:
description: "The Nextflow version to download (if necessary) and use. Example: 21.10.3" description: 'The Nextflow version to download (if necessary) and use. Example: 21.10.3'
required: false required: false
default: "latest-stable" default: 'latest-stable'
all: all:
description: "Whether to install every Nextflow release via the '-all' distribution." description: "Whether to install every Nextflow release via the '-all' distribution."
required: false required: false
default: false default: false
token: token:
description: "GitHub token to access the GitHub Releases API. The default token should be sufficient for all use cases." description: 'GitHub token to access the GitHub Releases API. The default token should be sufficient for all use cases.'
required: false required: false
default: ${{ github.token }} default: ${{ github.token }}
runs: runs:
using: "node16" using: 'node16'
main: "dist/index.js" main: 'dist/index.js'
branding: branding:
icon: "shuffle" icon: 'shuffle'
color: "green" color: 'green'

176
index.ts
View file

@ -1,180 +1,176 @@
import * as core from "@actions/core"; import * as core from '@actions/core'
import * as exec from "@actions/exec"; import * as exec from '@actions/exec'
import * as fs from "fs"; import * as fs from 'fs'
import * as github from "@actions/github"; import * as github from '@actions/github'
import * as tc from "@actions/tool-cache"; import * as tc from '@actions/tool-cache'
import retry = require("async-retry"); import retry = require('async-retry')
import semver = require("semver"); import semver = require('semver')
const NEXTFLOW_REPO = { owner: "nextflow-io", repo: "nextflow" }; const NEXTFLOW_REPO = {owner: 'nextflow-io', repo: 'nextflow'}
async function all_nf_releases(ok) { async function all_nf_releases(ok) {
return await ok.paginate( return await ok.paginate(
ok.rest.repos.listReleases, ok.rest.repos.listReleases,
NEXTFLOW_REPO, NEXTFLOW_REPO,
(response) => response.data response => response.data
); )
} }
async function latest_stable_release_data(ok) { async function latest_stable_release_data(ok) {
const { data: stable_release } = await ok.rest.repos.getLatestRelease( const {data: stable_release} = await ok.rest.repos.getLatestRelease(
NEXTFLOW_REPO NEXTFLOW_REPO
); )
return stable_release; return stable_release
} }
async function release_data(version, ok) { async function release_data(version, ok) {
// Setup tag-based filtering // Setup tag-based filtering
let filter = (r) => { let filter = r => {
return semver.satisfies(r.tag_name, version, true); return semver.satisfies(r.tag_name, version, true)
}; }
// Check if the user passed a 'latest*' tag, and override filtering // Check if the user passed a 'latest*' tag, and override filtering
// accordingly // accordingly
if (version.includes("latest")) { if (version.includes('latest')) {
if (version.includes("-everything")) { if (version.includes('-everything')) {
// No filtering // No filtering
filter = (r) => { filter = r => {
return true; return true
}; }
} else if (version.includes("-edge")) { } else if (version.includes('-edge')) {
filter = (r) => { filter = r => {
return r.tag_name.endsWith("-edge"); return r.tag_name.endsWith('-edge')
}; }
} else { } else {
// This is special: passing 'latest' or 'latest-stable' allows us to use // This is special: passing 'latest' or 'latest-stable' allows us to use
// the latest stable GitHub release direct from the API // the latest stable GitHub release direct from the API
const stable_release = await latest_stable_release_data(ok); const stable_release = await latest_stable_release_data(ok)
return stable_release; return stable_release
} }
} }
// Get all the releases // Get all the releases
const all_releases = await all_nf_releases(ok); const all_releases = await all_nf_releases(ok)
let matching_releases = all_releases.filter(filter); let matching_releases = all_releases.filter(filter)
matching_releases.sort(function (x, y) { matching_releases.sort(function (x, y) {
semver.compare(x.tag_name, y.tag_name, true); semver.compare(x.tag_name, y.tag_name, true)
}); })
return matching_releases[0]; return matching_releases[0]
} }
function nextflow_bin_url(release, get_all) { function nextflow_bin_url(release, get_all) {
const release_assets = release.assets; const release_assets = release.assets
const all_asset = release_assets.filter((a) => { const all_asset = release_assets.filter(a => {
return a.browser_download_url.endsWith("-all"); return a.browser_download_url.endsWith('-all')
})[0]; })[0]
const regular_asset = release_assets.filter((a) => { const regular_asset = release_assets.filter(a => {
return a.name == "nextflow"; return a.name == 'nextflow'
})[0]; })[0]
const dl_asset = get_all ? all_asset : regular_asset; const dl_asset = get_all ? all_asset : regular_asset
return dl_asset.browser_download_url; return dl_asset.browser_download_url
} }
async function install_nextflow(url, version) { async function install_nextflow(url, version) {
core.debug(`Downloading Nextflow from ${url}`); core.debug(`Downloading Nextflow from ${url}`)
const nf_dl_path = await retry( const nf_dl_path = await retry(
async (bail) => { async bail => {
return await tc.downloadTool(url); return await tc.downloadTool(url)
}, },
{ {
onRetry: (err) => { onRetry: err => {
core.debug(`Download of ${url} failed, trying again. Error ${err}`); core.debug(`Download of ${url} failed, trying again. Error ${err}`)
}, }
} }
); )
const temp_install_dir = fs.mkdtempSync(`nxf-${version}`); const temp_install_dir = fs.mkdtempSync(`nxf-${version}`)
const nf_path = `${temp_install_dir}/nextflow`; const nf_path = `${temp_install_dir}/nextflow`
fs.renameSync(nf_dl_path, nf_path); fs.renameSync(nf_dl_path, nf_path)
fs.chmodSync(nf_path, "0711"); fs.chmodSync(nf_path, '0711')
return temp_install_dir; return temp_install_dir
} }
async function run() { async function run() {
// Set environment variables // Set environment variables
core.exportVariable("CAPSULE_LOG", "none"); core.exportVariable('CAPSULE_LOG', 'none')
// Read in the arguments // Read in the arguments
const token = core.getInput("token"); const token = core.getInput('token')
const version = core.getInput("version"); const version = core.getInput('version')
const get_all = core.getBooleanInput("all"); const get_all = core.getBooleanInput('all')
let resolved_version = ""; let resolved_version = ''
// Setup the API // Setup the API
let octokit = {}; let octokit = {}
try { try {
octokit = github.getOctokit(token); octokit = github.getOctokit(token)
} catch (e: any) { } catch (e: any) {
core.setFailed( core.setFailed(
`Could not authenticate to GitHub Releases API with provided token\n${e.message}` `Could not authenticate to GitHub Releases API with provided token\n${e.message}`
); )
} }
// Get the release info for the desired release // Get the release info for the desired release
let release: any = {}; let release: any = {}
try { try {
release = await release_data(version, octokit); release = await release_data(version, octokit)
resolved_version = release.tag_name; resolved_version = release.tag_name
core.info( core.info(`Input version '${version}' resolved to Nextflow ${release.name}`)
`Input version '${version}' resolved to Nextflow ${release.name}`
);
} catch (e: any) { } catch (e: any) {
core.setFailed( core.setFailed(
`Could not retrieve Nextflow release matching ${version}.\n${e.message}` `Could not retrieve Nextflow release matching ${version}.\n${e.message}`
); )
} }
// Get the download url for the desired release // Get the download url for the desired release
let url = ""; let url = ''
try { try {
url = nextflow_bin_url(release, get_all); url = nextflow_bin_url(release, get_all)
core.info(`Preparing to download from ${url}`); core.info(`Preparing to download from ${url}`)
} catch (e: any) { } catch (e: any) {
core.setFailed(`Could not parse the download URL\n${e.message}`); core.setFailed(`Could not parse the download URL\n${e.message}`)
} }
try { try {
// Download Nextflow and add it to path // Download Nextflow and add it to path
let nf_path = ""; let nf_path = ''
nf_path = tc.find("nextflow", resolved_version); nf_path = tc.find('nextflow', resolved_version)
if (!nf_path) { if (!nf_path) {
core.debug(`Could not find Nextflow ${resolved_version} in cache`); core.debug(`Could not find Nextflow ${resolved_version} in cache`)
const nf_install_path = await install_nextflow(url, resolved_version); const nf_install_path = await install_nextflow(url, resolved_version)
nf_path = await tc.cacheDir( nf_path = await tc.cacheDir(nf_install_path, 'nextflow', resolved_version)
nf_install_path, core.debug(`Added Nextflow to cache: ${nf_path}`)
"nextflow",
resolved_version
);
core.debug(`Added Nextflow to cache: ${nf_path}`);
fs.rmdirSync(nf_install_path, { recursive: true }); fs.rmdirSync(nf_install_path, {recursive: true})
} else { } else {
core.debug(`Using cached version of Nextflow: ${nf_path}`); core.debug(`Using cached version of Nextflow: ${nf_path}`)
} }
core.addPath(nf_path); core.addPath(nf_path)
core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`); core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`)
} catch (e: any) { } catch (e: any) {
core.setFailed(e.message); core.setFailed(e.message)
} }
// Run Nextflow so it downloads its dependencies // Run Nextflow so it downloads its dependencies
try { try {
const nf_exit_code = await exec.exec("nextflow", ["help"]) const nf_exit_code = await exec.exec('nextflow', ['help'])
} catch (e: any) { } catch (e: any) {
core.warning("Nextflow appears to have installed correctly, but an error was thrown while running it.") core.warning(
'Nextflow appears to have installed correctly, but an error was thrown while running it.'
)
} }
} }
run(); run()

View file

@ -1,10 +1,10 @@
{ {
"extends": "@tsconfig/node16/tsconfig.json", "extends": "@tsconfig/node16/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"target": "es6", "target": "es6",
"module": "commonjs", "module": "commonjs",
"strict": true, "strict": true,
"noImplicitAny": false, "noImplicitAny": false,
"esModuleInterop": true, "esModuleInterop": true
} }
} }