This repository has been archived by the owner on Feb 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from actions/features/getRubyVersion
First attempt at find ruby action
- Loading branch information
Showing
7 changed files
with
145 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = 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")); | ||
const IS_WINDOWS = process.platform === 'win32'; | ||
function default_1(version) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const installDir = tc.find('Ruby', version); | ||
if (!installDir) { | ||
throw new Error(`Version ${version} not found`); | ||
} | ||
const toolPath = path.join(installDir, 'bin'); | ||
if (!IS_WINDOWS) { | ||
// Ruby / Gem heavily use the '#!/usr/bin/ruby' to find ruby, so this task needs to | ||
// replace that version of ruby so all the correct version of ruby gets selected | ||
// replace the default | ||
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as core from '@actions/core'; | ||
import * as exec from '@actions/exec'; | ||
import * as tc from '@actions/tool-cache'; | ||
import * as path from 'path'; | ||
|
||
const IS_WINDOWS = process.platform === 'win32'; | ||
|
||
export default async function(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'); | ||
|
||
if (!IS_WINDOWS) { | ||
// Ruby / Gem heavily use the '#!/usr/bin/ruby' to find ruby, so this task needs to | ||
// replace that version of ruby so all the correct version of ruby gets selected | ||
// replace the default | ||
const dest: string = '/usr/bin/ruby'; | ||
exec.exec('sudo ln', ['-sf', path.join(toolPath, 'ruby'), dest]); // replace any existing | ||
} | ||
|
||
core.addPath(toolPath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import * as core from '@actions/core'; | ||
import findRubyVersion from './find-ruby'; | ||
|
||
async function run() { | ||
const myInput = core.getInput('myInput'); | ||
core.debug(`Hello ${myInput}`); | ||
try { | ||
const version = core.getInput('version'); | ||
await findRubyVersion(version); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
} | ||
|
||
run(); |