mirror of
https://github.com/MillironX/setup-nextflow.git
synced 2024-11-22 09:49:56 +00:00
Merge pull request #15 from data-intuitive/run-unit-test-in-ci
Fix testing ci
This commit is contained in:
commit
b77a1defc2
5 changed files with 60 additions and 10 deletions
5
.github/workflows/test.yml
vendored
5
.github/workflows/test.yml
vendored
|
@ -23,5 +23,6 @@ jobs:
|
|||
- run: npm run format:check
|
||||
- run: npm run lint
|
||||
- run: npm run package
|
||||
# FIXME Token doesn't get passed correctly
|
||||
# - run: npm run test
|
||||
- run: npm run test
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
|
|
@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- If `fs.renameSync` fails (e.g. because source and destination files are on different partitions), try `fs.copySync` and `fs.unlinkSync` instead (#14).
|
||||
|
||||
## Fixed
|
||||
|
||||
- Re-enable npm run test in CI (#15).
|
||||
|
||||
- Fix release version check in unit test (#15).
|
||||
|
||||
- Add helper function for checking the latest releases in the unit tests (#15).
|
||||
|
||||
## [1.3.0] - 2023-05-19
|
||||
|
||||
## Changed
|
||||
|
|
|
@ -3,7 +3,7 @@ import { GitHub } from "@actions/github/lib/utils"
|
|||
import anyTest, { TestFn } from "ava" // eslint-disable-line import/no-unresolved
|
||||
|
||||
import * as functions from "../src/functions"
|
||||
import { getToken } from "./utils"
|
||||
import { getReleaseTag, getToken } from "./utils"
|
||||
|
||||
const test = anyTest as TestFn<{
|
||||
token: string
|
||||
|
@ -29,7 +29,8 @@ test("lastest_stable_release_data", async t => {
|
|||
t.context["octokit"]
|
||||
)
|
||||
t.is(typeof result, "object")
|
||||
t.is(result["tag_name"], "v22.10.2")
|
||||
const expected = await getReleaseTag("nextflow-io/nextflow", false)
|
||||
t.is(result["tag_name"], expected)
|
||||
})
|
||||
|
||||
test.todo("nextflow_bin_url")
|
||||
|
|
|
@ -3,7 +3,7 @@ import { GitHub } from "@actions/github/lib/utils"
|
|||
import anyTest, { TestFn } from "ava" // eslint-disable-line import/no-unresolved
|
||||
|
||||
import { release_data } from "../src/functions"
|
||||
import { getToken } from "./utils"
|
||||
import { getReleaseTag, getToken } from "./utils"
|
||||
|
||||
const test = anyTest as TestFn<{
|
||||
token: string
|
||||
|
@ -19,12 +19,22 @@ test.before(t => {
|
|||
}
|
||||
})
|
||||
|
||||
const macro = test.macro(async (t, version: string, expected: string) => {
|
||||
const macro = test.macro(async (t, version: string) => {
|
||||
let expected
|
||||
if (version === "latest-stable") {
|
||||
expected = await getReleaseTag("nextflow-io/nextflow", false)
|
||||
} else if (version === "latest-edge") {
|
||||
expected = await getReleaseTag("nextflow-io/nextflow", true)
|
||||
} else if (version === "latest-everything") {
|
||||
expected = await getReleaseTag("nextflow-io/nextflow", undefined)
|
||||
} else {
|
||||
expected = version
|
||||
}
|
||||
const result = await release_data(version, t.context["octokit"])
|
||||
t.is(result["tag_name"], expected)
|
||||
})
|
||||
|
||||
test("hard version", macro, "v22.10.2", "v22.10.2")
|
||||
test("latest-stable", macro, "latest-stable", "v22.10.2")
|
||||
test("latest-edge", macro, "latest-edge", "v22.09.7-edge")
|
||||
test("latest-everything", macro, "latest-everything", "v22.10.2")
|
||||
test("hard version", macro, "v22.10.2")
|
||||
test("latest-stable", macro, "latest-stable")
|
||||
test("latest-edge", macro, "latest-edge")
|
||||
test("latest-everything", macro, "latest-everything")
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import fetch from "node-fetch"
|
||||
|
||||
export function getToken(first: boolean): string {
|
||||
const token = process.env["GITHUB_TOKEN"] || ""
|
||||
if (!token && first) {
|
||||
|
@ -10,3 +12,31 @@ export function getToken(first: boolean): string {
|
|||
|
||||
return token
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the release from a GitHub repository. This function allows to fetch
|
||||
* either the latest release or the latest pre-release ("edge" release).
|
||||
*
|
||||
* @param {string} repo - The GitHub repository to fetch the release from,
|
||||
* in the format 'owner/repo'.
|
||||
* @param {boolean} [prerelease] - If true, fetches the latest pre-release.
|
||||
* If false or undefined, fetches the latest release regardless of whether
|
||||
* it's a pre-release or not.
|
||||
*
|
||||
* @returns {Promise<string>} A Promise that resolves to a string representing the tag name
|
||||
* of the found release. If no release is found, the Promise resolves to 'Release not found'.
|
||||
*/
|
||||
export async function getReleaseTag(
|
||||
repo: string,
|
||||
prerelease?: boolean
|
||||
): Promise<string> {
|
||||
const response = await fetch(`https://api.github.com/repos/${repo}/releases`)
|
||||
const releases = await response.json()
|
||||
|
||||
const release = releases.find(
|
||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||
(rel: any) => prerelease === undefined || rel.prerelease === prerelease
|
||||
)
|
||||
|
||||
return release ? release.tag_name : "No release found"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue