From e5a10d78e4c8dbefc754f738f30ecb7e3e06bf59 Mon Sep 17 00:00:00 2001 From: Cedric van Putten Date: Fri, 4 Dec 2020 19:16:34 +0100 Subject: [PATCH] refactor: group output by steps for readability --- .eslintrc.js | 1 + build/index.js | 14 +++++++++----- src/expo.ts | 1 + src/install.ts | 2 +- src/run.ts | 33 +++++++++++++++++++++++---------- tests/run.test.ts | 6 +++++- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 9805d64a..d176ef60 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -22,5 +22,6 @@ module.exports = { '@typescript-eslint/indent': ['error', 'tab'], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-use-before-define': 'off', + '@typescript-eslint/no-explicit-any': 'off', }, }; diff --git a/build/index.js b/build/index.js index e80758c5..ff1dc4e5 100644 --- a/build/index.js +++ b/build/index.js @@ -14098,21 +14098,24 @@ const install_1 = __webpack_require__(655); const system_1 = __webpack_require__(913); function run() { return __awaiter(this, void 0, void 0, function* () { - const path = yield install_1.install({ + const config = { version: core_1.getInput('expo-version') || 'latest', packager: core_1.getInput('expo-packager') || 'yarn', cache: (core_1.getInput('expo-cache') || 'false') === 'true', cacheKey: core_1.getInput('expo-cache-key') || undefined, - }); + }; + const path = yield core_1.group(config.cache + ? `Installing Expo CLI from cache or with ${config.packager}` + : `Installing Expo CLI with ${config.packager}`, () => install_1.install(config)); core_1.addPath(path); - yield expo_1.authenticate({ + yield core_1.group('Checking current authenticated account', () => expo_1.authenticate({ token: core_1.getInput('expo-token') || undefined, username: core_1.getInput('expo-username') || undefined, password: core_1.getInput('expo-password') || undefined, - }); + })); const shouldPatchWatchers = core_1.getInput('expo-patch-watchers') || 'true'; if (shouldPatchWatchers !== 'false') { - yield system_1.patchWatchers(); + yield core_1.group('Patching system watchers for the `ENOSPC` error', () => system_1.patchWatchers()); } }); } @@ -22837,6 +22840,7 @@ function authenticate(options) { return authWithCredentials(options.username, options.password); } core.info('Skipping authentication: `expo-token`, `expo-username`, and/or `expo-password` not set...'); + return Promise.resolve(); } exports.authenticate = authenticate; diff --git a/src/expo.ts b/src/expo.ts index 237326b6..3f9be7d6 100644 --- a/src/expo.ts +++ b/src/expo.ts @@ -67,4 +67,5 @@ export function authenticate(options: AuthOptions) { } core.info('Skipping authentication: `expo-token`, `expo-username`, and/or `expo-password` not set...'); + return Promise.resolve(); } diff --git a/src/install.ts b/src/install.ts index 3c2e6831..e7e94233 100644 --- a/src/install.ts +++ b/src/install.ts @@ -7,7 +7,7 @@ import { fromLocalCache, fromRemoteCache, toLocalCache, toRemoteCache } from './ // eslint-disable-next-line @typescript-eslint/no-var-requires const registry = require('libnpm'); -type InstallConfig = { +export type InstallConfig = { version: string; packager: string; cache?: boolean; diff --git a/src/run.ts b/src/run.ts index ede5425c..4d9b8849 100644 --- a/src/run.ts +++ b/src/run.ts @@ -1,27 +1,40 @@ -import { addPath, getInput } from '@actions/core'; +import { addPath, getInput, group } from '@actions/core'; import { authenticate } from './expo'; -import { install } from './install'; +import { install, InstallConfig } from './install'; import { patchWatchers } from './system'; export async function run() { - const path = await install({ + const config: InstallConfig = { version: getInput('expo-version') || 'latest', packager: getInput('expo-packager') || 'yarn', cache: (getInput('expo-cache') || 'false') === 'true', cacheKey: getInput('expo-cache-key') || undefined, - }); + }; + + const path = await group( + config.cache + ? `Installing Expo CLI from cache or with ${config.packager}` + : `Installing Expo CLI with ${config.packager}`, + () => install(config), + ); addPath(path); - await authenticate({ - token: getInput('expo-token') || undefined, - username: getInput('expo-username') || undefined, - password: getInput('expo-password') || undefined, - }); + await group( + 'Checking current authenticated account', + () => authenticate({ + token: getInput('expo-token') || undefined, + username: getInput('expo-username') || undefined, + password: getInput('expo-password') || undefined, + }), + ); const shouldPatchWatchers = getInput('expo-patch-watchers') || 'true'; if (shouldPatchWatchers !== 'false') { - await patchWatchers(); + await group( + 'Patching system watchers for the `ENOSPC` error', + () => patchWatchers(), + ); } } diff --git a/tests/run.test.ts b/tests/run.test.ts index f3879a52..31ec18b1 100644 --- a/tests/run.test.ts +++ b/tests/run.test.ts @@ -1,4 +1,8 @@ -const core = { addPath: jest.fn(), getInput: jest.fn() }; +const core = { + addPath: jest.fn(), + getInput: jest.fn(), + group: (message: string, action: () => Promise) => action() +}; const exec = { exec: jest.fn() }; const expo = { authenticate: jest.fn() }; const install = { install: jest.fn() };