|
1 | | -import { addPath, getBooleanInput, getInput, group, info } from '@actions/core'; |
| 1 | +import { getBooleanInput, getInput, group, info } from '@actions/core'; |
2 | 2 |
|
3 | | -import { install } from '../install'; |
4 | | -import { resolveVersion } from '../packager'; |
5 | | -import * as tools from '../tools'; |
| 3 | +import { restoreFromCache, saveToCache } from '../cacher'; |
| 4 | +import { installPackage, resolvePackage } from '../packager'; |
| 5 | +import { executeAction, expoAuthenticate, findTool, installToolFromPackage, patchWatchers } from '../worker'; |
6 | 6 |
|
7 | 7 | // Auto-execute in GitHub actions |
8 | | -tools.performAction(setupAction); |
9 | | - |
10 | | -export async function setupAction(): Promise<void> { |
11 | | - const expoVersion = await installCli('expo-cli'); |
12 | | - const easVersion = await installCli('eas-cli'); |
13 | | - |
14 | | - await group('Checking current authenticated account', () => |
15 | | - tools.maybeAuthenticate({ |
16 | | - cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined, |
17 | | - token: getInput('token') || undefined, |
18 | | - username: getInput('username') || undefined, |
19 | | - password: getInput('password') || undefined, |
20 | | - }) |
21 | | - ); |
22 | | - |
23 | | - if (!getInput('patch-watchers') || getBooleanInput('patch-watchers') !== false) { |
24 | | - await group('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers()); |
25 | | - } |
| 8 | +executeAction(setupAction); |
| 9 | + |
| 10 | +export type SetupInput = ReturnType<typeof setupInput>; |
| 11 | + |
| 12 | +export function setupInput() { |
| 13 | + return { |
| 14 | + easCache: getBooleanInput('eas-cache'), |
| 15 | + easVersion: getInput('eas-version'), |
| 16 | + expoCache: getBooleanInput('expo-cache'), |
| 17 | + expoVersion: getInput('expo-version'), |
| 18 | + packager: getInput('packager') || 'yarn', |
| 19 | + patchWatchers: !getInput('patch-watchers') || getBooleanInput('patch-watchers'), |
| 20 | + token: getInput('token'), |
| 21 | + }; |
26 | 22 | } |
27 | 23 |
|
28 | | -async function installCli(name: tools.PackageName): Promise<string | void> { |
29 | | - const shortName = tools.getBinaryName(name); |
30 | | - const inputVersion = getInput(`${shortName}-version`); |
31 | | - const packager = getInput('packager') || 'yarn'; |
| 24 | +export async function setupAction(input: SetupInput = setupInput()): Promise<void> { |
| 25 | + if (!input.expoVersion) { |
| 26 | + info(`Skipped installing expo-cli: 'expo-version' not provided.`); |
| 27 | + } else { |
| 28 | + const version = await resolvePackage('expo-cli', input.expoVersion); |
| 29 | + const message = input.expoCache |
| 30 | + ? `Installing expo-cli (${version}) from cache or with ${input.packager}` |
| 31 | + : `Installing expo-cli (${version}) with ${input.packager}`; |
32 | 32 |
|
33 | | - if (!inputVersion) { |
34 | | - return info(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`); |
| 33 | + await group(message, () => installCli('expo-cli', version, input.packager, input.expoCache)); |
35 | 34 | } |
36 | 35 |
|
37 | | - const version = await resolveVersion(name, inputVersion); |
38 | | - const cache = getBooleanInput(`${shortName}-cache`); |
39 | | - |
40 | | - try { |
41 | | - const path = await group( |
42 | | - cache |
43 | | - ? `Installing ${name} (${version}) from cache or with ${packager}` |
44 | | - : `Installing ${name} (${version}) with ${packager}`, |
45 | | - () => |
46 | | - install({ |
47 | | - packager, |
48 | | - version, |
49 | | - cache, |
50 | | - package: name, |
51 | | - cacheKey: getInput(`${shortName}-cache-key`) || undefined, |
52 | | - }) |
| 36 | + if (!input.easVersion) { |
| 37 | + info(`Skipped installing eas-cli: 'eas-version' not provided.`); |
| 38 | + } else { |
| 39 | + const version = await resolvePackage('eas-cli', input.easVersion); |
| 40 | + const message = input.easCache |
| 41 | + ? `Installing eas-cli (${version}) from cache or with ${input.packager}` |
| 42 | + : `Installing eas-cli (${version}) with ${input.packager}`; |
| 43 | + |
| 44 | + await group(message, () => installCli('eas-cli', input.easVersion, input.packager, input.easCache)); |
| 45 | + } |
| 46 | + |
| 47 | + if (!input.token) { |
| 48 | + info(`Skipped authentication: 'token' not provided.`); |
| 49 | + } else { |
| 50 | + await group('Validating authenticated account', () => |
| 51 | + expoAuthenticate(input.token, input.easVersion ? 'eas' : input.expoVersion ? 'expo' : undefined) |
53 | 52 | ); |
| 53 | + } |
| 54 | + |
| 55 | + if (!input.patchWatchers) { |
| 56 | + info(`Skipped patching watchers: 'patch-watchers' disabled.`); |
| 57 | + } else { |
| 58 | + await group(`Patching system watchers for the 'ENOSPC' error`, patchWatchers); |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +async function installCli(name: string, version: string, packager: string, cache: boolean = true) { |
| 63 | + const cliVersion = await resolvePackage(name, version); |
| 64 | + let cliPath = findTool(name, cliVersion) || undefined; |
| 65 | + |
| 66 | + if (!cliPath && cache) { |
| 67 | + cliPath = await restoreFromCache(name, cliVersion, packager); |
| 68 | + } |
| 69 | + |
| 70 | + if (!cliPath) { |
| 71 | + cliPath = await installPackage(name, cliVersion, packager); |
54 | 72 |
|
55 | | - addPath(path); |
56 | | - } catch (error) { |
57 | | - tools.handleError(name, error); |
| 73 | + if (cache) { |
| 74 | + await saveToCache(name, cliVersion, packager); |
| 75 | + } |
58 | 76 | } |
59 | 77 |
|
60 | | - return version; |
| 78 | + installToolFromPackage(cliPath); |
61 | 79 | } |
0 commit comments