From 34b2731a550e4a63105f875c5ceb0e992ccecde3 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Fri, 2 Feb 2024 10:40:23 -0600 Subject: [PATCH] feat: Add nf-core website API wrapper Basically, a stand-in for OctoKit, but smarter. --- src/nf-core-api-wrapper.ts | 45 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/nf-core-api-wrapper.ts diff --git a/src/nf-core-api-wrapper.ts b/src/nf-core-api-wrapper.ts new file mode 100644 index 0000000..2408d42 --- /dev/null +++ b/src/nf-core-api-wrapper.ts @@ -0,0 +1,45 @@ +import { info } from "@actions/core" +import { downloadTool } from "@actions/tool-cache" +import retry from "async-retry" +import { readFileSync } from "fs" + +import { NextflowRelease } from "./nextflow-release" + +async function fetch_nextflow_versions_data(): Promise { + // Occasionally the connection is reset for unknown reasons + // In those cases, retry the download + const versionsFile = await retry( + async () => { + return await downloadTool("https://nf-co.re/nextflow_version") + }, + { + retries: 5, + onRetry: (err: Error) => { + info(`Download of versions.json failed, trying again. Error: ${err}`) + } + } + ) + + return JSON.parse(readFileSync(versionsFile).toString()) +} + +export async function get_nextflow_versions(): Promise { + const version_dataset = await fetch_nextflow_versions_data() + const versions = version_dataset["versions"] + const nextflow_releases: NextflowRelease[] = [] + // eslint-disable-next-line github/array-foreach + versions.array.forEach(element => { + const release = element as NextflowRelease + nextflow_releases.push(release) + }) + return nextflow_releases +} + +export async function get_latest_nextflow_version( + flavor: string +): Promise { + const version_dataset = await fetch_nextflow_versions_data() + const latest_versions = version_dataset["latest"] + const latest_version = latest_versions[flavor] as NextflowRelease + return latest_version +}