mirror of
https://github.com/expo/expo-github-action.git
synced 2026-11-15 17:32:45 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8275e8fa89 | ||
|
|
4ec7251759 | ||
|
|
6c0f4d78ba | ||
|
|
917e072b54 | ||
|
|
ed7f67d90e | ||
|
|
13d78207a1 | ||
|
|
75b743cff5 | ||
|
|
187c4adfcc | ||
|
|
0eb46e97d7 | ||
|
|
5d3c1cdff4 | ||
|
|
ce1c6b612a | ||
|
|
b807fa603f | ||
|
|
1010edb8c8 | ||
|
|
b80de3494e | ||
|
|
f773f9c85c | ||
|
|
1c36889886 |
No files matched your search
@@ -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',
|
||||
},
|
||||
};
|
||||
@@ -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:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"jsxBracketSameLine": true,
|
||||
"trailingComma": "es5",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
@@ -1,3 +1,40 @@
|
||||
## [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
|
||||
|
||||
* add expo token authentication method ([#57](https://github.com/expo/expo-github-action/pull/57)) ([1c36889](https://github.com/expo/expo-github-action/commit/1c36889))
|
||||
|
||||
|
||||
## [5.2.0](https://github.com/expo/expo-github-action/compare/5.1.1...5.2.0) (2020-07-14)
|
||||
|
||||
### Bug fixes
|
||||
|
||||
@@ -40,6 +40,7 @@ Here is a summary of all the variables that you can use and their purpose.
|
||||
variable | default | description
|
||||
--- | --- | ---
|
||||
`expo-username` | - | The username of your Expo account _(e.g. `bycedric`)_
|
||||
`expo-token` | - | The token of your Expo account _(e.g. [`${{ secrets.EXPO_TOKEN }}`][link-actions-secrets])_
|
||||
`expo-password` | - | The password of your Expo account _(e.g. [`${{ secrets.EXPO_CLI_PASSWORD }}`][link-actions-secrets])_
|
||||
`expo-version` | `latest` | The Expo CLI version to use, can be any [SemVer][link-semver-playground]. _(e.g. `3.x`)_
|
||||
`expo-packager` | `yarn` | The package manager to install the CLI with. _(e.g. `npm`)_
|
||||
@@ -47,7 +48,8 @@ variable | default | description
|
||||
`expo-cache-key` | - | An optional custom (remote) cache key. _(**use with caution**)_
|
||||
`expo-patch-watchers` | `true` | If it should [patch the `fs.inotify.` limits](#enospc-errors-on-linux).
|
||||
|
||||
> Never hardcode your `expo-password` in your workflow, use [secrets][link-actions-secrets] to store them.
|
||||
> Never hardcode `expo-token` or `expo-password` in your workflow, use [secrets][link-actions-secrets] to store them.
|
||||
|
||||
> It's also recommended to set the `expo-version` to avoid breaking changes when a new major version is released.
|
||||
|
||||
## Example workflows
|
||||
@@ -60,6 +62,7 @@ You can read more about this in the [GitHub Actions documentation][link-actions]
|
||||
3. [Test PRs and publish a review version](#test-prs-and-publish-a-review-version)
|
||||
4. [Test PRs on multiple nodes and systems](#test-prs-on-multiple-nodes-and-systems)
|
||||
5. [Test and build web every day at 08:00](#test-and-build-web-every-day-at-0800)
|
||||
6. [Authenticate using an Expo token](#authenticate-using-an-expo-token)
|
||||
|
||||
### Publish on any push to master
|
||||
|
||||
@@ -81,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
|
||||
@@ -113,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
|
||||
@@ -141,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
|
||||
@@ -181,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
|
||||
@@ -205,30 +208,59 @@ 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
|
||||
```
|
||||
|
||||
### Authenticate using an Expo token
|
||||
|
||||
Instead of username and password, you can also authenticate using a token.
|
||||
This might help increasing security and avoids adding username and password to your repository secrets.
|
||||
|
||||
```yml
|
||||
name: Expo Publish
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
jobs:
|
||||
publish:
|
||||
name: Install and publish
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 14.x
|
||||
- uses: expo/expo-github-action@v5
|
||||
with:
|
||||
expo-version: 4.x
|
||||
expo-token: ${{ secrets.EXPO_TOKEN }}
|
||||
- run: yarn install
|
||||
- run: expo publish
|
||||
```
|
||||
|
||||
## Things to know
|
||||
|
||||
### Automatic Expo login
|
||||
|
||||
You need to authenticate for some Expo commands like `expo publish` and `expo build`.
|
||||
This action gives you configuration options to keep your workflow simple.
|
||||
Under the hood, it uses the [`EXPO_CLI_PASSWORD`][link-expo-cli-password] environment variable to make this as secure as possible.
|
||||
You can choose if you want to authenticate using an `EXPO_TOKEN` or account credentials.
|
||||
Under the hood, it uses the [`EXPO_CLI_PASSWORD`][link-expo-cli-password] environment variable to make credentials authentication as secure as possible.
|
||||
|
||||
> Note, this action only uses your credentials to authenticate with Expo. It doesn't store these anywhere.
|
||||
> Note, this action only uses your token or credentials to authenticate with Expo. It doesn't store these anywhere.
|
||||
|
||||
### 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].
|
||||
@@ -249,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/
|
||||
|
||||
@@ -14,6 +14,8 @@ inputs:
|
||||
default: latest
|
||||
expo-username:
|
||||
description: Your Expo username, for authentication.
|
||||
expo-token:
|
||||
description: Your Expo token, for authentication. (use with secrets)
|
||||
expo-password:
|
||||
description: Your Expo password, for authentication. (use with secrets)
|
||||
expo-packager:
|
||||
|
||||
+96066
-38861
File diff suppressed because it is too large.
Load diff
+18
-16
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "expo-github-action",
|
||||
"version": "5.1.0",
|
||||
"version": "5.3.0",
|
||||
"description": "Expo CLI in your GitHub Actions workflow",
|
||||
"main": "build/index.js",
|
||||
"repository": {
|
||||
@@ -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
@@ -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}`;
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as cli from '@actions/exec';
|
||||
|
||||
/**
|
||||
* 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 authenticate(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,
|
||||
},
|
||||
});
|
||||
}
|
||||
+2
-2
@@ -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);
|
||||
+10
-27
@@ -2,53 +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');
|
||||
import { fromLocalCache, fromRemoteCache, toLocalCache, toRemoteCache } from './cache';
|
||||
|
||||
interface 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,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);
|
||||
|
||||
|
||||
+28
-11
@@ -1,26 +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(
|
||||
getInput('expo-username'),
|
||||
getInput('expo-password'),
|
||||
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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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
@@ -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);
|
||||
}
|
||||
+27
-15
@@ -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';
|
||||
|
||||
@@ -28,9 +29,13 @@ describe('toLocalCache', () => {
|
||||
});
|
||||
|
||||
describe('fromRemoteCache', () => {
|
||||
const spy = {
|
||||
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
|
||||
};
|
||||
let spy: { [key: string]: jest.SpyInstance } = {};
|
||||
|
||||
beforeEach(() => {
|
||||
spy = {
|
||||
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
utils.setEnv('RUNNER_TOOL_CACHE', join('cache', 'path'));
|
||||
@@ -38,13 +43,13 @@ describe('fromRemoteCache', () => {
|
||||
|
||||
afterAll(() => {
|
||||
utils.restoreEnv();
|
||||
spy.restore.mockRestore();
|
||||
});
|
||||
|
||||
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()),
|
||||
`expo-cli-${process.platform}-${os.arch()}-yarn-3.20.1`,
|
||||
[join('cache', 'path', 'expo-cli', '3.20.1', os.arch())],
|
||||
`expo-cli-${process.platform}-${os.arch()}-yarn-3.20.1`,
|
||||
);
|
||||
});
|
||||
@@ -52,8 +57,7 @@ describe('fromRemoteCache', () => {
|
||||
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()),
|
||||
'custom-cache-key',
|
||||
[join('cache', 'path', 'expo-cli', '3.20.0', os.arch())],
|
||||
'custom-cache-key',
|
||||
);
|
||||
});
|
||||
@@ -61,7 +65,7 @@ describe('fromRemoteCache', () => {
|
||||
it('returns path when remote cache exists', async () => {
|
||||
spy.restore.mockResolvedValueOnce(true);
|
||||
await expect(cache.fromRemoteCache('3.20.1', 'npm')).resolves.toBe(
|
||||
join('cache', 'path', 'expo-cli', '3.20.1', os.arch()),
|
||||
join('cache', 'path', 'expo-cli', '3.20.1', os.arch())
|
||||
);
|
||||
});
|
||||
|
||||
@@ -73,21 +77,29 @@ describe('fromRemoteCache', () => {
|
||||
});
|
||||
|
||||
describe('toRemoteCache', () => {
|
||||
const spy = {
|
||||
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
|
||||
};
|
||||
let spy: { [key: string]: jest.SpyInstance } = {};
|
||||
|
||||
beforeEach(() => {
|
||||
spy = {
|
||||
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
|
||||
};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
spy.save.mockRestore();
|
||||
});
|
||||
|
||||
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'),
|
||||
`expo-cli-${process.platform}-${os.arch()}-npm-3.20.1`,
|
||||
[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 () => {
|
||||
|
||||
@@ -1,67 +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';
|
||||
|
||||
describe('authenticate', () => {
|
||||
const spy = {
|
||||
exec: jest.spyOn(cli, 'exec').mockImplementation(),
|
||||
info: jest.spyOn(core, 'info').mockImplementation(),
|
||||
};
|
||||
|
||||
it('skips authentication without credentials', async () => {
|
||||
await expo.authenticate('', '');
|
||||
expect(spy.exec).not.toBeCalled();
|
||||
expect(spy.info).toBeCalled();
|
||||
});
|
||||
|
||||
it('skips authentication without password', async () => {
|
||||
await expo.authenticate('bycedric', '');
|
||||
expect(spy.exec).not.toBeCalled();
|
||||
expect(spy.info).toBeCalled();
|
||||
});
|
||||
|
||||
it('executes login command with password through environment', async () => {
|
||||
utils.setEnv('TEST_INCLUDED', 'hellyeah');
|
||||
await expo.authenticate('bycedric', 'mypassword');
|
||||
expect(spy.exec).toBeCalled();
|
||||
expect(spy.exec.mock.calls[0][1]).toStrictEqual(['login', '--username=bycedric'])
|
||||
expect(spy.exec.mock.calls[0][2]).toMatchObject({
|
||||
env: {
|
||||
TEST_INCLUDED: 'hellyeah',
|
||||
EXPO_CLI_PASSWORD: 'mypassword',
|
||||
},
|
||||
});
|
||||
utils.restoreEnv();
|
||||
});
|
||||
|
||||
it('executes login command with `expo` on macos', async () => {
|
||||
utils.setPlatform('darwin');
|
||||
await expo.authenticate('bycedric', 'mypassword');
|
||||
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.authenticate('bycedric', 'mypassword');
|
||||
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.authenticate('bycedric', 'mypassword');
|
||||
expect(spy.exec).toBeCalled();
|
||||
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
|
||||
utils.restorePlatform();
|
||||
});
|
||||
|
||||
it('fails when credentials are incorrect', async () => {
|
||||
const error = new Error('Invalid username/password. Please try again.');
|
||||
spy.exec.mockRejectedValue(error);
|
||||
await expect(expo.authenticate('bycedric', 'incorrect')).rejects.toBe(error);
|
||||
});
|
||||
});
|
||||
+2
-13
@@ -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);
|
||||
|
||||
+40
-17
@@ -1,20 +1,27 @@
|
||||
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';
|
||||
|
||||
interface MockInputProps {
|
||||
version?: string;
|
||||
packager?: string;
|
||||
token?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
patchWatchers?: string;
|
||||
@@ -26,14 +33,24 @@ const mockInput = (props: MockInputProps = {}) => {
|
||||
// fix: kind of dirty workaround for missing "mock 'value' based on arguments"
|
||||
const input = (name: string) => {
|
||||
switch (name) {
|
||||
case 'expo-version': return props.version || '';
|
||||
case 'expo-packager': return props.packager || '';
|
||||
case 'expo-username': return props.username || '';
|
||||
case 'expo-password': return props.password || '';
|
||||
case 'expo-patch-watchers': return props.patchWatchers || '';
|
||||
case 'expo-cache': return props.cache || '';
|
||||
case 'expo-cache-key': return props.cacheKey || '';
|
||||
default: return '';
|
||||
case 'expo-version':
|
||||
return props.version || '';
|
||||
case 'expo-packager':
|
||||
return props.packager || '';
|
||||
case 'expo-token':
|
||||
return props.token || '';
|
||||
case 'expo-username':
|
||||
return props.username || '';
|
||||
case 'expo-password':
|
||||
return props.password || '';
|
||||
case 'expo-patch-watchers':
|
||||
return props.patchWatchers || '';
|
||||
case 'expo-cache':
|
||||
return props.cache || '';
|
||||
case 'expo-cache-key':
|
||||
return props.cacheKey || '';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
@@ -62,24 +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('bycedric', 'mypassword');
|
||||
expect(tools.maybeAuthenticate).toBeCalledWith({ username: 'bycedric', password: 'mypassword' });
|
||||
});
|
||||
|
||||
it('authenticates with provided token', async () => {
|
||||
mockInput({ token: 'ABC123', patchWatchers: 'false' });
|
||||
await run();
|
||||
expect(tools.maybeAuthenticate).toBeCalledWith({ token: 'ABC123' });
|
||||
});
|
||||
});
|
||||
@@ -1,57 +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', () => {
|
||||
const spy = {
|
||||
info: jest.spyOn(core, 'info').mockImplementation(),
|
||||
warning: jest.spyOn(core, 'warning').mockImplementation(),
|
||||
exec: jest.spyOn(cli, 'exec').mockImplementation(),
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
utils.restorePlatform();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user