Skip to content

Commit a4955da

Browse files
authored
fix: remove custom and add global error handling (#46)
1 parent cb49096 commit a4955da

6 files changed

Lines changed: 28 additions & 64 deletions

File tree

build/index.js

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20413,15 +20413,9 @@ function authenticate(username, password) {
2041320413
const bin = process.platform === 'win32'
2041420414
? 'expo.cmd'
2041520415
: 'expo';
20416-
try {
20417-
yield cli.exec(bin, ['login', `--username=${username}`], {
20418-
env: Object.assign(Object.assign({}, process.env), { EXPO_CLI_PASSWORD: password }),
20419-
});
20420-
}
20421-
catch (error) {
20422-
core.setFailed(error);
20423-
throw error;
20424-
}
20416+
yield cli.exec(bin, ['login', `--username=${username}`], {
20417+
env: Object.assign(Object.assign({}, process.env), { EXPO_CLI_PASSWORD: password }),
20418+
});
2042520419
});
2042620420
}
2042720421
exports.authenticate = authenticate;
@@ -25945,9 +25939,17 @@ Promise._SomePromiseArray = SomePromiseArray;
2594525939

2594625940
"use strict";
2594725941

25942+
var __importStar = (this && this.__importStar) || function (mod) {
25943+
if (mod && mod.__esModule) return mod;
25944+
var result = {};
25945+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
25946+
result["default"] = mod;
25947+
return result;
25948+
};
2594825949
Object.defineProperty(exports, "__esModule", { value: true });
25950+
const core = __importStar(__webpack_require__(470));
2594925951
const run_1 = __webpack_require__(180);
25950-
run_1.run();
25952+
run_1.run().catch(core.setFailed);
2595125953

2595225954

2595325955
/***/ }),
@@ -54205,7 +54207,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5420554207
};
5420654208
Object.defineProperty(exports, "__esModule", { value: true });
5420754209
const lib_1 = __webpack_require__(484);
54208-
const core = __importStar(__webpack_require__(470));
5420954210
const toolCache = __importStar(__webpack_require__(533));
5421054211
const path_1 = __importDefault(__webpack_require__(622));
5421154212
const os_1 = __importDefault(__webpack_require__(87));
@@ -54242,15 +54243,9 @@ function fromRemoteCache(version, packager, customCacheKey) {
5424254243
// see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401
5424354244
const target = path_1.default.join(process.env['RUNNER_TOOL_CACHE'] || '', 'expo-cli', version, os_1.default.arch());
5424454245
const cacheKey = customCacheKey || getRemoteKey(version, packager);
54245-
try {
54246-
const hit = yield lib_1.restoreCache(target, cacheKey, cacheKey);
54247-
if (hit) {
54248-
return target;
54249-
}
54250-
}
54251-
catch (error) {
54252-
core.setFailed(error);
54253-
throw error;
54246+
const hit = yield lib_1.restoreCache(target, cacheKey, cacheKey);
54247+
if (hit) {
54248+
return target;
5425454249
}
5425554250
});
5425654251
}
@@ -54262,13 +54257,7 @@ exports.fromRemoteCache = fromRemoteCache;
5426254257
function toRemoteCache(source, version, packager, customCacheKey) {
5426354258
return __awaiter(this, void 0, void 0, function* () {
5426454259
const cacheKey = customCacheKey || getRemoteKey(version, packager);
54265-
try {
54266-
yield lib_1.saveCache(source, cacheKey);
54267-
}
54268-
catch (error) {
54269-
core.setFailed(error);
54270-
throw error;
54271-
}
54260+
yield lib_1.saveCache(source, cacheKey);
5427254261
});
5427354262
}
5427454263
exports.toRemoteCache = toRemoteCache;

