diff --git a/__tests__/find-ruby.test.ts b/__tests__/find-ruby.test.ts new file mode 100644 index 0000000..44b6ba2 --- /dev/null +++ b/__tests__/find-ruby.test.ts @@ -0,0 +1,59 @@ +import * as io from '@actions/io'; +import fs = require('fs'); +import os = require('os'); +import path = require('path'); + +const toolDir = path.join(__dirname, 'runner', 'tools'); +const tempDir = path.join(__dirname, 'runner', 'temp'); + +process.env['RUNNER_TOOLSDIRECTORY'] = toolDir; +process.env['RUNNER_TEMPDIRECTORY'] = tempDir; + +import findRubyVersion from '../src/find-ruby'; + +describe('find-ruby', () => { + beforeAll(async () => { + await io.rmRF(toolDir); + await io.rmRF(tempDir); + }); + + afterAll(async () => { + try { + await io.rmRF(toolDir); + await io.rmRF(tempDir); + } catch { + console.log('Failed to remove test directories'); + } + }, 100000); + + it('findRubyVersion throws if cannot find any version of ruby', async () => { + let thrown = false; + try { + await findRubyVersion('>= 2.4'); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('findRubyVersion throws version of ruby is not complete', async () => { + let thrown = false; + const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch()); + await io.mkdirP(rubyDir); + try { + await findRubyVersion('>= 2.4'); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('findRubyVersion adds ruby bin to PATH', async () => { + const rubyDir: string = path.join(toolDir, 'Ruby', '2.4.6', os.arch()); + await io.mkdirP(rubyDir); + fs.writeFileSync(`${rubyDir}.complete`, 'hello'); + await findRubyVersion('>= 2.4'); + const binDir = path.join(rubyDir, 'bin'); + expect(process.env['PATH']!.startsWith(`${binDir};`)).toBe(true); + }); +}); diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts deleted file mode 100644 index 2c750df..0000000 --- a/__tests__/main.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import findRuby, {Platform} from '../src/find-ruby'; - -describe('TODO - Add a test suite', () => { - it('TODO - Add a test', async () => { - findRuby({addToPath: 'true', version: '>= 2.4'}, Platform.Windows); - }); -}); diff --git a/lib/find-ruby.js b/lib/find-ruby.js index 5624f7b..7827b14 100644 --- a/lib/find-ruby.js +++ b/lib/find-ruby.js @@ -15,6 +15,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); const exec = __importStar(require("@actions/exec")); const tc = __importStar(require("@actions/tool-cache")); const path = __importStar(require("path")); @@ -33,6 +34,7 @@ function default_1(version) { const dest = '/usr/bin/ruby'; exec.exec('sudo ln', ['-sf', path.join(toolPath, 'ruby'), dest]); // replace any existing } + core.addPath(toolPath); }); } exports.default = default_1; diff --git a/src/find-ruby.ts b/src/find-ruby.ts index 3c6c9ae..45178bd 100644 --- a/src/find-ruby.ts +++ b/src/find-ruby.ts @@ -1,3 +1,4 @@ +import * as core from '@actions/core'; import * as exec from '@actions/exec'; import * as tc from '@actions/tool-cache'; import * as path from 'path'; @@ -20,4 +21,6 @@ export default async function(version: string) { const dest: string = '/usr/bin/ruby'; exec.exec('sudo ln', ['-sf', path.join(toolPath, 'ruby'), dest]); // replace any existing } + + core.addPath(toolPath); }