Compare commits

...

29 commits

Author SHA1 Message Date
6d789993b6
wip: Update rebuilt script files 2024-02-09 08:20:13 -06:00
9a19a73647
chore: Remove unused parameters from debug configuration 2024-02-09 08:20:12 -06:00
d8993744fc
chore: Remove GITHUB_TOKEN from actrc 2024-02-09 08:20:11 -06:00
852c1c2d64
chore: Remove GitHub token from README 2024-02-09 08:20:10 -06:00
cd4c4de0d4
chore: Update CHANGELOG 2024-02-09 08:20:09 -06:00
661b592858
wip: Add build to repo for debugging purposes
This should be removed before merging. The only reason I'm doing this is
because Github actions provides no other way for me to test this action at
the scale that we need. If you are reading this past the v2.0 release,
then something went terribly wrong.
2024-02-09 08:20:08 -06:00
300e3aba80
chore!: Remove unused parameters from action.yml 2024-02-09 08:20:07 -06:00
1ee4e6e816
test: Add test for install_nextflow 2024-02-09 08:20:06 -06:00
3578fbc391
chore: Add ability to deal with temporary files generated by tests
The "install_nextflow" tests generate a new install of Nextflow every time
 they are run based on the "RUNNER_TEMP" environment variable. Deal with
this by adding our RUNNER_TEMP variable to the ava config and making sure
none of these installs get committed.
2024-02-09 08:20:05 -06:00
be0874ac4c
test: Add tests for Nextflow release version resolver 2024-02-09 08:20:04 -06:00
a30c5df9d2
feat!: Remove url resolver for NextflowRelease 2024-02-09 08:20:03 -06:00
c61ec5549a
feat!: Remove Octkit conversion function for NextflowRelease 2024-02-09 08:20:02 -06:00
ea3e21d0fa
test!: Remove testing utils for getting GitHub token
This is no longer needed under the new API.
2024-02-09 08:20:01 -06:00
f42a08db49
chore!: Remove octokit throttling dependency 2024-02-09 08:20:00 -06:00
c808397a09
feat!: Remove Octokit API 2024-02-09 08:19:59 -06:00
8013af975a
refactor!: Replace Octokit API with nf-core API in main script 2024-02-09 08:19:58 -06:00
a8257a33e4
refactor!: Rename NextflowRelease.allBinaryURL to NextflowRelease.downloadUrlAll
Another API consistency update.
2024-02-09 08:19:57 -06:00
e50352a811
refactor!: Rename NextflowRelease.binaryURL to NextflowRelease.downloadURL
Another API consistency change.
2024-02-09 08:19:56 -06:00
a9c11a2b4e
refactor!: Rename NextflowRelease.versionNumber to NextflowRelease.version
This is to preserve consistency with the new API
2024-02-09 08:19:55 -06:00
f144ed4bc0
feat!: Remove the "latest-*" version resolvers from get_nextflow_release
Not needed due to the new API
2024-02-09 08:19:55 -06:00
8c124f715d
fix: Fix the version number debug log 2024-02-09 08:19:54 -06:00
9231e026c0
test!: Remove version resolving tests for "latest*" versions
This functionality is now offloaded to the API.
2024-02-09 08:19:53 -06:00
120fbe0a2a
feat: Make get_nextflow_release compatible with arrays
Although it seems like we're moving backwards, the new API only supports a
single data dump. I still like the iterative nature rather, so tack on
array support.
2024-02-09 08:19:52 -06:00
27c92fbd84
feat: Add nf-core website API wrapper
Basically, a stand-in for OctoKit, but smarter.
2024-02-09 08:19:51 -06:00
e9ea6b06f5
feat: Add optional published_at field to NextflowRelease type
Per @ewels request, the API on nf-co.re includes a "published_at" field
with the date of each release. For future compatibility without breaking
anything current, add an optional field that can handle this additional
information.
2024-02-09 08:19:50 -06:00
5fc57fbcc8 chore: Update CHANGELOG 2024-02-09 08:18:27 -06:00
Matthias Hörtenhuber
a877f66559 Update node version 2024-02-09 08:18:27 -06:00
bdd63150d7
chore: Bump version in CHANGELOG to v1.5.2 2024-02-07 09:28:31 -06:00
7810249267
chore: Bump version is package.json to v1.5.2 2024-02-07 09:26:28 -06:00
20 changed files with 154 additions and 506 deletions

