Skip to content

Commit 83c9f7a

Browse files
authored
Update tool-cache for download retries (#120)
1 parent ada4b78 commit 83c9f7a

File tree

8 files changed

+266
-177
lines changed

8 files changed

+266
-177
lines changed

.github/workflows/workflow.yml

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ jobs:
4040
- name: Verify node and npm
4141
run: __tests__/verify-node.sh 10
4242

43+
test-fallback:
44+
runs-on: windows-latest
45+
steps:
46+
- uses: actions/checkout@v2
47+
- name: Clear tool cache
48+
run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old"
49+
- name: Setup node 0.12.18 # For non LTS versions of Node, the zip is not always available
50+
uses: ./ # and falls back to downloading node.exe and node.lib
51+
with:
52+
node-version: 0.12.18
53+
- name: Verify node
54+
shell: bash
55+
run: __tests__/verify-node.sh 0.12.18 SKIP_NPM
56+
4357
test-proxy:
4458
runs-on: ubuntu-latest
4559
container:

__tests__/authutil.test.ts

+18-19
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
import io = require('@actions/io');
2-
import fs = require('fs');
3-
import path = require('path');
4-
5-
const tempDir = path.join(
6-
__dirname,
7-
'runner',
8-
path.join(
9-
Math.random()
10-
.toString(36)
11-
.substring(7)
12-
),
13-
'temp'
14-
);
15-
16-
const rcFile = path.join(tempDir, '.npmrc');
17-
18-
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
19-
process.env['RUNNER_TEMP'] = tempDir;
1+
import * as io from '@actions/io';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
204
import * as auth from '../src/authutil';
215

6+
let rcFile: string;
7+
228
describe('installer tests', () => {
239
beforeAll(async () => {
10+
const tempDir = path.join(
11+
__dirname,
12+
'runner',
13+
path.join(
14+
Math.random()
15+
.toString(36)
16+
.substring(7)
17+
),
18+
'temp'
19+
);
2420
await io.rmRF(tempDir);
2521
await io.mkdirP(tempDir);
22+
process.env['GITHUB_REPOSITORY'] = 'OwnerName/repo';
23+
process.env['RUNNER_TEMP'] = tempDir;
24+
rcFile = path.join(tempDir, '.npmrc');
2625
}, 100000);
2726

2827
beforeEach(() => {

__tests__/installer.test.ts

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
1-
import io = require('@actions/io');
2-
import fs = require('fs');
3-
import os = require('os');
4-
import path = require('path');
5-
6-
const toolDir = path.join(
7-
__dirname,
8-
'runner',
9-
path.join(
10-
Math.random()
11-
.toString(36)
12-
.substring(7)
13-
),
14-
'tools'
15-
);
16-
const tempDir = path.join(
17-
__dirname,
18-
'runner',
19-
path.join(
20-
Math.random()
21-
.toString(36)
22-
.substring(7)
23-
),
24-
'temp'
25-
);
26-
27-
process.env['RUNNER_TOOL_CACHE'] = toolDir;
28-
process.env['RUNNER_TEMP'] = tempDir;
1+
import * as io from '@actions/io';
2+
import * as tc from '@actions/tool-cache';
3+
import * as fs from 'fs';
4+
import * as os from 'os';
5+
import * as path from 'path';
296
import * as installer from '../src/installer';
307

31-
const IS_WINDOWS = process.platform === 'win32';
8+
const isWindows = process.platform === 'win32';
9+
let toolDir: string;
3210

3311
describe('installer tests', () => {
3412
beforeAll(async () => {
13+
toolDir = path.join(
14+
__dirname,
15+
'runner',
16+
path.join(
17+
Math.random()
18+
.toString(36)
19+
.substring(7)
20+
),
21+
'tools'
22+
);
23+
const tempDir = path.join(
24+
__dirname,
25+
'runner',
26+
path.join(
27+
Math.random()
28+
.toString(36)
29+
.substring(7)
30+
),
31+
'temp'
32+
);
3533
await io.rmRF(toolDir);
3634
await io.rmRF(tempDir);
35+
process.env['RUNNER_TOOL_CACHE'] = toolDir;
36+
process.env['RUNNER_TEMP'] = tempDir;
3737
}, 100000);
3838

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

4343
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
44-
if (IS_WINDOWS) {
44+
if (isWindows) {
4545
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
4646
} else {
4747
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);
4848
}
4949
}, 100000);
5050

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

8383
expect(fs.existsSync(`${nodeDir}.complete`)).toBe(true);
84-
if (IS_WINDOWS) {
84+
if (isWindows) {
8585
expect(fs.existsSync(path.join(nodeDir, 'node.exe'))).toBe(true);
8686
} else {
8787
expect(fs.existsSync(path.join(nodeDir, 'bin', 'node'))).toBe(true);

__tests__/verify-node.sh

+10-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ fi
77

88
node_version="$(node --version)"
99
echo "Found node version '$node_version'"
10-
if [ -z "$(echo $node_version | grep v$1)" ]; then
10+
if [ -z "$(echo $node_version | grep --fixed-strings v$1)" ]; then
1111
echo "Unexpected version"
1212
exit 1
1313
fi
1414

15-
echo "Testing npm install"
16-
mkdir -p test-npm-install
17-
cd test-npm-install
18-
npm init -y || exit 1
19-
npm install @actions/core || exit 1
15+
if [ -z "$2" ]; then
16+
echo "Testing npm install"
17+
mkdir -p test-npm-install
18+
cd test-npm-install
19+
npm init -y || exit 1
20+
npm install @actions/core || exit 1
21+
else
22+
echo "Skip testing npm"
23+
fi

0 commit comments

Comments
 (0)