Compare commits

..
12 Commits
Author SHA1 Message Date
Cedric van Putten 8275e8fa89 chore: release version 5.4.0 2021-01-12 15:20:04 +01:00
Cedric van Putten 4ec7251759 chore: update all dependencies to latest versions (#78) 2021-01-12 14:43:14 +01:00
Cedric van Putten 6c0f4d78ba chore: update readme to latest expo cli and node (#77) 2021-01-12 14:40:35 +01:00
Cedric van Putten 917e072b54 refactor: improve error handling with update check (#76) 2021-01-12 14:32:44 +01:00
Cedric van Putten ed7f67d90e refactor: update all dev dependencies to latest version (#71)
* refactor: use node 14 as primary version to build from

* refactor: add explicit return types to all files

* refactor: update all dev dependencies to latest version

* refactor: update strict typings in test utils
2020-12-04 19:52:01 +01:00
Cedric van Putten 13d78207a1 docs: update the cache description without the fork 2020-12-04 19:29:33 +01:00
Cedric van Putten 75b743cff5 refactor: group output by steps for readability (#70) 2020-12-04 19:20:56 +01:00
Cedric van Putten 187c4adfcc refactor: output cache errors with actions core 2020-12-04 17:10:23 +01:00
Matthew Ondash 0eb46e97d7 refactor: use official actions cache package instead of cypress fork (#62)
* Now uses official @actions/cache package

* Run yarn upgrade

* Add handling for ReserveCacheError (#1)

Bump @actions/cache from 1.0.2 to 1.0.3
Add missing caret to specify @actions/cache version range
Add handling for ReserveCacheError
2020-12-04 16:16:20 +01:00
Cedric van Putten 5d3c1cdff4 chore: release version 5.3.1 2020-10-20 18:08:45 +02:00
Cedric van Putten ce1c6b612a chore: rebuilt the project after dependency bump 2020-10-02 15:17:31 +02:00
dependabot[bot] b807fa603f chore: bump @actions/core from 1.2.4 to 1.2.6 (#63)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.4 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-10-02 15:12:54 +02:00
21 changed files with 98004 additions and 40372 deletions

No files matched your search

+1
View File
@@ -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',
},
};
+2 -2
View File
@@ -17,10 +17,10 @@ jobs:
- ubuntu-latest
- windows-latest
include:
- node: 12
- node: 14
os: macos-latest
checkUpToDate: true
- node: 12
- node: 14
os: ubuntu-latest
checkUpToDate: true
steps:
+30
View File
@@ -1,3 +1,33 @@
## [5.4.0](https://github.com/expo/expo-github-action/compare/5.3.1...5.4.0) (2021-01-12)
### New features
* improve error handling with update check ([#76](https://github.com/expo/expo-github-action/pull/76)) ([917e072](https://github.com/expo/expo-github-action/commit/917e072))
### Code refactors
* use official actions cache package instead of cypress fork ([#62](https://github.com/expo/expo-github-action/pull/62)) ([0eb46e9](https://github.com/expo/expo-github-action/commit/0eb46e9))
* output cache errors with actions core ([187c4ad](https://github.com/expo/expo-github-action/commit/187c4ad))
* group output by steps for readability ([#70](https://github.com/expo/expo-github-action/pull/70)) ([75b743c](https://github.com/expo/expo-github-action/commit/75b743c))
* update all dev dependencies to latest version ([#71](https://github.com/expo/expo-github-action/pull/71)) ([ed7f67d](https://github.com/expo/expo-github-action/commit/ed7f67d))
### Documentation changes
* update the cache description without the fork ([13d7820](https://github.com/expo/expo-github-action/commit/13d7820))
* update readme to latest expo cli and node ([#77](https://github.com/expo/expo-github-action/pull/77)) ([6c0f4d7](https://github.com/expo/expo-github-action/commit/6c0f4d7))
### Other chores
* update all dependencies to latest versions ([#78](https://github.com/expo/expo-github-action/pull/78)) ([4ec7251](https://github.com/expo/expo-github-action/commit/4ec7251))
## [5.3.1](https://github.com/expo/expo-github-action/compare/5.3.0...5.3.1) (2020-10-20)
### Other chores
* bump @actions/core from 1.2.4 to 1.2.6 ([#63](https://github.com/expo/expo-github-action/pull/63)) ([b807fa6](https://github.com/expo/expo-github-action/commit/b807fa6))
## [5.3.0](https://github.com/expo/expo-github-action/compare/5.2.0...5.3.0) (2020-09-19)
### New features
+15 -18
View File
@@ -52,9 +52,6 @@ variable | default | description
> It's also recommended to set the `expo-version` to avoid breaking changes when a new major version is released.
> `expo-token` is available from Expo CLI `3.25.0`.
## Example workflows
Before you dive into the workflow examples, you should know the basics of GitHub Actions.
@@ -87,10 +84,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
- run: yarn install
@@ -119,10 +116,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
@@ -147,10 +144,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
- run: yarn install
@@ -187,7 +184,7 @@ jobs:
node-version: ${{ matrix.node }}
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
- run: yarn install
- run: yarn test
- run: expo doctor
@@ -211,10 +208,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
- run: yarn install
- run: yarn test
- run: expo build:web
@@ -239,10 +236,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
node-version: 14.x
- uses: expo/expo-github-action@v5
with:
expo-version: 3.x
expo-version: 4.x
expo-token: ${{ secrets.EXPO_TOKEN }}
- run: yarn install
- run: expo publish
@@ -261,9 +258,9 @@ Under the hood, it uses the [`EXPO_CLI_PASSWORD`][link-expo-cli-password] enviro
### Using the built-in cache
As of writing, GitHub doesn't provide a (remote) cache for 3rd party actions.
That's why we implemented the [Cypress fork of the `actions/cache`][link-actions-cache-cypress].
With this, you can opt-in to caching the Expo CLI install, making it a lot faster.
You can opt-in to caching the installation, making it a lot faster.
Under the hood, it uses the [`@action/cache`][link-actions-cache-package] package to restore the Expo CLI installation.
This action generates a unique cache key for the OS, used packager, and exact version of the Expo CLI.
If you need more control over this cache, you can define a custom cache key with `expo-cache-key`.
> Note, this cache will count towards your [repo cache limit][link-actions-cache-limit].
@@ -284,8 +281,8 @@ You can disable this patch by setting the `expo-patch-watchers` to `false`.
</div>
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
[link-actions-cache-cypress]: https://github.com/cypress-io/github-actions-cache
[link-actions-cache-limit]: https://github.com/actions/cache#cache-limits
[link-actions-cache-package]: https://www.npmjs.com/package/@actions/cache
[link-actions-node]: https://github.com/actions/setup-node
[link-actions-secrets]: https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets
[link-expo-cli]: https://docs.expo.io/workflow/expo-cli/
+96063 -38895
View File
File diff suppressed because it is too large. Load diff
+17 -15
View File
@@ -21,27 +21,29 @@
"clean": "rimraf build"
},
"dependencies": {
"@actions/cache": "github:cypress-io/github-actions-cache#8bec6cc",
"@actions/core": "^1.2.4",
"@actions/cache": "^1.0.4",
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.5",
"libnpm": "^3.0.1"
"@actions/tool-cache": "^1.6.1",
"libnpm": "^3.0.1",
"semver": "^7.3.4"
},
"devDependencies": {
"@types/jest": "^26.0.4",
"@types/node": "^12.12.49",
"@typescript-eslint/eslint-plugin": "^3.6.1",
"@typescript-eslint/parser": "^3.6.1",
"@types/jest": "^26.0.16",
"@types/node": "^14.14.10",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.9.0",
"@typescript-eslint/parser": "^4.9.0",
"@zeit/ncc": "^0.22.3",
"eslint": "^7.4.0",
"eslint-plugin-jest": "^23.18.0",
"husky": "^4.2.5",
"jest": "^26.0.1",
"jest-circus": "^26.1.0",
"eslint": "^7.14.0",
"eslint-plugin-jest": "^24.1.3",
"husky": "^4.3.0",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"rimraf": "^3.0.2",
"ts-jest": "^26.1.2",
"typescript": "^3.9.6"
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
},
"husky": {
"hooks": {
+18 -8
View File
@@ -1,4 +1,5 @@
import { restoreCache, saveCache } from '@actions/cache/lib';
import { ReserveCacheError, restoreCache, saveCache } from '@actions/cache';
import * as core from '@actions/core';
import * as toolCache from '@actions/tool-cache';
import path from 'path';
import os from 'os';
@@ -9,7 +10,7 @@ import os from 'os';
*
* @see https://github.com/actions/toolkit/issues/47
*/
export async function fromLocalCache(version: string) {
export async function fromLocalCache(version: string): Promise<string | undefined> {
return toolCache.find('expo-cli', version);
}
@@ -19,7 +20,7 @@ export async function fromLocalCache(version: string) {
*
* @see https://github.com/actions/toolkit/issues/47
*/
export async function toLocalCache(root: string, version: string) {
export async function toLocalCache(root: string, version: string): Promise<string> {
return toolCache.cacheDir(root, 'expo-cli', version);
}
@@ -27,11 +28,11 @@ export async function toLocalCache(root: string, version: string) {
* Download the remotely stored `expo-cli` from cache, if any.
* Note, this cache is shared between jobs.
*/
export async function fromRemoteCache(version: string, packager: string, customCacheKey?: string) {
export async function fromRemoteCache(version: string, packager: string, customCacheKey?: string): Promise<string | undefined> {
// see: https://github.com/actions/toolkit/blob/8a4134761f09d0d97fb15f297705fd8644fef920/packages/tool-cache/src/tool-cache.ts#L401
const target = path.join(process.env['RUNNER_TOOL_CACHE'] || '', 'expo-cli', version, os.arch());
const cacheKey = customCacheKey || getRemoteKey(version, packager);
const hit = await restoreCache(target, cacheKey, cacheKey);
const hit = await restoreCache([target], cacheKey);
if (hit) {
return target;
@@ -42,15 +43,24 @@ export async function fromRemoteCache(version: string, packager: string, customC
* Store the root of `expo-cli` in the remote cache, for future reuse.
* Note, this cache is shared between jobs.
*/
export async function toRemoteCache(source: string, version: string, packager: string, customCacheKey?: string) {
export async function toRemoteCache(source: string, version: string, packager: string, customCacheKey?: string): Promise<void> {
const cacheKey = customCacheKey || getRemoteKey(version, packager);
await saveCache(source, cacheKey);
try {
await saveCache([source], cacheKey);
} catch (error) {
if (error instanceof ReserveCacheError) {
core.info('Skipping remote cache storage, encountered error:');
core.info(error.message);
} else {
throw error;
}
}
}
/**
* Get the cache key to use when (re)storing the Expo CLI from remote cache.
*/
function getRemoteKey(version: string, packager: string) {
function getRemoteKey(version: string, packager: string): string {
return `expo-cli-${process.platform}-${os.arch()}-${packager}-${version}`;
}
-70
View File
@@ -1,70 +0,0 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
type AuthOptions = {
token?: string;
username?: string;
password?: string;
};
/**
* Authenticate at Expo using `expo login`.
* This step is required for publishing and building new apps.
* It uses the `EXPO_CLI_PASSWORD` environment variable for improved security.
*/
export async function authWithCredentials(username?: string, password?: string) {
if (!username || !password) {
return core.info('Skipping authentication: `expo-username` and/or `expo-password` not set...');
}
// github actions toolkit will handle commands with `.cmd` on windows, we need that
const bin = process.platform === 'win32' ? 'expo.cmd' : 'expo';
await cli.exec(bin, ['login', `--username=${username}`], {
env: {
...process.env,
EXPO_CLI_PASSWORD: password,
},
});
}
/**
* Authenticate with Expo using `EXPO_TOKEN`.
* This exports the EXPO_TOKEN environment variable for all future steps within the workflow.
* It also double-checks if this token is valid and for what user, by running `expo whoami`.
*
* @see https://github.com/actions/toolkit/blob/905b2c7b0681b11056141a60055f1ba77358b7e9/packages/core/src/core.ts#L39
*/
export async function authWithToken(token?: string) {
if (!token) {
return core.info('Skipping authentication: `expo-token` not set...');
}
// github actions toolkit will handle commands with `.cmd` on windows, we need that
const bin = process.platform === 'win32' ? 'expo.cmd' : 'expo';
await cli.exec(bin, ['whoami'], {
env: {
...process.env,
EXPO_TOKEN: token,
},
});
core.exportVariable('EXPO_TOKEN', token);
}
/**
* Authenticate with Expo using either the token or username/password method.
* If both of them are set, token has priority.
*/
export function authenticate(options: AuthOptions) {
if (options.token) {
return authWithToken(options.token);
}
if (options.username || options.password) {
return authWithCredentials(options.username, options.password);
}
core.info('Skipping authentication: `expo-token`, `expo-username`, and/or `expo-password` not set...');
}
+2 -2
View File
@@ -1,4 +1,4 @@
import * as core from '@actions/core';
import { run } from './run';
import { handleError } from './tools';
run().catch(core.setFailed);
run().catch(handleError);
+9 -21
View File
@@ -2,48 +2,36 @@ import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as io from '@actions/io';
import * as path from 'path';
import { fromLocalCache, fromRemoteCache, toLocalCache, toRemoteCache } from './cache';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const registry = require('libnpm');
type InstallConfig = {
export type InstallConfig = {
version: string;
packager: string;
cache?: boolean;
cacheKey?: string;
};
/**
* Resolve the provided semver to exact version of `expo-cli`.
* This uses the npm registry and accepts latest, dist-tags or version ranges.
* It's used to determine the cached version of `expo-cli`.
*/
export async function resolve(version: string) {
return (await registry.manifest(`expo-cli@${version}`)).version;
}
/**
* Install `expo-cli`, by version, using the packager.
* Here you can provide any semver range or dist tag used in the registry.
* It returns the path where Expo is installed.
*/
export async function install(config: InstallConfig) {
const exact = await resolve(config.version);
let root: string | undefined = await fromLocalCache(exact);
export async function install(config: InstallConfig): Promise<string> {
let root: string | undefined = await fromLocalCache(config.version);
if (!root && config.cache) {
root = await fromRemoteCache(exact, config.packager, config.cacheKey);
root = await fromRemoteCache(config.version, config.packager, config.cacheKey);
} else {
core.info('Skipping remote cache, not enabled...');
}
if (!root) {
root = await fromPackager(exact, config.packager);
root = await toLocalCache(root, exact);
root = await fromPackager(config.version, config.packager);
root = await toLocalCache(root, config.version);
if (config.cache) {
await toRemoteCache(root, exact, config.packager, config.cacheKey);
await toRemoteCache(root, config.version, config.packager, config.cacheKey);
}
}
@@ -54,7 +42,7 @@ export async function install(config: InstallConfig) {
* Install `expo-cli`, by version, using npm or yarn.
* It creates a temporary directory to store all required files.
*/
export async function fromPackager(version: string, packager: string) {
export async function fromPackager(version: string, packager: string): Promise<string> {
const root = process.env['RUNNER_TEMP'] || '';
const tool = await io.which(packager);
+29 -13
View File
@@ -1,27 +1,43 @@
import { addPath, getInput } from '@actions/core';
import { authenticate } from './expo';
import { install } from './install';
import { patchWatchers } from './system';
import { addPath, getInput, group } from '@actions/core';
export async function run() {
const path = await install({
import { install, InstallConfig } from './install';
import { maybeAuthenticate, maybePatchWatchers, resolveVersion } from './tools';
export async function run(): Promise<void> {
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,
});
};
// Resolve the exact requested Expo CLI version
config.version = await resolveVersion(config.version);
const path = await group(
config.cache
? `Installing Expo CLI (${config.version}) from cache or with ${config.packager}`
: `Installing Expo CLI (${config.version}) 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',
() => maybeAuthenticate({
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',
() => maybePatchWatchers(),
);
}
}
-28
View File
@@ -1,28 +0,0 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
/**
* Try to patch the default watcher/inotify limit.
* This is a limitation from GitHub Actions and might be an issue in some Expo projects.
* It sets the system's `fs.inotify` limits to a more sensible setting.
*
* @see https://github.com/expo/expo-github-action/issues/20
*/
export async function patchWatchers() {
if (process.platform !== 'linux') {
return core.info('Skipping patch for watchers, not running on Linux...');
}
core.info('Patching system watchers for the `ENOSPC` error...');
try {
// see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177
await cli.exec('sudo sysctl fs.inotify.max_user_instances=524288');
await cli.exec('sudo sysctl fs.inotify.max_user_watches=524288');
await cli.exec('sudo sysctl fs.inotify.max_queued_events=524288');
await cli.exec('sudo sysctl -p');
} catch {
core.warning("Looks like we can't patch watchers/inotify limits, you might encouter the `ENOSPC` error.");
core.warning('For more info, https://github.com/expo/expo-github-action/issues/20');
}
}
+104
View File
@@ -0,0 +1,104 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import semver from 'semver';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const registry = require('libnpm');
type AuthenticateOptions = {
token?: string;
username?: string;
password?: string;
};
/**
* Resolve the provided semver to exact version of `expo-cli`.
* This uses the npm registry and accepts latest, dist-tags or version ranges.
* It's used to determine the cached version of `expo-cli`.
*/
export async function resolveVersion(version: string): Promise<string> {
return (await registry.manifest(`expo-cli@${version}`)).version;
}
/**
* Authenticate with Expo using either the token or username/password method.
* If both of them are set, token has priority.
*/
export async function maybeAuthenticate(options: AuthenticateOptions = {}): Promise<void> {
// github actions toolkit will handle commands with `.cmd` on windows, we need that
const bin = process.platform === 'win32' ? 'expo.cmd' : 'expo';
if (options.token) {
await cli.exec(bin, ['whoami'], {
env: { ...process.env, EXPO_TOKEN: options.token },
});
return core.exportVariable('EXPO_TOKEN', options.token);
}
if (options.username || options.password) {
if (!options.username || !options.password) {
return core.info('Skipping authentication: `expo-username` and/or `expo-password` not set...');
}
await cli.exec(bin, ['login', `--username=${options.username}`], {
env: { ...process.env, EXPO_CLI_PASSWORD: options.password },
});
return;
}
core.info('Skipping authentication: `expo-token`, `expo-username`, and/or `expo-password` not set...');
}
/**
* Try to patch the default watcher/inotify limit.
* This is a limitation from GitHub Actions and might be an issue in some Expo projects.
* It sets the system's `fs.inotify` limits to a more sensible setting.
*
* @see https://github.com/expo/expo-github-action/issues/20
*/
export async function maybePatchWatchers(): Promise<void> {
if (process.platform !== 'linux') {
return core.info('Skipping patch for watchers, not running on Linux...');
}
core.info('Patching system watchers for the `ENOSPC` error...');
try {
// see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177
await cli.exec('sudo sysctl fs.inotify.max_user_instances=524288');
await cli.exec('sudo sysctl fs.inotify.max_user_watches=524288');
await cli.exec('sudo sysctl fs.inotify.max_queued_events=524288');
await cli.exec('sudo sysctl -p');
} catch {
core.warning("Looks like we can't patch watchers/inotify limits, you might encouter the `ENOSPC` error.");
core.warning('For more info, https://github.com/expo/expo-github-action/issues/20');
}
}
/**
* Check if there is a new major version available.
* If there is, create a warning for people to upgrade their workflow.
* Because this introduces additional requests, it should only be executed when necessary.
*/
export async function maybeWarnForUpdate(): Promise<void> {
const latest = await resolveVersion('latest');
const current = await resolveVersion(core.getInput('expo-version') || 'latest');
if (semver.diff(latest, current) === 'major') {
core.warning(`There is a new major version available of the Expo CLI (${latest})`);
core.warning(`If you run into issues, try upgrading your workflow to "expo-version: ${semver.major(latest)}.x"`);
}
}
/**
* Handle errors when this action fails, providing useful next-steps for developers.
* This mostly checks if the installed version is the latest version.
*/
export async function handleError(error: Error) {
try {
await maybeWarnForUpdate();
} catch {
// If this fails, ignore it
}
core.setFailed(error);
}
+6 -7
View File
@@ -1,7 +1,8 @@
import os from 'os';
import { join } from 'path';
import * as remoteCache from '@actions/cache/lib';
import * as remoteCache from '@actions/cache';
import * as toolCache from '@actions/tool-cache';
import * as cache from '../src/cache';
import * as utils from './utils';
@@ -48,18 +49,16 @@ describe('fromRemoteCache', () => {
it('restores remote cache with default key', async () => {
expect(await cache.fromRemoteCache('3.20.1', 'yarn')).toBeUndefined();
expect(remoteCache.restoreCache).toBeCalledWith(
join('cache', 'path', 'expo-cli', '3.20.1', os.arch()),
[join('cache', 'path', 'expo-cli', '3.20.1', os.arch())],
`expo-cli-${process.platform}-${os.arch()}-yarn-3.20.1`,
`expo-cli-${process.platform}-${os.arch()}-yarn-3.20.1`
);
});
it('restores remote cache with custom key', async () => {
expect(await cache.fromRemoteCache('3.20.0', 'yarn', 'custom-cache-key')).toBeUndefined();
expect(remoteCache.restoreCache).toBeCalledWith(
join('cache', 'path', 'expo-cli', '3.20.0', os.arch()),
[join('cache', 'path', 'expo-cli', '3.20.0', os.arch())],
'custom-cache-key',
'custom-cache-key'
);
});
@@ -93,14 +92,14 @@ describe('toRemoteCache', () => {
it('saves remote cache with default key', async () => {
expect(await cache.toRemoteCache(join('local', 'path'), '3.20.1', 'npm')).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith(
join('local', 'path'),
[join('local', 'path')],
`expo-cli-${process.platform}-${os.arch()}-npm-3.20.1`
);
});
it('saves remote cache with custom key', async () => {
expect(await cache.toRemoteCache(join('local', 'path'), '3.20.1', 'yarn', 'custom-cache-key')).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith(join('local', 'path'), 'custom-cache-key');
expect(remoteCache.saveCache).toBeCalledWith([join('local', 'path')], 'custom-cache-key');
});
it('fails when remote cache throws', async () => {
-148
View File
@@ -1,148 +0,0 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as expo from '../src/expo';
import * as utils from './utils';
const TOKEN = 'ABC123';
const USER = 'bycedric';
const PASS = 'mypassword';
describe('authWithCredentials', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
};
});
afterAll(() => {
spy.exec.mockRestore();
spy.info.mockRestore();
});
it('skips authentication without credentials', async () => {
await expo.authWithCredentials();
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('skips authentication without password', async () => {
await expo.authWithCredentials(USER);
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('executes login command with password through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await expo.authWithCredentials(USER, PASS);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][1]).toStrictEqual(['login', `--username=${USER}`]);
expect(spy.exec.mock.calls[0][2]).toMatchObject({
env: {
TEST_INCLUDED: 'hellyeah',
EXPO_CLI_PASSWORD: PASS,
},
});
utils.restoreEnv();
});
it('fails when credentials are incorrect', async () => {
const error = new Error('Invalid username/password. Please try again.');
spy.exec.mockRejectedValue(error);
await expect(expo.authWithCredentials(USER, PASS)).rejects.toBe(error);
});
it('executes login command with `expo` on macos', async () => {
utils.setPlatform('darwin');
await expo.authWithCredentials(USER, PASS);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes login command with `expo` on ubuntu', async () => {
utils.setPlatform('linux');
await expo.authWithCredentials(USER, PASS);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes login command with `expo.cmd` on windows', async () => {
utils.setPlatform('win32');
await expo.authWithCredentials(USER, PASS);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
describe('authWithToken', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
exportVariable: jest.spyOn(core, 'exportVariable').mockImplementation(),
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
};
});
afterAll(() => {
spy.exportVariable.mockRestore();
spy.exec.mockRestore();
spy.info.mockRestore();
});
it('skips authentication without token', async () => {
await expo.authWithToken();
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('executes whoami command with token through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await expo.authWithToken(TOKEN);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][1]).toStrictEqual(['whoami']);
expect(spy.exec.mock.calls[0][2]).toMatchObject({
env: {
TEST_INCLUDED: 'hellyeah',
EXPO_TOKEN: TOKEN,
},
});
utils.restoreEnv();
});
it('fails when token is incorrect', async () => {
const error = new Error('Not logged in');
spy.exec.mockRejectedValue(error);
await expect(expo.authWithToken(TOKEN)).rejects.toBe(error);
});
it('executes whoami command with `expo` on macos', async () => {
utils.setPlatform('darwin');
await expo.authWithToken(TOKEN);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes whoami command with `expo` on ubuntu', async () => {
utils.setPlatform('linux');
await expo.authWithToken(TOKEN);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes whoami command with `expo.cmd` on windows', async () => {
utils.setPlatform('win32');
await expo.authWithToken(TOKEN);
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
+2 -13
View File
@@ -1,6 +1,5 @@
const cli = { exec: jest.fn() };
const io = { mkdirP: jest.fn(), which: jest.fn() };
const registry = { manifest: jest.fn() };
const cache = {
fromLocalCache: jest.fn(),
fromRemoteCache: jest.fn(),
@@ -10,21 +9,13 @@ const cache = {
jest.mock('@actions/exec', () => cli);
jest.mock('@actions/io', () => io);
jest.mock('libnpm', () => registry);
jest.mock('../src/cache', () => cache);
import { join } from 'path';
import * as install from '../src/install';
import * as utils from './utils';
describe('resolve', () => {
it('fetches exact version of expo-cli', async () => {
registry.manifest.mockResolvedValue({ version: '3.0.10' });
expect(await install.resolve('latest')).toBe('3.0.10');
expect(registry.manifest).toBeCalledWith('expo-cli@latest');
});
});
describe('install', () => {
it('installs path from local cache', async () => {
cache.fromLocalCache.mockResolvedValue(join('cache', 'path'));
@@ -45,10 +36,9 @@ describe('install', () => {
it('installs path from remote cache', async () => {
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(join('cache', 'path'));
registry.manifest.mockResolvedValue({ version: '3.20.0' });
const expoPath = await install.install({ version: '3.20.1', packager: 'npm', cache: true });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.fromRemoteCache).toBeCalledWith('3.20.0', 'npm', undefined);
expect(cache.fromRemoteCache).toBeCalledWith('3.20.1', 'npm', undefined);
});
it('installs path from packager and cache it remotely', async () => {
@@ -56,7 +46,6 @@ describe('install', () => {
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue(join('cache', 'path'));
registry.manifest.mockResolvedValue({ version: '3.20.1' });
const expoPath = await install.install({ version: '3.20.1', packager: 'npm', cache: true });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.toRemoteCache).toBeCalledWith(join('cache', 'path'), '3.20.1', 'npm', undefined);
+16 -10
View File
@@ -1,14 +1,20 @@
const core = { addPath: jest.fn(), getInput: jest.fn() };
const core = {
addPath: jest.fn(),
getInput: jest.fn(),
group: (message: string, action: () => Promise<any>) => action()
};
const exec = { exec: jest.fn() };
const expo = { authenticate: jest.fn() };
const install = { install: jest.fn() };
const system = { patchWatchers: jest.fn() };
const tools = {
resolveVersion: jest.fn(v => v),
maybeAuthenticate: jest.fn(),
maybePatchWatchers: jest.fn(),
};
jest.mock('@actions/core', () => core);
jest.mock('@actions/exec', () => exec);
jest.mock('../src/expo', () => expo);
jest.mock('../src/tools', () => tools);
jest.mock('../src/install', () => install);
jest.mock('../src/system', () => system);
import { run } from '../src/run';
@@ -73,30 +79,30 @@ describe('run', () => {
it('patches the system when set to true', async () => {
mockInput({ patchWatchers: 'true' });
await run();
expect(system.patchWatchers).toHaveBeenCalled();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('patches the system when not set', async () => {
mockInput({ patchWatchers: '' });
await run();
expect(system.patchWatchers).toHaveBeenCalled();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('skips the system patch when set to false', async () => {
mockInput({ patchWatchers: 'false' });
await run();
expect(system.patchWatchers).not.toHaveBeenCalled();
expect(tools.maybePatchWatchers).not.toHaveBeenCalled();
});
it('authenticates with provided credentials', async () => {
mockInput({ username: 'bycedric', password: 'mypassword', patchWatchers: 'false' });
await run();
expect(expo.authenticate).toBeCalledWith({ username: 'bycedric', password: 'mypassword' });
expect(tools.maybeAuthenticate).toBeCalledWith({ username: 'bycedric', password: 'mypassword' });
});
it('authenticates with provided token', async () => {
mockInput({ token: 'ABC123', patchWatchers: 'false' });
await run();
expect(expo.authenticate).toBeCalledWith({ token: 'ABC123' });
expect(tools.maybeAuthenticate).toBeCalledWith({ token: 'ABC123' });
});
});
-67
View File
@@ -1,67 +0,0 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as system from '../src/system';
import * as utils from './utils';
describe('patchWatchers', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
info: jest.spyOn(core, 'info').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
exec: jest.spyOn(cli, 'exec').mockImplementation(),
};
});
afterEach(() => {
utils.restorePlatform();
});
afterAll(() => {
spy.info.mockRestore();
spy.warning.mockRestore();
spy.exec.mockRestore();
});
it('increses fs inotify settings with sysctl', async () => {
utils.setPlatform('linux');
await system.patchWatchers();
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_instances=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_watches=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_queued_events=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl -p');
});
it('warns for unsuccessful patches', async () => {
const error = new Error('Something went wrong');
spy.exec.mockRejectedValueOnce(error);
utils.setPlatform('linux');
await system.patchWatchers();
expect(core.warning).toBeCalledWith(expect.stringContaining("can't patch watchers"));
expect(core.warning).toBeCalledWith(
expect.stringContaining('https://github.com/expo/expo-github-action/issues/20')
);
});
it('skips on windows platform', async () => {
utils.setPlatform('win32');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('skips on macos platform', async () => {
utils.setPlatform('darwin');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('runs on linux platform', async () => {
utils.setPlatform('linux');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Patching'));
expect(spy.exec).toHaveBeenCalled();
});
});
+282
View File
@@ -0,0 +1,282 @@
const registry = { manifest: jest.fn() };
jest.mock('libnpm', () => registry);
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as tools from '../src/tools';
import * as utils from './utils';
describe('resolveVersion', () => {
it('fetches exact version of expo-cli', async () => {
registry.manifest.mockResolvedValue({ version: '3.0.10' });
expect(await tools.resolveVersion('latest')).toBe('3.0.10');
expect(registry.manifest).toBeCalledWith('expo-cli@latest');
});
});
describe('maybeAuthenticate', () => {
const token = 'ABC123';
const username = 'bycedric';
const password = 'mypassword';
describe('with token', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
exportVariable: jest.spyOn(core, 'exportVariable').mockImplementation(),
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
};
});
afterAll(() => {
spy.exportVariable.mockRestore();
spy.exec.mockRestore();
spy.info.mockRestore();
});
it('skips authentication without token', async () => {
await tools.maybeAuthenticate();
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('executes whoami command with token through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await tools.maybeAuthenticate({ token });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][1]).toStrictEqual(['whoami']);
expect(spy.exec.mock.calls[0][2]).toMatchObject({
env: {
TEST_INCLUDED: 'hellyeah',
EXPO_TOKEN: token,
},
});
utils.restoreEnv();
});
it('fails when token is incorrect', async () => {
const error = new Error('Not logged in');
spy.exec.mockRejectedValue(error);
await expect(tools.maybeAuthenticate({ token })).rejects.toBe(error);
});
it('executes whoami command with `expo` on macos', async () => {
utils.setPlatform('darwin');
await tools.maybeAuthenticate({ token });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes whoami command with `expo` on ubuntu', async () => {
utils.setPlatform('linux');
await tools.maybeAuthenticate({ token });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes whoami command with `expo.cmd` on windows', async () => {
utils.setPlatform('win32');
await tools.maybeAuthenticate({ token });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
describe('credentials', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
};
});
afterAll(() => {
spy.exec.mockRestore();
spy.info.mockRestore();
});
it('skips authentication without credentials', async () => {
await tools.maybeAuthenticate();
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('skips authentication without password', async () => {
await tools.maybeAuthenticate({ username });
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('executes login command with password through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await tools.maybeAuthenticate({ username, password })
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][1]).toStrictEqual(['login', `--username=${username}`]);
expect(spy.exec.mock.calls[0][2]).toMatchObject({
env: {
TEST_INCLUDED: 'hellyeah',
EXPO_CLI_PASSWORD: password,
},
});
utils.restoreEnv();
});
it('fails when credentials are incorrect', async () => {
const error = new Error('Invalid username/password. Please try again.');
spy.exec.mockRejectedValue(error);
await expect(tools.maybeAuthenticate({ username, password }))
.rejects
.toBe(error);
});
it('executes login command with `expo` on macos', async () => {
utils.setPlatform('darwin');
await tools.maybeAuthenticate({ username, password });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes login command with `expo` on ubuntu', async () => {
utils.setPlatform('linux');
await tools.maybeAuthenticate({ username, password });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
utils.restorePlatform();
});
it('executes login command with `expo.cmd` on windows', async () => {
utils.setPlatform('win32');
await tools.maybeAuthenticate({ username, password });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
});
describe('maybePatchWatchers', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
info: jest.spyOn(core, 'info').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
exec: jest.spyOn(cli, 'exec').mockImplementation(),
};
});
afterEach(() => {
utils.restorePlatform();
});
afterAll(() => {
spy.info.mockRestore();
spy.warning.mockRestore();
spy.exec.mockRestore();
});
it('increses fs inotify settings with sysctl', async () => {
utils.setPlatform('linux');
await tools.maybePatchWatchers();
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_instances=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_user_watches=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl fs.inotify.max_queued_events=524288');
expect(spy.exec).toBeCalledWith('sudo sysctl -p');
});
it('warns for unsuccessful patches', async () => {
const error = new Error('Something went wrong');
spy.exec.mockRejectedValueOnce(error);
utils.setPlatform('linux');
await tools.maybePatchWatchers();
expect(core.warning).toBeCalledWith(expect.stringContaining("can't patch watchers"));
expect(core.warning).toBeCalledWith(
expect.stringContaining('https://github.com/expo/expo-github-action/issues/20')
);
});
it('skips on windows platform', async () => {
utils.setPlatform('win32');
await tools.maybePatchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('skips on macos platform', async () => {
utils.setPlatform('darwin');
await tools.maybePatchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('runs on linux platform', async () => {
utils.setPlatform('linux');
await tools.maybePatchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Patching'));
expect(spy.exec).toHaveBeenCalled();
});
});
describe('maybeWarnForUpdate', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = { warning: jest.spyOn(core, 'warning').mockImplementation() };
});
afterAll(() => {
spy.warning.mockRestore();
});
it('is silent when major version is up to date', async () => {
registry.manifest
.mockResolvedValueOnce({ version: '4.1.0' })
.mockResolvedValueOnce({ version: '4.0.1'});
await tools.maybeWarnForUpdate();
expect(spy.warning).not.toBeCalled();
})
it('warns when major version is outdated', async () => {
registry.manifest
.mockResolvedValueOnce({ version: '4.1.0' })
.mockResolvedValueOnce({ version: '3.0.1'});
await tools.maybeWarnForUpdate();
expect(spy.warning).toBeCalledWith('There is a new major version available of the Expo CLI (4.1.0)');
expect(spy.warning).toBeCalledWith('If you run into issues, try upgrading your workflow to "expo-version: 4.x"');
})
});
describe('handleError', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = { setFailed: jest.spyOn(core, 'setFailed').mockImplementation() };
});
afterAll(() => {
spy.setFailed.mockRestore();
});
it('marks the job as failed', async () => {
const error = new Error('test');
registry.manifest.mockResolvedValue('4.0.0');
await tools.handleError(error);
expect(core.setFailed).toBeCalledWith(error);
});
it('fails with original error when update warning failed', async () => {
const error = new Error('test');
registry.manifest.mockRejectedValue(new Error('npm issue'));
await tools.handleError(error);
expect(core.setFailed).toBeCalledWith(error);
});
});
+4 -4
View File
@@ -5,14 +5,14 @@ const originalPlatform = process.platform;
* Change the node platform for testing purposes.
* With this you can fake the `process.platform`.
*/
export function setPlatform(platform: NodeJS.Platform) {
export function setPlatform(platform: NodeJS.Platform): void {
Object.defineProperty(process, 'platform', { value: platform });
}
/**
* Revert the platform to the original one.
*/
export function restorePlatform() {
export function restorePlatform(): void {
setPlatform(originalPlatform);
}
@@ -22,13 +22,13 @@ const originalEnv = { ...process.env };
/**
* Change the environment variable for testing purposes.
*/
export function setEnv(name: string, value: string) {
export function setEnv(name: string, value: string): void {
process.env[name] = value;
}
/**
* Revert the environment variable changes.
*/
export function restoreEnv() {
export function restoreEnv(): void {
process.env = originalEnv;
}
+1404 -1051
View File
File diff suppressed because it is too large. Load diff