update tool-cache for proxy and fix tests (#57)
update tool-cache for proxy and fix tests
This commit is contained in:
11
src/cache.ts
Normal file
11
src/cache.ts
Normal 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;
|
||||
}
|
||||
@@ -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
27
src/main.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user