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

Commit

Permalink
fix: deno version match not work (#43)
Browse files Browse the repository at this point in the history
* fix: deno version match not work
  • Loading branch information
axetroy authored Jun 27, 2020
1 parent 09bb1b1 commit 91263d4
Show file tree
Hide file tree
Showing 3 changed files with 229 additions and 209 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:

- name: Set up Deno v${{ matrix.deno }}
uses: ./
with:
deno-version: ${{ matrix.deno }}

- name: Run deno
run: |
Expand Down
26 changes: 16 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4578,7 +4578,6 @@ async function getDeno(version) {
toolPath = tc.find("deno", version);
if (toolPath)
break walk;
version = await clearVersion(version);
// check cache
toolPath = tc.find("deno", version);
if (toolPath)
Expand All @@ -4591,6 +4590,11 @@ async function getDeno(version) {
core.addPath(toolPath);
}
exports.getDeno = getDeno;
// Get a clear version
// eg.
// 1.x -> 1.1.2
// 1.1.x -> 1.1.2
// 0.x -> 0.43.0
async function clearVersion(version) {
const c = semver.clean(version) || "";
if (semver.valid(c)) {
Expand All @@ -4614,6 +4618,7 @@ async function queryLatestMatch(versionSpec) {
}
let version = "";
const versions = (await getAvailableVersions()).sort(cmp);
core.debug(`found Deno versions '${JSON.stringify(versions, null, 2)}'`);
for (let i = versions.length - 1; i >= 0; --i) {
if (semver.satisfies(versions[i], versionSpec)) {
version = versions[i];
Expand All @@ -4632,8 +4637,11 @@ async function getAvailableVersions() {
// a temporary workaround until a Release API is provided. (#11)
const httpc = new HttpClient_1.HttpClient("setup-deno");
const body = await (await httpc.get("https://raw.githubusercontent.com/denoland/deno/master/Releases.md")).readBody();
const matches = body.matchAll(/### (v\d+\.\d+\.\d+)/g);
return [...matches].map(m => m[1]).filter(v => v !== "v0.0.0");
const matches = body.matchAll(/### (v?\d+\.\d+\.\d+)/g);
return [...matches]
.map(m => m[1])
.filter(v => v && v !== "v0.0.0")
.map(version => (version.startsWith("v") ? version : "v" + version));
}
exports.getAvailableVersions = getAvailableVersions;
function getDownloadUrl(version) {
Expand All @@ -4648,6 +4656,7 @@ function getDownloadUrl(version) {
else {
filename = `deno-${arch}-${platform}.zip`;
}
version = version.replace(/^v/, "");
return `https://github.com/denoland/deno/releases/download/v${version}/${filename}`;
}
exports.getDownloadUrl = getDownloadUrl;
Expand All @@ -4673,17 +4682,14 @@ async function extractDenoArchive(version, archiveFilepath) {
}
exports.extractDenoArchive = extractDenoArchive;
async function acquireDeno(version) {
core.debug(`acquire Deno '${version}'`);
//
// Download - a tool installer intimately knows how to get the tool (and construct urls)
//
const c = semver.clean(version);
if (c) {
version = c;
}
else {
throw new Error(`Unable to find Deno version ${version}`);
}
version = await clearVersion(version);
core.debug(`resolve Deno '${version}'`);
const downloadUrl = getDownloadUrl(version);
core.debug(`download Deno from '${downloadUrl}'`);
const downloadPath = await tc.downloadTool(downloadUrl);
//
// Extract
Expand Down
Loading

0 comments on commit 91263d4

Please sign in to comment.