Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update tool-cache we consume
  • Loading branch information
Danny McCormick committed Jun 5, 2019
commit d7b6952411a3cbdd88a9e18673219d64db132476
15 changes: 7 additions & 8 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import installer = require('../src/installer');
import io = require('@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 * as installer from '../src/installer';

describe('installer tests', () => {
beforeAll(() => {});
beforeAll(async () => {
// TODO - these should eventually be changed to match new method of loading dir
process.env['Runner.ToolsDirectory'] = toolDir;
process.env['Runner.TempDirectory'] = tempDir;
await io.rmRF(toolDir);
await io.rmRF(tempDir);
});
Expand Down Expand Up @@ -63,7 +62,7 @@ describe('installer tests', () => {
}, 100000);

it('Uses version of node installed in cache', async () => {
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// This will throw if it doesn't find it in the cache (because no such version exists)
Expand All @@ -72,7 +71,7 @@ describe('installer tests', () => {
});

it('Doesnt use version of node that was only partially installed in cache', async () => {
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
let thrown = false;
try {
Expand All @@ -86,7 +85,7 @@ describe('installer tests', () => {
});

it('Resolves semantic versions of node installed in cache', async () => {
const nodeDir: string = path.join(toolDir, '250.0.0', os.arch());
const nodeDir: string = path.join(toolDir, 'node', '250.0.0', os.arch());
await io.mkdirP(nodeDir);
fs.writeFileSync(`${nodeDir}.complete`, 'hello');
// These will throw if it doesn't find it in the cache (because no such version exists)
Expand Down
24 changes: 21 additions & 3 deletions lib/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// Load tempDirectory before it gets wiped by tool-cache
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || '';
const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io"));
const tc = __importStar(require("@actions/tool-cache"));
Expand All @@ -24,6 +26,22 @@ const path = __importStar(require("path"));
const semver = __importStar(require("semver"));
let osPlat = os.platform();
let osArch = os.arch();
if (!tempDirectory) {
let baseLocation;
if (process.platform === 'win32') {
// On windows use the USERPROFILE env variable
baseLocation = process.env['USERPROFILE'] || 'C:\\';
}
else {
if (process.platform === 'darwin') {
baseLocation = '/Users';
}
else {
baseLocation = '/home';
}
}
tempDirectory = path.join(baseLocation, 'actions', 'temp');
}
function getNode(versionSpec) {
return __awaiter(this, void 0, void 0, function* () {
// check cache
Expand Down Expand Up @@ -140,7 +158,7 @@ function acquireNode(version) {
downloadPath = yield tc.downloadTool(downloadUrl);
}
catch (err) {
if (err['httpStatusCode'] && err['httpStatusCode'] === '404') {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
return yield acquireNodeFromFallbackLocation(version);
}
throw err;
Expand Down Expand Up @@ -179,7 +197,7 @@ function acquireNodeFromFallbackLocation(version) {
return __awaiter(this, void 0, void 0, function* () {
// Create temporary folder to download in to
let tempDownloadFolder = 'temp_' + Math.floor(Math.random() * 2000000000);
let tempDir = path.join(__dirname, tempDownloadFolder);
let tempDir = path.join(tempDirectory, tempDownloadFolder);
yield io.mkdirP(tempDir);
let exeUrl;
let libUrl;
Expand All @@ -192,7 +210,7 @@ function acquireNodeFromFallbackLocation(version) {
yield io.mv(libPath, path.join(tempDir, 'node.lib'));
}
catch (err) {
if (err['httpStatusCode'] && err['httpStatusCode'] === '404') {
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
exeUrl = `https://nodejs.org/dist/v${version}/node.exe`;
libUrl = `https://nodejs.org/dist/v${version}/node.lib`;
const exePath = yield tc.downloadTool(exeUrl);
Expand Down
16 changes: 9 additions & 7 deletions node_modules/@actions/core/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions node_modules/@actions/exec/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions node_modules/@actions/exit/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions node_modules/@actions/io/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions node_modules/@actions/tool-cache/lib/tool-cache.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading