update tool-cache for proxy and fix tests (#57)

update tool-cache for proxy and fix tests
This commit is contained in:
Bryan MacFarlane
2020-01-31 13:57:22 -05:00
committed by GitHub
parent c38a6d4068
commit 9b0a0db81f
190 changed files with 4708 additions and 14158 deletions

11
src/cache.ts Normal file
View File

@@ -0,0 +1,11 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as path from 'path';
export async function find(version: string): Promise<string> {
const installDir: string | null = tc.find('Ruby', version);
let toolPath: string = installDir ? path.join(installDir, 'bin') : '';
return toolPath;
}

View File

@@ -1,15 +1 @@
import * as core from '@actions/core';
import * as tc from '@actions/tool-cache';
import * as path from 'path';
export async function findRubyVersion(version: string) {
const installDir: string | null = tc.find('Ruby', version);
if (!installDir) {
throw new Error(`Version ${version} not found`);
}
const toolPath: string = path.join(installDir, 'bin');
core.addPath(toolPath);
}
// TODO: support acquiring JIT

27
src/main.ts Normal file
View File

@@ -0,0 +1,27 @@
import * as core from '@actions/core';
import * as cache from './cache';
export async function run() {
try {
let versionSpec = core.getInput('ruby-version', {required: true});
if (!versionSpec) {
// deprecated
versionSpec = core.getInput('version');
}
// check in the VMs cache first
let toolPath: string = await cache.find(versionSpec);
// TODO: download JIT and/or ruby-build
if (!toolPath) {
core.setFailed(`Version ${versionSpec} not found`);
return;
}
core.addPath(toolPath);
} catch (error) {
// unhandled
core.setFailed(error.message);
}
}

View File

@@ -1,16 +1,3 @@
import * as core from '@actions/core';
import {findRubyVersion} from './installer';
async function run() {
try {
let version = core.getInput('version');
if (!version) {
version = core.getInput('ruby-version');
}
await findRubyVersion(version);
} catch (error) {
core.setFailed(error.message);
}
}
import {run} from './main';
run();