src/cache.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { restoreCache, saveCache } from '@actions/cache/lib';
2-
import * as core from '@actions/core';
32
import * as toolCache from '@actions/tool-cache';
43
import path from 'path';
54
import os from 'os';
@@ -32,16 +31,10 @@ export async function fromRemoteCache(version: string, packager: string, customC
3231
// see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401
3332
const target = path.join(process.env['RUNNER_TOOL_CACHE'] || '', 'expo-cli', version, os.arch());
3433
const cacheKey = customCacheKey || getRemoteKey(version, packager);
34+
const hit = await restoreCache(target, cacheKey, cacheKey);
3535

36-
try {
37-
const hit = await restoreCache(target, cacheKey, cacheKey);
38-
39-
if (hit) {
40-
return target;
41-
}
42-
} catch (error) {
43-
core.setFailed(error);
44-
throw error;
36+
if (hit) {
37+
return target;
4538
}
4639
}
4740

@@ -52,12 +45,7 @@ export async function fromRemoteCache(version: string, packager: string, customC
5245
export async function toRemoteCache(source: string, version: string, packager: string, customCacheKey?: string) {
5346
const cacheKey = customCacheKey || getRemoteKey(version, packager);
5447

55-
try {
56-
await saveCache(source, cacheKey);
57-
} catch (error) {
58-
core.setFailed(error);
59-
throw error;
60-
}
48+
await saveCache(source, cacheKey);
6149
}
6250

6351
/**

src/expo.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@ export async function authenticate(username: string, password: string) {
1616
? 'expo.cmd'
1717
: 'expo';
1818

19-
try {
20-
await cli.exec(bin, ['login', `--username=${username}`], {
21-
env: {
22-
...process.env,
23-
EXPO_CLI_PASSWORD: password,
24-
},
25-
});
26-
} catch (error) {
27-
core.setFailed(error);
28-
throw error;
29-
}
19+
await cli.exec(bin, ['login', `--username=${username}`], {
20+
env: {
21+
...process.env,
22+
EXPO_CLI_PASSWORD: password,
23+
},
24+
});
3025
}

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as core from '@actions/core';
12
import { run } from './run';
23

3-
run();
4+
run().catch(core.setFailed);

tests/cache.test.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as remoteCache from '@actions/cache/lib';
2-
import * as core from '@actions/core';
32
import * as toolCache from '@actions/tool-cache';
43
import os from 'os';
54
import * as cache from '../src/cache';
@@ -29,7 +28,6 @@ describe('toLocalCache', () => {
2928

3029
describe('fromRemoteCache', () => {
3130
const spy = {
32-
fail: jest.spyOn(core, 'setFailed').mockImplementation(),
3331
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
3432
};
3533

@@ -70,13 +68,11 @@ describe('fromRemoteCache', () => {
7068
const error = new Error('Remote cache restore failed');
7169
spy.restore.mockRejectedValueOnce(error);
7270
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).rejects.toBe(error);
73-
expect(spy.fail).toBeCalledWith(error);
7471
});
7572
});
7673

7774
describe('toRemoteCache', () => {
7875
const spy = {
79-
fail: jest.spyOn(core, 'setFailed').mockImplementation(),
8076
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
8177
};
8278

@@ -97,6 +93,5 @@ describe('toRemoteCache', () => {
9793
const error = new Error('Remote cache save failed');
9894
spy.save.mockRejectedValueOnce(error);
9995
await expect(cache.toRemoteCache('/local/path', '3.20.1', 'yarn')).rejects.toBe(error);
100-
expect(spy.fail).toBeCalledWith(error);
10196
});
10297
});

tests/expo.test.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@ describe('authenticate', () => {
77
const spy = {
88
exec: jest.spyOn(cli, 'exec').mockImplementation(),
99
info: jest.spyOn(core, 'info').mockImplementation(),
10-
fail: jest.spyOn(core, 'setFailed').mockImplementation(),
1110
};
1211

1312
it('skips authentication without credentials', async () => {
1413
await expo.authenticate('', '');
1514
expect(spy.exec).not.toBeCalled();
16-
expect(spy.fail).not.toBeCalled();
1715
expect(spy.info).toBeCalled();
1816
});
1917

2018
it('skips authentication without password', async () => {
2119
await expo.authenticate('bycedric', '');
2220
expect(spy.exec).not.toBeCalled();
23-
expect(spy.fail).not.toBeCalled();
2421
expect(spy.info).toBeCalled();
2522
});
2623

@@ -51,6 +48,5 @@ describe('authenticate', () => {
5148
const error = new Error('Invalid username/password. Please try again.');
5249
spy.exec.mockRejectedValue(error);
5350
await expect(expo.authenticate('bycedric', 'incorrect')).rejects.toBe(error);
54-
expect(spy.fail).toBeCalledWith(error);
5551
});
5652
});

0 commit comments

Comments
 (0)