-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix #4
- Loading branch information
Showing
7 changed files
with
2,091 additions
and
1,962 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,37 @@ | ||
import path from "path"; | ||
import fs from "fs/promises"; | ||
import * as core from "@actions/core"; | ||
import * as tc from "@actions/tool-cache"; | ||
import { getOsTriplet } from "./platform"; | ||
import { versionWithPrefix } from "./versions"; | ||
|
||
export async function downloadScarb(repo, version) { | ||
const triplet = getOsTriplet(); | ||
const basename = `scarb-v${version}-${triplet}`; | ||
const tag = versionWithPrefix(version); | ||
const basename = `scarb-${tag}-${triplet}`; | ||
const extension = triplet.includes("-windows-") ? "zip" : "tar.gz"; | ||
const url = `https://github.com/${repo}/releases/download/v${version}/${basename}.${extension}`; | ||
const url = `https://github.com/${repo}/releases/download/${tag}/${basename}.${extension}`; | ||
|
||
core.info(`Downloading Scarb from ${url}`); | ||
const pathToTarball = await tc.downloadTool(url); | ||
|
||
const extract = url.endsWith(".zip") ? tc.extractZip : tc.extractTar; | ||
const extractedPath = await extract(pathToTarball); | ||
const pathToCli = path.join(extractedPath, basename); | ||
|
||
const pathToCli = await findScarbDir(extractedPath); | ||
|
||
core.debug(`Extracted to ${pathToCli}`); | ||
return pathToCli; | ||
} | ||
|
||
async function findScarbDir(extractedPath) { | ||
for (const dirent of await fs.readdir(extractedPath, { | ||
withFileTypes: true, | ||
})) { | ||
if (dirent.isDirectory() && dirent.name.startsWith("scarb-")) { | ||
return path.join(extractedPath, dirent.name); | ||
} | ||
} | ||
|
||
throw new Error(`could not find Scarb directory in ${extractedPath}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters