mirror of
https://github.com/MillironX/setup-nextflow.git
synced 2024-11-25 02:39:55 +00:00
Add more robust caching
This commit is contained in:
parent
a9be6482af
commit
dcbcd9ccd4
3 changed files with 50 additions and 20 deletions
66
index.js
66
index.js
|
@ -1,9 +1,10 @@
|
||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
|
const fs = require("fs");
|
||||||
const github = require("@actions/github");
|
const github = require("@actions/github");
|
||||||
|
const io = require("@actions/io");
|
||||||
|
const retry = require("async-retry");
|
||||||
const semver = require("semver");
|
const semver = require("semver");
|
||||||
const tc = require("@actions/tool-cache");
|
const tc = require("@actions/tool-cache");
|
||||||
const fs = require("fs");
|
|
||||||
const retry = require("async-retry");
|
|
||||||
|
|
||||||
const NEXTFLOW_REPO = { owner: "nextflow-io", repo: "nextflow" };
|
const NEXTFLOW_REPO = { owner: "nextflow-io", repo: "nextflow" };
|
||||||
|
|
||||||
|
@ -73,11 +74,38 @@ function nextflow_bin_url(release, get_all) {
|
||||||
return dl_asset.browser_download_url;
|
return dl_asset.browser_download_url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function install_nextflow(url, version) {
|
||||||
|
core.debug(`Downloading Nextflow from ${url}`);
|
||||||
|
const nf_dl_path = await retry(
|
||||||
|
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 = await io.mv(nf_path, `${temp_install_dir}/nextflow`, {
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
fs.chmod(nf_path, "+x");
|
||||||
|
|
||||||
|
return temp_install_dir;
|
||||||
|
}
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
|
// Read in the arguments
|
||||||
|
const token = core.getInput("token");
|
||||||
|
const version = core.getInput("version");
|
||||||
|
const get_all = core.getBooleanInput("all");
|
||||||
|
|
||||||
// Setup the API
|
// Setup the API
|
||||||
let octokit = {};
|
let octokit = {};
|
||||||
try {
|
try {
|
||||||
const token = core.getInput("token");
|
|
||||||
octokit = github.getOctokit(token);
|
octokit = github.getOctokit(token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
|
@ -88,7 +116,6 @@ async function run() {
|
||||||
// Get the release info for the desired release
|
// Get the release info for the desired release
|
||||||
let release = {};
|
let release = {};
|
||||||
try {
|
try {
|
||||||
const version = core.getInput("version");
|
|
||||||
release = await release_data(version, octokit);
|
release = await release_data(version, octokit);
|
||||||
core.info(
|
core.info(
|
||||||
`Input version '${version}' resolved to Nextflow ${release.name}`
|
`Input version '${version}' resolved to Nextflow ${release.name}`
|
||||||
|
@ -102,29 +129,30 @@ async function run() {
|
||||||
// Get the download url for the desired release
|
// Get the download url for the desired release
|
||||||
let url = "";
|
let url = "";
|
||||||
try {
|
try {
|
||||||
const get_all = core.getBooleanInput("all");
|
|
||||||
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) {
|
} catch (e) {
|
||||||
core.setFailed(`Could not parse the download URL\n${e.message}`);
|
core.setFailed(`Could not parse the download URL\n${e.message}`);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
// Download Nextflow and add it to path
|
// Download Nextflow and add it to path
|
||||||
let nf_path = "";
|
let nf_path = "";
|
||||||
try {
|
nf_path = tc.find("nextflow", version);
|
||||||
const temp_install_dir = fs.mkdtempSync(`nextflow`);
|
|
||||||
nf_path = await retry(
|
if (!nf_path) {
|
||||||
async (bail) => {
|
core.debug(`Could not find Nextflow ${version} in cache`);
|
||||||
return await tc.downloadTool(url, `${temp_install_dir}/nextflow`);
|
const nf_install_path = await install_nextflow(url, version);
|
||||||
},
|
|
||||||
{
|
nf_path = await tc.cacheDir(nf_install_path, "nextflow", version);
|
||||||
onRetry: (err) => {
|
core.debug(`Added Nextflow to cache: ${nf_path}`);
|
||||||
core.debug(`Download of ${url} failed, trying again. Error: ${err}`);
|
|
||||||
},
|
io.rmRF(nf_install_path);
|
||||||
}
|
} else {
|
||||||
);
|
core.debug(`Using cached version of Nextflow: ${nf_path}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
core.addPath(nf_path);
|
||||||
|
|
||||||
core.addPath(temp_install_dir);
|
|
||||||
core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`);
|
core.info(`Downloaded \`nextflow\` to ${nf_path} and added to PATH`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
core.setFailed(e.message);
|
core.setFailed(e.message);
|
||||||
|
|
1
package-lock.json
generated
1
package-lock.json
generated
|
@ -11,6 +11,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.8.2",
|
"@actions/core": "^1.8.2",
|
||||||
"@actions/github": "^5.0.3",
|
"@actions/github": "^5.0.3",
|
||||||
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"semver": "^7.3.7"
|
"semver": "^7.3.7"
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.8.2",
|
"@actions/core": "^1.8.2",
|
||||||
"@actions/github": "^5.0.3",
|
"@actions/github": "^5.0.3",
|
||||||
|
"@actions/io": "^1.1.2",
|
||||||
"@actions/tool-cache": "^2.0.1",
|
"@actions/tool-cache": "^2.0.1",
|
||||||
"async-retry": "^1.3.3",
|
"async-retry": "^1.3.3",
|
||||||
"semver": "^7.3.7"
|
"semver": "^7.3.7"
|
||||||
|
|
Loading…
Reference in a new issue