1
.actrc
View file

@ -1,3 +1,2 @@
-P ubuntu-latest=catthehacker/ubuntu:act-latest -P ubuntu-latest=catthehacker/ubuntu:act-latest
-s GITHUB_TOKEN
--container-architecture linux/amd64 --container-architecture linux/amd64

10
.gitignore vendored
View file

@ -89,7 +89,9 @@ out
# Nuxt.js build / generate output # Nuxt.js build / generate output
.nuxt .nuxt
dist # TODO: Remove the dist folder again after merging
# This folder is only committed right now to allow for remote testing
#dist
# Gatsby files # Gatsby files
.cache/ .cache/
@ -131,4 +133,8 @@ dist
# Ignore built ts files # Ignore built ts files
__tests__/runner/* __tests__/runner/*
lib/**/* lib/**/*
# Testing garbage
.tmp
nxf-v*

5
.vscode/launch.json vendored
View file

@ -13,10 +13,7 @@
"outFiles": ["${workspaceFolder}/lib/**/*.js"], "outFiles": ["${workspaceFolder}/lib/**/*.js"],
"env": { "env": {
"INPUT_ALL": "false", "INPUT_ALL": "false",
"INPUT_VERSION": "latest", "INPUT_VERSION": "v23.10",
"INPUT_TOKEN": "${env:GITHUB_TOKEN}",
"INPUT_COOLDOWN": "60",
"INPUT_MAX_RETRIES": "3",
"RUNNER_TEMP": "${workspaceFolder}/.tmp" "RUNNER_TEMP": "${workspaceFolder}/.tmp"
} }
} }

View file

@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Upgraded GitHub Actions node version to v20
## [1.5.2] - 2024-02-07
### Added ### Added
- CI workflow steps for better compatibility with <https://github.com/nektos/act> - CI workflow steps for better compatibility with <https://github.com/nektos/act>
@ -14,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Husky pre-commit hooks for linting and formatting - Husky pre-commit hooks for linting and formatting
- Deprecation messages to warn users of upcoming API switch - Deprecation messages to warn users of upcoming API switch
### Changed
- GitHub Octokit API switched to nf-core custom API
## [1.5.1] - 2024-01-30 ## [1.5.1] - 2024-01-30
### Changed ### Changed
@ -81,7 +91,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- GitHub Actions workflow to test Nextflow installation and downstream usage - GitHub Actions workflow to test Nextflow installation and downstream usage
- Documentation and license files - Documentation and license files
[unreleased]: https://github.com/nf-core/setup-nextflow/compare/v1.5.1...HEAD [unreleased]: https://github.com/nf-core/setup-nextflow/compare/v1.5.2...HEAD
[1.5.2]: https://github.com/nf-core/setup-nextflow/compare/v1.5.1...v1.5.2
[1.5.1]: https://github.com/nf-core/setup-nextflow/compare/v1.5.0...v1.5.1 [1.5.1]: https://github.com/nf-core/setup-nextflow/compare/v1.5.0...v1.5.1
[1.5.0]: https://github.com/nf-core/setup-nextflow/compare/v1.4.0...v1.5.0 [1.5.0]: https://github.com/nf-core/setup-nextflow/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/nf-core/setup-nextflow/compare/v1.3.0...v1.4.0 [1.4.0]: https://github.com/nf-core/setup-nextflow/compare/v1.3.0...v1.4.0

View file

