9 Commits
8 changed files with 2422 additions and 589 deletions
+52
View File
@@ -0,0 +1,52 @@
name: build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install --global @zeit/ncc
- run: npm ci
- run: npm run lint
- run: npm run build
test-latest:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Setup just
uses: ./
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
run: |
[ "$(just --justfile tests/Justfile)" = "Test..." ]
shell: bash
test-version:
needs: test-latest
strategy:
matrix:
just-version: [0.4.5, 0.5.11, 0.6.1, 0.7.3, 0.8.3]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run self
uses: ./
with:
just-version: ${{ matrix.just-version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check version
run: just --version | grep "^just v${{ matrix.just-version }}$"
- name: Test
run: |
[ "$(just --justfile tests/Justfile)" = "Test..." ]
-37
View File
@@ -1,37 +0,0 @@
name: build
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12.x'
- run: npm install --global @zeit/ncc
- run: npm ci
- run: npm run lint
- run: npm run build
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Run self
uses: ./
with:
just-version: 0.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check just version
run: just --version | grep "^just v0.4.5$"
shell: bash
+13 -4
View File
@@ -9,10 +9,19 @@ This GitHub Action will install the latest release of the
### Inputs
| Name | Required | Description | Type | Default |
| -------------- | -------- | -------------------------------------------------------- | ------ | ------- |
| `just-version` | no | A valid semver specification for the version to install. | string | * |
| Name | Required | Description | Type | Default |
| -------------- | -------- | --------------------------------------- | ------ | ------- |
| `just-version` | no | A valid NPM-style semver specification. | string | * |
The semver specification is passed directly to NPM's [semver
package](https://www.npmjs.com/package/semver). This GitHub Action will install
the latest matching release. Examples include
- `just-version: '*'` latest version (default).
- `just-version: '0.8'` equivalent to `>=0.8.0 <0.9.0`.
- `just-version: '0.8.x'` equivalent to `>=0.8.0 <0.9.0`.
- `just-version: '0.8.3'` equivalent to `=0.8.3`.
- `just-version: '^0.8.3'` equivalent to `>=0.8.3 <0.9.0`.
### Basic example
@@ -21,7 +30,7 @@ Add the following to your workflow.
```yaml
- uses: extractions/setup-just@v1
with:
just-version: 0.5
just-version: 0.8
env:
# this is not required but add it if you get any rate limiting issues
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+1 -1
View File
File diff suppressed because one or more lines are too long
+2335 -389
View File
File diff suppressed because it is too large Load Diff
+11 -13
View File
@@ -1,13 +1,13 @@
{
"name": "setup-just",
"version": "1.2.0",
"version": "1.4.0",
"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",
"run": "npm run build && node dist/index.js"
"run": "npm run build && RUNNER_TOOL_CACHE=./runner/cache RUNNER_TEMP=./runner/temp node dist/index.js"
},
"repository": {
"type": "git",
@@ -20,18 +20,16 @@
},
"homepage": "https://github.com/extractions/setup-just#readme",
"dependencies": {
"@actions/core": "^1.2.5",
"@actions/tool-cache": "^1.3.4",
"@octokit/rest": "^18.0.5",
"semver": "^7.3.2"
"@actions/core": "^1.2.6",
"@extractions/setup-crate": "^0.2.1"
},
"devDependencies": {
"@types/node": "^14.10.1",
"@types/semver": "^7.3.3",
"@typescript-eslint/eslint-plugin": "^4.1.0",
"@typescript-eslint/parser": "^4.1.0",
"eslint": "^7.9.0",
"prettier": "^2.1.1",
"typescript": "^4.0.2"
"@types/node": "^14.11.6",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.4.0",
"@typescript-eslint/parser": "^4.4.0",
"eslint": "^7.10.0",
"prettier": "^2.1.2",
"typescript": "^4.0.3"
}
}
+8 -145
View File
@@ -1,153 +1,16 @@
import * as core from "@actions/core";
import * as tc from "@actions/tool-cache";
import * as semver from "semver";
import { Octokit } from "@octokit/rest";
/**
* @returns {string} the Rust target specifier for the current platform.
*/
function getTarget(): string {
const { arch, platform } = process;
if (arch == "x64") {
if (platform == "linux") {
return "x86_64-unknown-linux-musl";
} else if (platform == "darwin") {
return "x86_64-apple-darwin";
} else if (platform == "win32") {
return "x86_64-pc-windows-msvc";
}
}
throw new Error(
`failed to determine current target; arch = ${arch}, platform = ${platform}`
);
}
/**
* Represents a tool to install from GitHub.
*/
interface Tool {
/** The GitHub owner (username or organization). */
owner: string;
/** The name of the tool and the GitHub repo name. */
name: string;
/** A valid semantic version specifier for the tool. */
versionSpec?: string;
}
/**
* Represents a single release for a {@link Tool}.
*/
interface Release {
/** The exact release tag. */
version: string;
/** The asset download URL. */
downloadUrl: string;
}
/**
* Fetch the latest matching release for the given tool.
*
* @param tool the tool to fetch a release for.
* @param target the Rust target specifier that should be included in the GitHub
* release asset.
*
* @returns {Promise<Release>} a single GitHub release.
*/
async function getRelease(tool: Tool, target: string): Promise<Release> {
const { owner, name, versionSpec } = tool;
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
return octokit
.paginate(
octokit.repos.listReleases,
{ owner, repo: name },
(response, done) => {
const releases = response.data
.map((rel) => {
const asset = rel.assets.find((ass) => ass.name.includes(target));
if (asset) {
return {
version: rel.tag_name.replace(/^v/, ""),
downloadUrl: asset.browser_download_url,
};
}
})
.filter((rel) =>
rel && versionSpec
? semver.satisfies(rel.version, versionSpec)
: true
);
if (releases && done) {
done();
}
return releases;
}
)
.then((releases) => {
const release = releases.find((release) => release != null);
if (release === undefined) {
throw new Error(
`no release for ${name} matching version specifier ${versionSpec}`
);
}
return release;
});
}
/**
* Checks the tool cache for the tool, and if it is missing fetches it from
* GitHub releases.
*
* @param tool the tool to check or install.
* @param target the Rust target specifier that should be included in the GitHub
* release asset.
*
* @returns the directory containing the tool binary.
*/
async function checkOrInstallTool(tool: Tool, target: string): Promise<string> {
const { name, versionSpec } = tool;
// first check if we have previously donwloaded the tool
const cache = tc.find(name, versionSpec || "*");
if (cache) {
core.info(
`${name} matching version specifier ${versionSpec} found in cache`
);
return cache;
}
// find the latest release by querying GitHub API
const { version, downloadUrl } = await getRelease(tool, target);
// download, extract, and cache the tool
core.info(`Download from "${downloadUrl}"`);
const artifact = await tc.downloadTool(downloadUrl);
core.info("Extract downloaded archive");
const dir = `./${name}-${version}`;
let extractDir;
if (downloadUrl.endsWith(".zip")) {
extractDir = await tc.extractZip(artifact, dir);
} else {
extractDir = await tc.extractTar(artifact, dir);
}
return tc.cacheDir(extractDir, name, version);
}
import * as setup from "@extractions/setup-crate";
async function main() {
try {
const versionSpec = core.getInput("just-version");
const target = getTarget();
const cacheDir = await checkOrInstallTool(
{
owner: "casey",
name: "just",
versionSpec,
},
target
);
core.addPath(cacheDir);
const tool = await setup.checkOrInstallTool({
owner: "casey",
name: "just",
versionSpec,
});
core.addPath(tool.dir);
core.info(`Successfully setup ${tool.name} v${tool.version}`);
} catch (err) {
core.setFailed(err.message);
}
+2
View File
@@ -0,0 +1,2 @@
test:
@echo "Test..."