diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b9d4769..39539e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,7 +13,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] deno: - [1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049] + [1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049, rc] steps: - uses: actions/checkout@v3 diff --git a/README.md b/README.md index af64791..7871d8e 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,14 @@ Targets the latest major, minor and patch version of Deno. deno-version: e7b7129b7a92b7500ded88f8f5baa25a7f59e56e ``` +### Release candidate + +```yaml +- uses: denoland/setup-deno@v1 + with: + deno-version: rc +``` + ### Version from file The extension can also automatically read the version file from diff --git a/main.js b/main.js index 33574a0..cf13377 100644 --- a/main.js +++ b/main.js @@ -35,16 +35,13 @@ async function main() { exit("Could not resolve a version for the given range."); } - core.info( - `Going to install ${ - version.isCanary ? "canary" : "stable" - } version ${version.version}.`, - ); + core.info(`Going to install ${version.kind} version ${version.version}.`); await install(version); core.setOutput("deno-version", version.version); - core.setOutput("is-canary", version.isCanary); + // TODO(@crowlKats): change this output to "kind" + core.setOutput("is-canary", version.kind === "canary"); core.info("Installation complete."); } catch (err) { diff --git a/src/install.js b/src/install.js index abae86f..64bdc96 100644 --- a/src/install.js +++ b/src/install.js @@ -11,7 +11,7 @@ const tc = require("@actions/tool-cache"); async function install(version) { const cachedPath = tc.find( "deno", - version.isCanary ? `0.0.0-${version.version}` : version.version, + version.kind === "canary" ? `0.0.0-${version.version}` : version.version, ); if (cachedPath) { core.info(`Using cached Deno installation from ${cachedPath}.`); @@ -20,7 +20,7 @@ async function install(version) { } const zip = zipName(); - const url = version.isCanary + const url = version.kind === "canary" ? `https://dl.deno.land/canary/${version.version}/${zip}` : `https://dl.deno.land/release/v${version.version}/${zip}`; diff --git a/src/version.js b/src/version.js index 803b43d..e80e12b 100644 --- a/src/version.js +++ b/src/version.js @@ -7,13 +7,13 @@ const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/; /** * @typedef VersionRange * @property {string} range - * @property {boolean} isCanary + * @property {"canary" | "rc" | "release"} kind */ /** * @typedef Version * @property {string} version - * @property {boolean} isCanary + * @property {"canary" | "rc" | "release"} kind */ /** @@ -26,21 +26,25 @@ function parseVersionRange(version) { version = String(version) || "1.x"; version = version.trim(); - if (version == "canary") { - return { range: "latest", isCanary: true }; + if (version === "canary") { + return { range: "latest", kind: "canary" }; } - if (version == "latest") { - return { range: "latest", isCanary: false }; + if (version === "rc") { + return { range: "latest", kind: "rc" }; + } + + if (version === "latest") { + return { range: "latest", kind: "release" }; } if (GIT_HASH_RE.test(version)) { - return { range: version, isCanary: true }; + return { range: version, kind: "canary" }; } const range = semver.validRange(version); if (range !== null) { - return { range, isCanary: false }; + return { range, kind: "release" }; } return null; @@ -79,23 +83,59 @@ function getDenoVersionFromFile(versionFilePath) { * @param {VersionRange} range * @returns {Promise} */ -async function resolveVersion({ range, isCanary }) { - if (isCanary) { - if (range === "latest") { - const res = await fetchWithRetries( - "https://dl.deno.land/canary-latest.txt", +async function resolveVersion({ range, kind }) { + if (kind === "canary") { + return resolveCanary(range); + } else if (kind === "rc") { + // range is always "latest" + return resolveReleaseCandidate(); + } else { + return resolveRelease(range); + } +} + +/** + * @param {string} range + * @returns {Promise} + */ +async function resolveCanary(range) { + if (range === "latest") { + const res = await fetchWithRetries( + "https://dl.deno.land/canary-latest.txt", + ); + if (res.status !== 200) { + throw new Error( + "Failed to fetch canary version info from dl.deno.land. Please try again later.", ); - if (res.status !== 200) { - throw new Error( - "Failed to fetch canary version info from dl.deno.land. Please try again later.", - ); - } - const version = (await res.text()).trim(); - return { version, isCanary: true }; } - return { version: range, isCanary: true }; + const version = (await res.text()).trim(); + return { version, kind: "canary" }; + } else { + return { version: range, kind: "canary" }; + } +} + +/** + * @returns {Promise} + */ +async function resolveReleaseCandidate() { + const res = await fetchWithRetries( + "https://dl.deno.land/release-rc-latest.txt", + ); + if (res.status !== 200) { + throw new Error( + "Failed to fetch release candidate version info from dl.deno.land. Please try again later.", + ); } + const version = semver.clean((await res.text()).trim()); + return { version, kind: "rc" }; +} +/** + * @param {string} range + * @returns {Promise} + */ +async function resolveRelease(range) { if (range === "latest") { const res = await fetchWithRetries( "https://dl.deno.land/release-latest.txt", @@ -110,35 +150,35 @@ async function resolveVersion({ range, isCanary }) { if (version === null) { return null; } - return { version, isCanary: false }; - } + return { version, kind: "release" }; + } else { + const res = await fetchWithRetries("https://deno.com/versions.json"); + if (res.status !== 200) { + throw new Error( + "Failed to fetch stable version info from deno.com/versions.json. Please try again later.", + ); + } + const versionJson = await res.json(); + if (!("cli" in versionJson)) { + throw new Error("Fetched stable version info is invalid."); + } + /** @type {string[]} */ + const versions = versionJson.cli; + if (!Array.isArray(versions)) { + throw new Error("Fetched stable version info is invalid."); + } - const res = await fetchWithRetries("https://deno.com/versions.json"); - if (res.status !== 200) { - throw new Error( - "Failed to fetch stable version info from deno.com/versions.json. Please try again later.", - ); - } - const versionJson = await res.json(); - if (!("cli" in versionJson)) { - throw new Error("Fetched stable version info is invalid."); - } - /** @type {string[]} */ - const versions = versionJson.cli; - if (!Array.isArray(versions)) { - throw new Error("Fetched stable version info is invalid."); - } + let version = semver.maxSatisfying(versions, range); + if (version === null) { + return null; + } + version = semver.clean(version); + if (version === null) { + return null; + } - let version = semver.maxSatisfying(versions, range); - if (version === null) { - return null; - } - version = semver.clean(version); - if (version === null) { - return null; + return { version, kind: "release" }; } - - return { version, isCanary: false }; } /** @param {string} url */