@ -60,17 +60,6 @@ There are three (technically four) aliases to assist in choosing up-to-date Next
A boolean deciding whether to download the "all versions" distribution of Nextflow. May be useful for running tests against multiple versions downstream. A boolean deciding whether to download the "all versions" distribution of Nextflow. May be useful for running tests against multiple versions downstream.
### `token`
> **default: `${{ secrets.GITHUB_TOKEN }}`**
> **:warning: This really shouldn't be changed. If you think this will fix a workflow problem, triple-check everything else first. :warning:**
This action locates the releases based upon the GitHub API, and requires an access token. The default token provided with all GitHub actions should be sufficient for all use cases on GitHub. Valid reasons to change this:
- GitHub Enterprise server (and only under some configurations)
- Testing workflows locally with [act](https://github.com/nektos/act)
## Outputs ## Outputs
There are no outputs from this action. There are no outputs from this action.

View file

@ -10,24 +10,8 @@ inputs:
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:
description: "GitHub token to access the GitHub Releases API. The default token should be sufficient for all use cases."
required: false
default: ${{ github.token }}
deprecationMessage: "setup-nextflow@v2 will no longer use the GitHub API. A token will no longer be needed."
cooldown:
description: "Time (in seconds) to wait before querying the GitHub Releases API in the case of hitting a rate limit."
required: false
default: "60"
deprecationMessage: "setup-nextflow@v2 will no longer use the GitHub API. The cooldown will no longer apply."
max-retries:
description: "The number of times that to try querying the GitHub Releases API in case of a rate-limited failure."
required: false
default: "3"
deprecationMessage: "setup-nextflow@v2 will no longer use the GitHub API. The retry count will no longer apply."
runs: runs:
using: "node16" using: "node20"
main: "dist/index.js" main: "dist/index.js"
branding: branding:
icon: "shuffle" icon: "shuffle"

BIN
dist/LICENSE generated vendored Normal file

Binary file not shown.

BIN
dist/index.js generated vendored Normal file

Binary file not shown.

BIN
dist/index.js.map generated vendored Normal file

Binary file not shown.

BIN
dist/sourcemap-register.js generated vendored Normal file

Binary file not shown.

37
package-lock.json generated
View file

@ -1,6 +1,6 @@
{ {
"name": "install-nextflow-action", "name": "install-nextflow-action",
"version": "1.5.1", "version": "1.5.2",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
@ -13,7 +13,6 @@
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@octokit/plugin-throttling": "^8.1.3",
"@types/node": "^17.0.44", "@types/node": "^17.0.44",
"async-retry": "^1.3.3", "async-retry": "^1.3.3",
"semver": "^7.3.7" "semver": "^7.3.7"
@ -393,21 +392,6 @@
"@octokit/core": ">=5" "@octokit/core": ">=5"
} }
}, },
"node_modules/@octokit/plugin-throttling": {
"version": "8.1.3",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-8.1.3.tgz",
"integrity": "sha512-pfyqaqpc0EXh5Cn4HX9lWYsZ4gGbjnSmUILeu4u2gnuM50K/wIk9s1Pxt3lVeVwekmITgN/nJdoh43Ka+vye8A==",
"dependencies": {
"@octokit/types": "^12.2.0",
"bottleneck": "^2.15.3"
},
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"@octokit/core": "^5.0.0"
}
},
"node_modules/@octokit/request": { "node_modules/@octokit/request": {
"version": "8.1.6", "version": "8.1.6",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz",
@ -1179,11 +1163,6 @@
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==", "integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==",
"dev": true "dev": true
}, },
"node_modules/bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"node_modules/brace-expansion": { "node_modules/brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
@ -5957,15 +5936,6 @@
"@octokit/types": "^12.3.0" "@octokit/types": "^12.3.0"
} }
}, },
"@octokit/plugin-throttling": {
"version": "8.1.3",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-8.1.3.tgz",
"integrity": "sha512-pfyqaqpc0EXh5Cn4HX9lWYsZ4gGbjnSmUILeu4u2gnuM50K/wIk9s1Pxt3lVeVwekmITgN/nJdoh43Ka+vye8A==",
"requires": {
"@octokit/types": "^12.2.0",
"bottleneck": "^2.15.3"
}
},
"@octokit/request": { "@octokit/request": {
"version": "8.1.6", "version": "8.1.6",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-8.1.6.tgz",
@ -6504,11 +6474,6 @@
"integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==", "integrity": "sha512-DRQrD6gJyy8FbiE4s+bDoXS9hiW3Vbx5uCdwvcCf3zLHL+Iv7LtGHLpr+GZV8rHG8tK766FGYBwRbu8pELTt+w==",
"dev": true "dev": true
}, },
"bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",

