Skip to content

Commit

Permalink
Update tool-cache for download retries (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsciple committed Mar 10, 2020
1 parent ada4b78 commit 83c9f7a
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 177 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ jobs:
- name: Verify node and npm
run: __tests__/verify-node.sh 10

test-fallback:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Clear tool cache
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
- name: Setup node 0.12.18 # For non LTS versions of Node, the zip is not always available
uses: ./ # and falls back to downloading node.exe and node.lib
with:
node-version: 0.12.18
- name: Verify node
shell: bash
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM

test-proxy:
runs-on: ubuntu-latest
container:
Expand Down
37 changes: 18 additions & 19 deletions __tests__/authutil.test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import io = require('@actions/io');
import fs = require('fs');
import path = require('path');

const tempDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);

const rcFile = path.join(tempDir, '.npmrc');

process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
process.env['RUNNER_TEMP'] = tempDir;
import * as io from '@actions/io';
import * as fs from 'fs';
import * as path from 'path';
import * as auth from '../src/authutil';

let rcFile: string;

describe('installer tests', () => {
beforeAll(async () => {
const tempDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);
await io.rmRF(tempDir);
await io.mkdirP(tempDir);
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
process.env['RUNNER_TEMP'] = tempDir;
rcFile = path.join(tempDir, '.npmrc');
}, 100000);

beforeEach(() => {
Expand Down
64 changes: 32 additions & 32 deletions __tests__/installer.test.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import io = require('@actions/io');
import fs = require('fs');
import os = require('os');
import path = require('path');

const toolDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'tools'
);
const tempDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);

process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
import * as io from '@actions/io';
import * as tc from '@actions/tool-cache';
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as installer from '../src/installer';

const IS_WINDOWS = process.platform === 'win32';
const isWindows = process.platform === 'win32';
let toolDir: string;

describe('installer tests', () => {
beforeAll(async () => {
toolDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'tools'
);
const tempDir = path.join(
__dirname,
'runner',
path.join(
Math.random()
.toString(36)
.substring(7)
),
'temp'
);
await io.rmRF(toolDir);
await io.rmRF(tempDir);
process.env['RUNNER_TOOL_CACHE'] = toolDir;
process.env['RUNNER_TEMP'] = tempDir;
}, 100000);

it('Acquires version of node if no matching version is installed', async () => {
await installer.getNode('10.16.0');
const nodeDir = path.join(toolDir, 'node', '10.16.0', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
if (isWindows) {
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
} else {
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
}
}, 100000);

if (IS_WINDOWS) {
if (isWindows) {
it('Falls back to backup location if first one doesnt contain correct version', async () => {
await installer.getNode('5.10.1');
const nodeDir = path.join(toolDir, 'node', '5.10.1', os.arch());
Expand Down Expand Up @@ -81,7 +81,7 @@ describe('installer tests', () => {
const nodeDir = path.join(toolDir, 'node', '8.8.1', os.arch());

expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
if (IS_WINDOWS) {
if (isWindows) {
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
} else {
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
Expand Down
16 changes: 10 additions & 6 deletions __tests__/verify-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ fi

node_version="$(node --version)"
echo "Found node version '$node_version'"
if [ -z "$(echo $node_version | grep v$1)" ]; then
if [ -z "$(echo $node_version | grep --fixed-strings v$1)" ]; then
echo "Unexpected version"
exit 1
fi

echo "Testing npm install"
mkdir -p test-npm-install
cd test-npm-install
npm init -y || exit 1
npm install @actions/core || exit 1
if [ -z "$2" ]; then
echo "Testing npm install"
mkdir -p test-npm-install
cd test-npm-install
npm init -y || exit 1
npm install @actions/core || exit 1
else
echo "Skip testing npm"
fi

0 comments on commit 83c9f7a

Please sign in to comment.