Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
use official versions file (#74)
Browse files Browse the repository at this point in the history
fixed #47, #58
  • Loading branch information
zhmushan authored Dec 2, 2020
1 parent 4df079f commit f9b45b3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions src/installer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Version, Arch, Platform } from "./types";
import type { Version, Arch, Platform, DenoVersions } from "./types";

import * as os from "os";
import * as path from "path";
Expand Down Expand Up @@ -38,6 +38,8 @@ import * as io from "@actions/io";
import { v4 as uuidV4 } from "uuid";
import { HttpClient } from "@actions/http-client";

import * as deprecatedVersions from "./versions-before-0.34.0.json";

function getDenoArch(version: Version): Arch {
return version === "nightly"
? "x86_64"
Expand Down Expand Up @@ -131,19 +133,18 @@ async function queryLatestMatch(versionSpec: Version): Promise<string> {
}

export async function getAvailableVersions(): Promise<string[]> {
// a temporary workaround until a Release API is provided. (#11)
const httpc = new HttpClient("setup-deno");
const body = await (
await httpc.get(
"https://raw.githubusercontent.com/denoland/deno/master/Releases.md"
const body = (
await httpc.getJson<DenoVersions>(
"https://raw.githubusercontent.com/denoland/deno_website2/master/versions.json"
)
).readBody();
const matches = body.matchAll(/### (v?\d+\.\d+\.\d+)/g);
).result;

if (body === null) {
throw new Error("Unable to fetch Deno versions");
}

return [...matches]
.map((m) => m[1])
.filter((v) => v && v !== "v0.0.0")
.map((version) => (version.startsWith("v") ? version : "v" + version));
return [...Object.keys(body.cli_to_std), ...deprecatedVersions];
}

export function getDownloadUrl(version: Version): string {
Expand Down
9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ export type ArchOld = "x64";
export type Arch = "x86_64" | ArchOld;

export type Version = LiteralUnion<"nightly", string>;

/**
* https://raw.githubusercontent.com/denoland/deno_website2/master/versions.json
*/
export interface DenoVersions {
std: string[];
cli: string[];
cli_to_std: Record<string, string>;
}
69 changes: 69 additions & 0 deletions src/versions-before-0.34.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[
"v0.33.0",
"v0.32.0",
"v0.31.0",
"v0.30.0",
"v0.29.0",
"v0.28.1",
"v0.28.0",
"v0.27.0",
"v0.26.0",
"v0.25.0",
"v0.24.0",
"v0.23.0",
"v0.22.0",
"v0.21.0",
"v0.20.0",
"v0.19.0",
"v0.18.0",
"v0.17.0",
"v0.16.0",
"v0.15.0",
"v0.14.0",
"v0.13.0",
"v0.12.0",
"v0.11.0",
"v0.10.0",
"v0.9.0",
"v0.8.0",
"v0.7.0",
"v0.6.0",
"v0.5.0",
"v0.4.0",
"v0.3.10",
"v0.3.9",
"v0.3.8",
"v0.3.7",
"v0.3.6",
"v0.3.5",
"v0.3.4",
"v0.3.3",
"v0.3.2",
"v0.3.1",
"v0.3.0",
"v0.2.11",
"v0.2.10",
"v0.2.9",
"v0.2.8",
"v0.2.7",
"v0.2.6",
"v0.2.5",
"v0.2.4",
"v0.2.3",
"v0.2.2",
"v0.2.1",
"v0.2.0",
"v0.1.12",
"v0.1.11",
"v0.1.10",
"v0.1.9",
"v0.1.8",
"v0.1.7",
"v0.1.6",
"v0.1.5",
"v0.1.4",
"v0.1.3",
"v0.1.2",
"v0.1.1",
"v0.1.0"
]
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"module": "CommonJS",
"outDir": "./lib",
"rootDir": "./src",
"strict": true
"strict": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "**/*.test.ts"]
}

0 comments on commit f9b45b3

Please sign in to comment.