Skip to content

Commit a1496dd

Browse files
feat: add "lts" version option (denoland#97)
1 parent 95bbb87 commit a1496dd

File tree

6 files changed

+52
-4
lines changed

6 files changed

+52
-4
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
- "~1.32"
2424
- "b290fd01f3f5d32f9d010fc719ced0240759c049"
2525
- "rc"
26+
- "lts"
2627

2728
steps:
2829
- uses: actions/checkout@v3
@@ -111,5 +112,5 @@ jobs:
111112
- name: Build code
112113
run: deno run -A scripts/build.ts
113114

114-
- name: Assert no git changes
115+
- name: Assert no git changes (run `deno task build` if this fails)
115116
run: git diff --quiet

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ Targets the latest major, minor and patch version of Deno.
7070
deno-version: 2.0.0-rc.1
7171
```
7272
73+
### Latest LTS
74+
75+
```yaml
76+
- uses: denoland/setup-deno@v2
77+
with:
78+
deno-version: lts
79+
```
80+
7381
### Version from file
7482
7583
The extension can also automatically read the version file from

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ branding:
66
color: "gray-dark"
77
inputs:
88
deno-version:
9-
description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, or the Git hash of a specific canary release.
9+
description: The Deno version to install. Can be a semver version of a stable release, "canary" for the latest canary, "lts" for the latest LTS, or the Git hash of a specific canary release.
1010
default: "2.x"
1111
deno-version-file:
1212
description: File containing the Deno version to install such as .dvmrc or .tool-versions.

dist/main.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36389,6 +36389,10 @@ function parseVersionRange(version) {
3638936389
range: "latest",
3639036390
kind: "stable"
3639136391
};
36392+
if (version === "lts") return {
36393+
range: "latest",
36394+
kind: "lts"
36395+
};
3639236396
if (GIT_HASH_RE.test(version)) return {
3639336397
range: version,
3639436398
kind: "canary"
@@ -36410,6 +36414,7 @@ function getDenoVersionFromFile(versionFilePath) {
3641036414
function resolveVersion({ range, kind }) {
3641136415
if (kind === "canary") return resolveCanary(range);
3641236416
else if (kind === "rc") return resolveReleaseCandidate();
36417+
else if (kind === "lts") return resolveLTS();
3641336418
else return resolveRelease(range);
3641436419
}
3641536420
async function resolveCanary(range) {
@@ -36436,6 +36441,16 @@ async function resolveReleaseCandidate() {
3643636441
kind: "rc"
3643736442
};
3643836443
}
36444+
async function resolveLTS() {
36445+
const res = await fetchWithRetries("https://dl.deno.land/release-lts-latest.txt");
36446+
if (res.status !== 200) throw new Error("Failed to fetch LTS version info from dl.deno.land. Please try again later.");
36447+
const version = import_semver.default.clean((await res.text()).trim());
36448+
if (version === null) throw new Error("Failed to parse LTS version.");
36449+
return {
36450+
version,
36451+
kind: "lts"
36452+
};
36453+
}
3643936454
async function resolveRelease(range) {
3644036455
if (range === "latest") {
3644136456
const res = await fetchWithRetries("https://dl.deno.land/release-latest.txt");
@@ -38230,6 +38245,7 @@ async function install(version) {
3823038245
url = `https://dl.deno.land/release/v${version.version}/${zip}`;
3823138246
break;
3823238247
case "stable":
38248+
case "lts":
3823338249
url = `https://github.com/denoland/deno/releases/download/v${version.version}/${zip}`;
3823438250
break;
3823538251
}

src/install.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export async function install(version: Version) {
2828
url = `https://dl.deno.land/release/v${version.version}/${zip}`;
2929
break;
3030
case "stable":
31+
case "lts":
3132
url =
3233
`https://github.com/denoland/deno/releases/download/v${version.version}/${zip}`;
3334
break;

src/version.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ const GIT_HASH_RE = /^[0-9a-fA-F]{40}$/;
99

1010
export interface VersionRange {
1111
range: string;
12-
kind: "canary" | "rc" | "stable";
12+
kind: "canary" | "rc" | "stable" | "lts";
1313
}
1414

1515
export interface Version {
1616
version: string;
17-
kind: "canary" | "rc" | "stable";
17+
kind: "canary" | "rc" | "stable" | "lts";
1818
}
1919

2020
/** Parses the version from the user into a structure */
@@ -36,6 +36,10 @@ export function parseVersionRange(
3636
return { range: "latest", kind: "stable" };
3737
}
3838

39+
if (version === "lts") {
40+
return { range: "latest", kind: "lts" };
41+
}
42+
3943
if (GIT_HASH_RE.test(version)) {
4044
return { range: version, kind: "canary" };
4145
}
@@ -82,6 +86,8 @@ export function resolveVersion(
8286
} else if (kind === "rc") {
8387
// range is always "latest"
8488
return resolveReleaseCandidate();
89+
} else if (kind === "lts") {
90+
return resolveLTS();
8591
} else {
8692
return resolveRelease(range);
8793
}
@@ -120,6 +126,22 @@ async function resolveReleaseCandidate(): Promise<Version | null> {
120126
return { version, kind: "rc" };
121127
}
122128

129+
async function resolveLTS(): Promise<Version | null> {
130+
const res = await fetchWithRetries(
131+
"https://dl.deno.land/release-lts-latest.txt",
132+
);
133+
if (res.status !== 200) {
134+
throw new Error(
135+
"Failed to fetch LTS version info from dl.deno.land. Please try again later.",
136+
);
137+
}
138+
const version = semver.clean((await res.text()).trim());
139+
if (version === null) {
140+
throw new Error("Failed to parse LTS version.");
141+
}
142+
return { version, kind: "lts" };
143+
}
144+
123145
async function resolveRelease(range: string): Promise<Version | null> {
124146
if (range === "latest") {
125147
const res = await fetchWithRetries(

0 commit comments

Comments
 (0)