mirror of
https://github.com/extractions/setup-just
synced 2026-09-07 20:04:00 +00:00
Add basic implementation
This commit is contained in:
+2
-1
@@ -4,7 +4,8 @@
|
||||
"es6": true
|
||||
},
|
||||
"extends": [
|
||||
"airbnb-base"
|
||||
"eslint:recommended",
|
||||
"plugin:@typescript-eslint/eslint-recommended"
|
||||
],
|
||||
"globals": {
|
||||
"Atomics": "readonly",
|
||||
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
+412
-596
File diff suppressed because it is too large
Load Diff
+10
-6
@@ -4,8 +4,10 @@
|
||||
"description": "Install the just command runner",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"fmt": "node node_modules/.bin/prettier --write **/*.ts",
|
||||
"lint": "node node_modules/.bin/eslint **/*.ts",
|
||||
"build": "rm -rf dist/ && ncc build src/index.ts --minify"
|
||||
"build": "rm -rf dist/ && ncc build src/index.ts --minify",
|
||||
"run": "npm run build && node dist/index.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -18,16 +20,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/extractions/setup-just#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.3"
|
||||
"@actions/core": "^1.2.3",
|
||||
"@actions/tool-cache": "^1.3.4",
|
||||
"@octokit/rest": "^17.6.0",
|
||||
"semver": "^7.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^13.13.2",
|
||||
"@types/semver": "^7.1.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.29.0",
|
||||
"@typescript-eslint/parser": "^2.29.0",
|
||||
"@typescript-eslint/eslint-plugin": "^2.30.0",
|
||||
"@typescript-eslint/parser": "^2.30.0",
|
||||
"eslint": "^6.8.0",
|
||||
"eslint-config-airbnb-base": "^14.1.0",
|
||||
"eslint-plugin-import": "^2.20.2",
|
||||
"prettier": "^2.0.5",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
|
||||
+85
-4
@@ -1,10 +1,91 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as core from "@actions/core";
|
||||
import * as tc from "@actions/tool-cache";
|
||||
import * as semver from "semver";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
|
||||
class Release {
|
||||
version: string;
|
||||
downloadUrl: string;
|
||||
|
||||
constructor(version: string, downloadUrl: string) {
|
||||
this.version = version;
|
||||
this.downloadUrl = downloadUrl;
|
||||
}
|
||||
}
|
||||
|
||||
async function getRelease(versionSpec?: string): Promise<Release | undefined> {
|
||||
const octokit = new Octokit();
|
||||
return octokit
|
||||
.paginate(
|
||||
octokit.repos.listReleases,
|
||||
{ owner: "casey", repo: "just" },
|
||||
(response, done) => {
|
||||
const releases = response.data
|
||||
.map((rel) => {
|
||||
const asset = rel.assets.find((ass) =>
|
||||
ass.name.includes(process.platform)
|
||||
);
|
||||
if (asset) {
|
||||
return new Release(
|
||||
rel.tag_name.replace(/^v/, ""),
|
||||
asset.browser_download_url
|
||||
);
|
||||
}
|
||||
})
|
||||
.filter((rel) =>
|
||||
rel && versionSpec
|
||||
? semver.satisfies(rel.version, versionSpec)
|
||||
: true
|
||||
);
|
||||
if (releases && done) {
|
||||
done();
|
||||
}
|
||||
return releases;
|
||||
}
|
||||
)
|
||||
.then((releases) => releases.find(Boolean));
|
||||
}
|
||||
|
||||
async function checkOrInstallTool(
|
||||
toolName: string,
|
||||
versionSpec?: string
|
||||
): Promise<string> {
|
||||
// first check if we have previously donwloaded the tool
|
||||
const cache = tc.find(toolName, versionSpec || "*");
|
||||
if (cache) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
// find the latest release by querying GitHub API
|
||||
const release = await getRelease(versionSpec);
|
||||
if (release === undefined) {
|
||||
throw new Error(
|
||||
`no release for ${toolName} matching version spec ${versionSpec}`
|
||||
);
|
||||
}
|
||||
|
||||
// download, extract and cache the tool
|
||||
core.info(`Download from "${release.downloadUrl}"`);
|
||||
const artifact = await tc.downloadTool(release.downloadUrl);
|
||||
|
||||
core.info("Extract downloaded archive");
|
||||
const dir = `./just-${release.version}`;
|
||||
|
||||
let extractDir;
|
||||
if (release.downloadUrl.endsWith(".zip")) {
|
||||
extractDir = await tc.extractZip(artifact, dir);
|
||||
} else {
|
||||
extractDir = await tc.extractTar(artifact, dir);
|
||||
}
|
||||
|
||||
return tc.cacheDir(extractDir, "just", release.version);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const version: string | null = core.getInput('version') || null;
|
||||
// TODO
|
||||
core.info(`[setup-just] installed just v${version}`);
|
||||
const version = core.getInput("version");
|
||||
const cacheDir = await checkOrInstallTool("just", version);
|
||||
core.addPath(cacheDir);
|
||||
} catch (err) {
|
||||
core.setFailed(err.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user