feat: support rc version (#72)

This commit is contained in:
Leo Kettmeir
2024-09-13 07:41:34 -07:00
committed by GitHub
parent 3a041055d2
commit f8480e68ca
6 changed files with 106 additions and 58 deletions

View File

@@ -13,7 +13,7 @@ jobs:
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
deno: deno:
[1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049] [1.x, "1.33.1", canary, ~1.32, b290fd01f3f5d32f9d010fc719ced0240759c049, rc]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3

View File

@@ -54,6 +54,14 @@ Targets the latest major, minor and patch version of Deno.
deno-version: e7b7129b7a92b7500ded88f8f5baa25a7f59e56e deno-version: e7b7129b7a92b7500ded88f8f5baa25a7f59e56e
``` ```
### Release candidate
```yaml
- uses: denoland/setup-deno@v1
with:
deno-version: rc
```
### Version from file ### Version from file
The extension can also automatically read the version file from The extension can also automatically read the version file from

View File

@@ -18,6 +18,8 @@ outputs:
description: "The Deno version that was installed." description: "The Deno version that was installed."
is-canary: is-canary:
description: "If the installed Deno version was a canary version." description: "If the installed Deno version was a canary version."
release-channel:
description: "The release channel of the installed version."
runs: runs:
using: "node20" using: "node20"
main: "main.js" main: "main.js"

10
main.js
View File

@@ -35,16 +35,14 @@ async function main() {
exit("Could not resolve a version for the given range."); exit("Could not resolve a version for the given range.");
} }
core.info( core.info(`Going to install ${version.kind} version ${version.version}.`);
`Going to install ${
version.isCanary ? "canary" : "stable"
} version ${version.version}.`,
);
await install(version); await install(version);
core.setOutput("deno-version", version.version); core.setOutput("deno-version", version.version);
core.setOutput("is-canary", version.isCanary); // TODO(@crowlKats): remove in 2.0
core.setOutput("is-canary", version.kind === "canary");
core.setOutput("release-channel", version.kind);
core.info("Installation complete."); core.info("Installation complete.");
} catch (err) { } catch (err) {

View File

@@ -11,7 +11,7 @@ const tc = require("@actions/tool-cache");
async function install(version) { async function install(version) {
const cachedPath = tc.find( const cachedPath = tc.find(
"deno", "deno",
version.isCanary ? `0.0.0-${version.version}` : version.version, version.kind === "canary" ? `0.0.0-${version.version}` : version.version,
); );
if (cachedPath) { if (cachedPath) {
core.info(`Using cached Deno installation from ${cachedPath}.`); core.info(`Using cached Deno installation from ${cachedPath}.`);
@@ -20,7 +20,7 @@ async function install(version) {
} }
const zip = zipName(); const zip = zipName();
const url = version.isCanary const url = version.kind === "canary"
? `https://dl.deno.land/canary/${version.version}/${zip}` ? `https://dl.deno.land/canary/${version.version}/${zip}`
: `https://dl.deno.land/release/v${version.version}/${zip}`; : `https://dl.deno.land/release/v${version.version}/${zip}`;

View File

@@ -7,13 +7,13 @@ const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/;
/** /**
* @typedef VersionRange * @typedef VersionRange
* @property {string} range * @property {string} range
* @property {boolean} isCanary * @property {"canary" | "rc" | "release"} kind
*/ */
/** /**
* @typedef Version * @typedef Version
* @property {string} 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 = String(version) || "1.x";
version = version.trim(); version = version.trim();
if (version == "canary") { if (version === "canary") {
return { range: "latest", isCanary: true }; return { range: "latest", kind: "canary" };
} }
if (version == "latest") { if (version === "rc") {
return { range: "latest", isCanary: false }; return { range: "latest", kind: "rc" };
}
if (version === "latest") {
return { range: "latest", kind: "release" };
} }
if (GIT_HASH_RE.test(version)) { if (GIT_HASH_RE.test(version)) {
return { range: version, isCanary: true }; return { range: version, kind: "canary" };
} }
const range = semver.validRange(version); const range = semver.validRange(version);
if (range !== null) { if (range !== null) {
return { range, isCanary: false }; return { range, kind: "release" };
} }
return null; return null;
@@ -79,23 +83,59 @@ function getDenoVersionFromFile(versionFilePath) {
* @param {VersionRange} range * @param {VersionRange} range
* @returns {Promise<Version | null>} * @returns {Promise<Version | null>}
*/ */
async function resolveVersion({ range, isCanary }) { function resolveVersion({ range, kind }) {
if (isCanary) { if (kind === "canary") {
if (range === "latest") { return resolveCanary(range);
const res = await fetchWithRetries( } else if (kind === "rc") {
"https://dl.deno.land/canary-latest.txt", // range is always "latest"
); return resolveReleaseCandidate();
if (res.status !== 200) { } else {
throw new Error( return resolveRelease(range);
"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 };
} }
}
/**
* @param {string} range
* @returns {Promise<Version | null>}
*/
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.",
);
}
const version = (await res.text()).trim();
return { version, kind: "canary" };
} else {
return { version: range, kind: "canary" };
}
}
/**
* @returns {Promise<Version | null>}
*/
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<Version | null>}
*/
async function resolveRelease(range) {
if (range === "latest") { if (range === "latest") {
const res = await fetchWithRetries( const res = await fetchWithRetries(
"https://dl.deno.land/release-latest.txt", "https://dl.deno.land/release-latest.txt",
@@ -110,35 +150,35 @@ async function resolveVersion({ range, isCanary }) {
if (version === null) { if (version === null) {
return 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"); let version = semver.maxSatisfying(versions, range);
if (res.status !== 200) { if (version === null) {
throw new Error( return null;
"Failed to fetch stable version info from deno.com/versions.json. Please try again later.", }
); version = semver.clean(version);
} if (version === null) {
const versionJson = await res.json(); return null;
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); return { version, kind: "release" };
if (version === null) {
return null;
} }
version = semver.clean(version);
if (version === null) {
return null;
}
return { version, isCanary: false };
} }
/** @param {string} url */ /** @param {string} url */