View file

@ -1,6 +1,6 @@
{ {
"name": "install-nextflow-action", "name": "install-nextflow-action",
"version": "1.5.1", "version": "1.5.2",
"description": "An action to install Nextflow into a GitHub Actions workflow and make it available for subsequent steps.", "description": "An action to install Nextflow into a GitHub Actions workflow and make it available for subsequent steps.",
"main": "lib/src/main.js", "main": "lib/src/main.js",
"scripts": { "scripts": {
@ -28,6 +28,9 @@
"extensions": [ "extensions": [
"ts" "ts"
], ],
"environmentVariables": {
"RUNNER_TEMP": "./.tmp"
},
"rewritePaths": { "rewritePaths": {
"src/": "lib/" "src/": "lib/"
}, },
@ -51,7 +54,6 @@
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^6.0.0", "@actions/github": "^6.0.0",
"@actions/tool-cache": "^2.0.1", "@actions/tool-cache": "^2.0.1",
"@octokit/plugin-throttling": "^8.1.3",
"@types/node": "^17.0.44", "@types/node": "^17.0.44",
"async-retry": "^1.3.3", "async-retry": "^1.3.3",
"semver": "^7.3.7" "semver": "^7.3.7"

View file

@ -6,115 +6,15 @@ import semver from "semver"
import { NextflowRelease } from "./nextflow-release" import { NextflowRelease } from "./nextflow-release"
async function get_latest_everything_nextflow_release(
releases: AsyncGenerator<NextflowRelease>
): Promise<NextflowRelease> {
// Need to make sure we aren't in the edge case where a patch release is
// more recent chronologically than the edge release
let latest_release = {} as NextflowRelease
for await (const release of releases) {
// First iteration:
if (Object.keys(latest_release).length === 0) {
// If the most recent release is an edge release, then we have nothing to
// worry about, return it.
if (release.isEdge) {
return release
}
// Ok, so the most recent release is a stable release. We need to keep
// tabs on it
latest_release = release
continue
}
// A larger version number that is older than the "latest" release
// indicates that we've hit an edge release that is more up-to-date
// than a patch release. Return it.
if (semver.gt(release.versionNumber, latest_release.versionNumber, true)) {
return release
}
// A smaller version number that is also an edge release indicates that the
// chronologically most recent release is also the most up-to-date
if (
release.isEdge &&
semver.lt(release.versionNumber, latest_release.versionNumber, true)
) {
return latest_release
}
// Once we've hit the major.minor.0 of the version that is the most recent
// patch, we know that we would have traversed any edge releases along the
// way, so check to see if we've hit that point yet.
const latest_release_major = semver.major(
latest_release.versionNumber,
true
)
const latest_release_minor = semver.minor(
latest_release.versionNumber,
true
)
const latest_release_minver = `${latest_release_major}.${latest_release_minor}.0`
if (semver.eq(release.versionNumber, latest_release_minver, true)) {
return latest_release
}
}
// We should never get here, but just in case
return {} as NextflowRelease
}
async function get_latest_edge_nextflow_release(
releases: AsyncGenerator<NextflowRelease>
): Promise<NextflowRelease> {
// Because we don't have to worry about crossing between edge and stable
// releases, we can just return the first edge release we come across
for await (const release of releases) {
if (release.isEdge) {
return release
}
}
// We should never get here, but just in case
return {} as NextflowRelease
}
async function get_latest_stable_nextflow_release(
releases: AsyncGenerator<NextflowRelease>
): Promise<NextflowRelease> {
// Because we don't have to worry about crossing between edge and stable
// releases, we can just return the first stable release we come across
for await (const release of releases) {
if (!release.isEdge) {
return release
}
}
// We should never get here, but just in case
return {} as NextflowRelease
}
export async function get_nextflow_release( export async function get_nextflow_release(
version: string, version: string,
releases: AsyncGenerator<NextflowRelease> releases: NextflowRelease[] | AsyncGenerator<NextflowRelease>
): Promise<NextflowRelease> { ): Promise<NextflowRelease> {
// First, check to see if we are using a "latest-*" version system, and return
// early
if (version === "latest-everything") {
return await get_latest_everything_nextflow_release(releases)
}
if (version === "latest-edge") {
return await get_latest_edge_nextflow_release(releases)
}
if (version === "latest" || version === "latest-stable") {
return await get_latest_stable_nextflow_release(releases)
}
// The releases are sent in reverse chronological order // The releases are sent in reverse chronological order
// If we are sent a numbered tag, then back through the list until we find // If we are sent a numbered tag, then back through the list until we find
// a release that fulfils the requested version number // a release that fulfils the requested version number
for await (const release of releases) { for await (const release of releases) {
if (semver.satisfies(release.versionNumber, version, true)) { if (semver.satisfies(release.version, version, true)) {
return release return release
} }
} }
@ -127,8 +27,8 @@ export async function install_nextflow(
release: NextflowRelease, release: NextflowRelease,
get_all: boolean get_all: boolean
): Promise<string> { ): Promise<string> {
const url = get_all ? release.allBinaryURL : release.binaryURL const url = get_all ? release.downloadUrlAll : release.downloadUrl
const version = release.versionNumber const version = release.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(

View file

@ -11,10 +11,9 @@ import {
} from "./functions" } from "./functions"
import { NextflowRelease } from "./nextflow-release" import { NextflowRelease } from "./nextflow-release"
import { import {
pull_latest_stable_release, get_latest_nextflow_version,
pull_releases, get_nextflow_versions
setup_octokit } from "./nf-core-api-wrapper"
} from "./octokit-wrapper"
async function run(): Promise<void> { async function run(): Promise<void> {
// CAPSULE_LOG leads to a bunch of boilerplate being output to the logs: turn // CAPSULE_LOG leads to a bunch of boilerplate being output to the logs: turn
@ -22,33 +21,29 @@ async function run(): Promise<void> {
core.exportVariable("CAPSULE_LOG", "none") core.exportVariable("CAPSULE_LOG", "none")
// Read in the arguments // Read in the arguments
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")
const cooldown = Number(core.getInput("cooldown"))
const max_retries = Number(core.getInput("max-retries"))
// Check the cache for the Nextflow version that matched last time // Check the cache for the Nextflow version that matched last time
if (check_cache(version)) { if (check_cache(version)) {
return return
} }
// Setup the API
const octokit = await setup_octokit(token, cooldown, max_retries)
// Get the release info for the desired release // Get the release info for the desired release
let release = {} as NextflowRelease let release = {} as NextflowRelease
let resolved_version = "" let resolved_version = ""
try { try {
if (version === "latest" || version === "latest-stable") { if (version.includes("latest")) {
release = await pull_latest_stable_release(octokit) let flavor = version.split("-")[1]
flavor = flavor ? flavor : "stable"
release = await get_latest_nextflow_version(flavor)
} else { } else {
const release_iterator = pull_releases(octokit) const nextflow_releases = await get_nextflow_versions()
release = await get_nextflow_release(version, release_iterator) release = await get_nextflow_release(version, nextflow_releases)
} }
resolved_version = release.versionNumber resolved_version = release.version
core.info( core.info(
`Input version '${version}' resolved to Nextflow ${release["name"]}` `Input version '${version}' resolved to Nextflow ${release.version}`
) )
} catch (e: unknown) { } catch (e: unknown) {
if (e instanceof Error) { if (e instanceof Error) {

View file

@ -2,48 +2,9 @@
* Houses the pertinent data that GitHub exposes for each Nextflow release * Houses the pertinent data that GitHub exposes for each Nextflow release
*/ */
export type NextflowRelease = { export type NextflowRelease = {
versionNumber: string version: string
isEdge: boolean isEdge: boolean
binaryURL: string downloadUrl: string
allBinaryURL: string downloadUrlAll: string
} published_at?: string
/**
* Converts the raw OctoKit data into a structured NextflowRelease
* @param data A "release" data struct from OctoKit
* @returns `data` converted into a `NextflowRelease`
*/
export function nextflow_release(data: object): NextflowRelease {
const nf_release: NextflowRelease = {
versionNumber: data["tag_name"],
isEdge: data["prerelease"],
binaryURL: nextflow_bin_url(data, false),
allBinaryURL: nextflow_bin_url(data, true)
}
return nf_release
}
/**
* Gets the download URL of a Nextflow binary
* @param release A "release" data struct from OctoKit
* @param get_all Whether to return the url for the "all" variant of Nextflow
* @returns The URL of the Nextflow binary
*/
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")
})[0]
const regular_asset = release_assets.filter((a: object) => {
return a["name"] === "nextflow"
})[0]
const dl_asset = get_all ? all_asset : regular_asset
if (dl_asset) {
return dl_asset.browser_download_url
} else {
// Old pre-release versions of Nextflow didn't have an "all" variant. To
// avoid downstream errors, substitute the regular url here.
return regular_asset.browser_download_url
}
} }

View file

@ -0,0 +1,44 @@
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<object> {
// 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<NextflowRelease[]> {
const version_dataset = await fetch_nextflow_versions_data()
const versions = version_dataset["versions"]
const nextflow_releases: NextflowRelease[] = []
for (const element of versions) {
const release = element as NextflowRelease
nextflow_releases.push(release)
}
return nextflow_releases
}
export async function get_latest_nextflow_version(
flavor: string
): Promise<NextflowRelease> {
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
}

View file

@ -1,95 +0,0 @@
import * as core from "@actions/core"
import { getOctokitOptions, GitHub } from "@actions/github/lib/utils"
import { throttling } from "@octokit/plugin-throttling"
import { nextflow_release, NextflowRelease } from "./nextflow-release"
const NEXTFLOW_REPO = {
owner: "nextflow-io",
repo: "nextflow",
per_page: 100,
headers: {
"x-github-api-version": "2022-11-28"
}
}
export async function setup_octokit(
github_token: string,
cooldown = 60,
max_retries = 3
): Promise<InstanceType<typeof GitHub>> {
const throttledOctokit = GitHub.plugin(throttling)
let octokit = {} as InstanceType<typeof GitHub>
try {
octokit = new throttledOctokit(
getOctokitOptions(github_token, {
throttle: {
onRateLimit: (retryAfter, options, ok, retryCount) => {
ok.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
)
if (retryCount < max_retries) {
ok.log.info(`Retrying after ${retryAfter} seconds!`)
return true
}
},
onSecondaryRateLimit: (retryAfter, options, ok, retryCount) => {
ok.log.warn(
`SecondaryRateLimit detected for request ${options.method} ${options.url}`
)
if (retryCount < max_retries) {
octokit.log.info(`Retrying after ${retryAfter} seconds!`)
return true
}
},
fallbackSecondaryRateRetryAfter: cooldown
}
})
)
} catch (e: unknown) {
if (e instanceof Error) {
core.setFailed(
`Could not authenticate to GitHub Releases API with provided token\n${e.message}`
)
}
}
return octokit
}
export async function* pull_releases(
octokit: InstanceType<typeof GitHub>
): AsyncGenerator<NextflowRelease> {
const iterator = octokit.paginate.iterator(
octokit.rest.repos.listReleases,
NEXTFLOW_REPO
)
let item_index = 0
let release_items = []
/* eslint-disable-next-line @typescript-eslint/unbound-method */
const { next } = iterator[Symbol.asyncIterator]()
let request = await next()
release_items = request.value.data
while (true) {
if (item_index > release_items.length) {
request = await next()
release_items = request.value.data
item_index = 0
}
yield nextflow_release(release_items[item_index++])
}
}
export async function pull_latest_stable_release(
ok: InstanceType<typeof GitHub>
): Promise<NextflowRelease> {
const { data: stable_release } = await ok.rest.repos.getLatestRelease(
NEXTFLOW_REPO
)
return nextflow_release(stable_release)
}

View file

@ -1,6 +1,7 @@
import test from "ava" // eslint-disable-line import/no-unresolved import test from "ava" //eslint-disable-line import/no-unresolved
import { execSync } from "child_process"
import * as functions from "../src/functions" import { get_nextflow_release, install_nextflow } from "../src/functions"
import { NextflowRelease } from "../src/nextflow-release" import { NextflowRelease } from "../src/nextflow-release"
// The Nextflow releases we are going to use for testing follow a regular // The Nextflow releases we are going to use for testing follow a regular
@ -9,10 +10,10 @@ import { NextflowRelease } from "../src/nextflow-release"
function nf_release_gen(version_number: string): NextflowRelease { function nf_release_gen(version_number: string): NextflowRelease {
const is_edge = version_number.endsWith("-edge") const is_edge = version_number.endsWith("-edge")
const release: NextflowRelease = { const release: NextflowRelease = {
versionNumber: version_number, version: version_number,
isEdge: is_edge, isEdge: is_edge,
binaryURL: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow`, downloadUrl: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow`,
allBinaryURL: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow-${version_number.replace( downloadUrlAll: `https://github.com/nextflow-io/nextflow/releases/download/${version_number}/nextflow-${version_number.replace(
"v", "v",
"" ""
)}-all` )}-all`
@ -20,95 +21,85 @@ function nf_release_gen(version_number: string): NextflowRelease {
return release return release
} }
// A mock set of Nextflow releases const release_test_macro = test.macro(
async function* edge_is_newer(): AsyncGenerator<NextflowRelease> {
yield nf_release_gen("v23.09.1-edge")
yield nf_release_gen("v23.04.3")
yield nf_release_gen("v23.04.2")
}
async function* edge_is_older(): AsyncGenerator<NextflowRelease> {
yield nf_release_gen("v23.04.3")
yield nf_release_gen("v23.04.2")
yield nf_release_gen("v23.03.0-edge")
}
/*
The whole reason this action exists is to handle the cases where a final
release is the "bleeding edge" release, rather than the "edge" release, even
though that's what the name would imply. Therefore, we need to test that the
'latest-everything' parameter can find the correct one regardless of whether
an "edge" release or a stable release is the true latest
*/
const release_filter_macro = test.macro(
async ( async (
t, t,
input_version: string, input_version: string,
expected_version: string, expected_version: string,
releases: AsyncGenerator<NextflowRelease> is_edge_older: Boolean
) => { ) => {
const matched_release = await functions.get_nextflow_release( const releases_set = [
nf_release_gen("v21.05.1-edge"),
nf_release_gen("v21.05.0-edge"),
nf_release_gen("v21.04.2"),
nf_release_gen("v21.04.1"),
nf_release_gen("v21.04.0"),
nf_release_gen("v21.03.0-edge")
]
const release_filtered = releases_set.splice(is_edge_older ? 2 : 0)
const matched_release = await get_nextflow_release(
input_version, input_version,
releases release_filtered
) )
t.is(matched_release.versionNumber, expected_version) t.is(matched_release.version, expected_version)
} }
) )
test( test(
"Latest-everything install with newer edge release", "Major and minor version only (edge newer)",
release_filter_macro, release_test_macro,
"latest-everything", "v21.04",
"v23.09.1-edge", "v21.04.2",
edge_is_newer() false
) )
test( test(
"Latest-everything install with older edge release", "Major and minor version only (edge older)",
release_filter_macro, release_test_macro,
"latest-everything", "v21.04",
"v23.04.3", "v21.04.2",
edge_is_older() true
) )
test( test(
"Latest-edge install with newer edge release", "Major, minor, and patch version: latest patch (edge newer)",
release_filter_macro, release_test_macro,
"latest-edge", "v21.04.2",
"v23.09.1-edge", "v21.04.2",
edge_is_newer() false
) )
test( test(
"Latest-edge install with older edge release", "Major, minor, and patch version: latest patch (edge older)",
release_filter_macro, release_test_macro,
"latest-edge", "v21.04.2",
"v23.03.0-edge", "v21.04.2",
edge_is_older() true
) )
test( test(
"Latest-stable install with newer edge release", "Major, minor, and patch version: older patch (edge newer)",
release_filter_macro, release_test_macro,
"latest", "v21.04.1",
"v23.04.3", "v21.04.1",
edge_is_newer() false
) )
test( test(
"Latest-stable install with older edge release", "Major, minor, and patch version: older patch (edge older)",
release_filter_macro, release_test_macro,
"latest", "v21.04.1",
"v23.04.3", "v21.04.1",
edge_is_older() true
) )
test( test(
"Fully versioned tag release", "Edge release",
release_filter_macro, release_test_macro,
"v23.04.2", "v21.03.0-edge",
"v23.04.2", "v21.03.0-edge",
edge_is_newer() false
)
test(
"Partially versioned tag release",
release_filter_macro,
"v23.04",
"v23.04.3",
edge_is_newer()
) )
test.todo("install_nextflow") test("Install Nextflow", async t => {
const release = nf_release_gen("v23.10.1")
const install_dir = await install_nextflow(release, false)
const version_output = execSync(`${install_dir}/nextflow -v`).toString()
const version_regex = /nextflow version 23\.10\.1.*/
t.regex(version_output, version_regex)
})

View file

@ -1,89 +0,0 @@
import * as github from "@actions/github"
import { GitHub } from "@actions/github/lib/utils"
import anyTest, { TestFn } from "ava" // eslint-disable-line import/no-unresolved
import { NextflowRelease } from "../src/nextflow-release"
import {
pull_latest_stable_release,
pull_releases
} from "../src/octokit-wrapper"
import { getToken } from "./utils"
const test = anyTest as TestFn<{
token: string
octokit: InstanceType<typeof GitHub>
}>
test.before(t => {
const first = true
const current_token = getToken(first)
t.context = {
token: current_token,
octokit: github.getOctokit(current_token)
}
})
async function get_latest_release(
octokit: InstanceType<typeof GitHub>,
use_latest_api: boolean
): Promise<NextflowRelease> {
if (use_latest_api) {
return await pull_latest_stable_release(octokit)
} else {
const all_releases = pull_releases(octokit)
const first_response = await all_releases.next()
const first_release = first_response.value
? first_response.value
: ({} as NextflowRelease)
return first_release
}
}
const version_macro = test.macro(
async (t, object_name: string, use_latest_api: boolean) => {
const latest_release = await get_latest_release(
t.context.octokit,
use_latest_api
)
t.assert(latest_release[object_name])
}
)
test(
"OctoKit iterator returns semver-parsable version number",
version_macro,
"versionNumber",
false
)
test(
"OctoKit latest API returns semver-parable version number",
version_macro,
"versionNumber",
true
)
const binary_url_macro = test.macro(
async (t, get_all: boolean, use_latest_api: boolean) => {
const latest_release = await get_latest_release(
t.context.octokit,
use_latest_api
)
const url = get_all ? latest_release.allBinaryURL : latest_release.binaryURL
t.notThrows(() => new URL(url))
}
)
test("Nextflow binary URL from iterator valid", binary_url_macro, false, false)
test("Nextflow binary URL from latest API valid", binary_url_macro, false, true)
test(
"Nextflow all binary URL from iterator valid",
binary_url_macro,
true,
false
)
test(
"Nextflow all binary URL from latest API valid",
binary_url_macro,
true,
true
)

View file

@ -1,12 +0,0 @@
export function getToken(first: boolean): string {
const token = process.env["GITHUB_TOKEN"] || ""
if (!token && first) {
/* eslint-disable-next-line no-console */
console.warn(
"Skipping GitHub tests. Set $GITHUB_TOKEN to run REST client and GraphQL client tests"
)
first = false
}
return token
}