Compare commits

..
12 Commits
Author SHA1 Message Date
Cedric van Putten 84e06132b2 chore: release new version 5.1.1 2020-06-10 19:28:03 +02:00
Brad Bumbalough 71dfeab7a0 fix: use inputs metadata key (#49) 2020-06-10 19:23:27 +02:00
Cedric van Putten f6dba4e7ce docs: fix typo in secrets link 2020-05-11 11:09:34 +02:00
Cedric van Putten 586d2b1bea docs: tweak the license to make it identifyable 2020-05-11 09:44:02 +02:00
Cedric van Putten 39cd204496 docs: refine the readme and update header style (#48)
* docs: update footer with a better design

* docs: refine some of the documentation
2020-05-09 22:42:25 +02:00
Cedric van Putten 58185fbf10 chore: release new version 5.1.0 (#47) 2020-05-08 13:16:50 +02:00
Cedric van Putten a4955da38e fix: remove custom and add global error handling (#46) 2020-05-08 12:54:13 +02:00
Cedric van Putten cb490968ad test: check if build is up to date (#45) 2020-05-08 12:35:19 +02:00
Cedric van Putten 42793272a5 test: add missing cache unit tests (#44)
* test: add missing cache unit tests

* refactor: clean up the tests
2020-05-08 12:22:22 +02:00
Cedric van Putten a7b6ce4357 feat: fail when provided credentials are incorrect (#43)
* refactor: add and use restore env utils for testing

* feat: fail when provided credentials are incorrect
2020-05-08 10:40:00 +02:00
Cedric van Putten 32b5f9cee8 chore: update dependencies and configuration (#42)
* chore: update dependencies and configuration

* chore: update eslint to match typescript files

* chore: reconfigure jest for 27 defaults

* chore: switch to yarn instead of npm

* chore: add node 14 to circle ci
2020-05-08 10:22:47 +02:00
dependabot[bot] 4aaf05ff10 chore(deps): bump acorn from 5.7.3 to 5.7.4
Bumps [acorn](https://github.com/acornjs/acorn) from 5.7.3 to 5.7.4.
- [Release notes](https://github.com/acornjs/acorn/releases)
- [Commits](https://github.com/acornjs/acorn/compare/5.7.3...5.7.4)

Signed-off-by: dependabot[bot] <[email protected]>
2020-03-14 11:22:33 -07:00
20 changed files with 13872 additions and 20721 deletions

No files matched your search

+23 -4
View File
@@ -4,10 +4,17 @@ version: 2
scripts: &scripts
steps:
- checkout
- run: npm ci
- run: npm test
- run: npm run lint
- run: npm run build
- run: yarn
- run: yarn test
- run: yarn lint
- run: yarn build
uptodate: &uptodate
steps:
- checkout
- run: yarn
- run: yarn build
- run: git diff --exit-code build
jobs:
node-10:
@@ -22,6 +29,16 @@ jobs:
<<: *scripts
docker:
- image: circleci/node:13
node-14:
<<: *scripts
docker:
- image: circleci/node:14
uptodate:
<<: *uptodate
requires:
- node-12
docker:
- image: circleci/node:12
workflows:
version: 2
@@ -30,3 +47,5 @@ workflows:
- node-10
- node-12
- node-13
- node-14
- uptodate
+16
View File
@@ -0,0 +1,16 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
indent_style = space
trim_trailing_whitespace = false
[*.yml]
indent_size = 2
indent_style = space
+25
View File
@@ -0,0 +1,25 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'jest',
],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error', { 'accessibility': 'no-public' },
],
'@typescript-eslint/indent': ['error', 'tab'],
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-use-before-define': 'off',
},
};
-28
View File
@@ -1,28 +0,0 @@
{
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jest"
],
"env": {
"es6": true,
"jest/globals": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
"accessibility": "no-public"
}
],
"@typescript-eslint/indent": ["error", "tab"],
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-use-before-define": "off"
}
}
+28
View File
@@ -1,3 +1,31 @@
## [5.1.0](https://github.com/expo/expo-github-action/compare/5.1.0...5.1.1) (2020-06-10)
### Bug fixes
* use inputs metadata key ([#49](https://github.com/expo/expo-github-action/pull/49)) ([71dfeab](https://github.com/expo/expo-github-action/commit/71dfeab))
## [5.1.0](https://github.com/expo/expo-github-action/compare/5.0.0...5.1.0) (2020-05-08)
### New features
* fail when provided credentials are incorrect ([#43](https://github.com/expo/expo-github-action/pull/43)) ([a7b6ce4](https://github.com/expo/expo-github-action/commit/a7b6ce4))
### Bug fixes
* remove custom and add global error handling ([#46](https://github.com/expo/expo-github-action/pull/46)) ([a4955da](https://github.com/expo/expo-github-action/commit/a4955da))
### Test changes
* check if build is up to date ([#45](https://github.com/expo/expo-github-action/pull/45)) ([cb49096](https://github.com/expo/expo-github-action/commit/cb49096))
* add missing cache unit tests ([#44](https://github.com/expo/expo-github-action/pull/44)) ([4279327](https://github.com/expo/expo-github-action/commit/4279327))
### Other chores
* update dependencies and configuration ([#42](https://github.com/expo/expo-github-action/pull/42)) ([32b5f9c](https://github.com/expo/expo-github-action/commit/32b5f9c))
* **deps**: bump acorn from 5.7.3 to 5.7.4 ([#37](https://github.com/expo/expo-github-action/pull/37)) ([4aaf05f](https://github.com/expo/expo-github-action/commit/4aaf05f))
## [5.0.0](https://github.com/expo/expo-github-action/compare/4.1.0...5.0.0) (2019-12-31)
### BREAKING CHANGES
+1
View File
@@ -1,6 +1,7 @@
# The MIT License (MIT)
Copyright (c) 2019-present Cedric van Putten <me@bycedric.com>
Copyright (c) 2019-present 650 Industries, Inc. (aka Expo)
> Permission is hereby granted, free of charge, to any person obtaining a copy
+76 -67
View File
@@ -1,37 +1,54 @@
# Expo GitHub Action
Publish, build, or manage your [Expo][link-expo] project with GitHub Actions!
This action installs the [Expo CLI][link-expo-cli] on your preferred os and authenticates your project.
You can also use [the Docker image][link-docker-expo] in other Docker-based environments.
1. [What's inside?](#whats-inside)
2. [Used variables](#used-variables)
3. [Example workflows](#example-workflows)
4. [Things to know](#things-to-know)
<div align="center">
<h1>expo github action</h1>
<p></p>
<p>Publish, build or manage your <a href="https://github.com/expo/expo">Expo</a> app with Github Actions!</p>
<sup>
<a href="https://github.com/expo/expo-github-action/releases">
<img src="https://img.shields.io/github/release/expo/expo-github-action/all.svg?style=flat-square" alt="releases" />
</a>
<a href="https://app.circleci.com/pipelines/github/expo/expo-github-action">
<img src="https://img.shields.io/circleci/build/github/expo/expo-github-action/master?style=flat-square" alt="builds" />
</a>
<a href="https://github.com/expo/expo-github-action/blob/master/LICENSE.md">
<img src="https://img.shields.io/github/license/expo/expo-github-action?style=flat-square" alt="license" />
</a>
</sup>
<br />
<p align="center">
<a href="https://github.com/expo/expo-github-action#configuration-options"><b>Usage</b></a>
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
<a href="https://github.com/expo/expo-github-action#example-workflows"><b>Examples</b></a>
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
<a href="https://github.com/expo/expo-github-action#things-to-know"><b>Caveats</b></a>
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
<a href="https://github.com/expo/expo-github-action/blob/master/CHANGELOG.md"><b>Changelog</b></a>
</p>
<br />
</div>
## What's inside?
Within this Expo action, you have full access to the [Expo CLI][link-expo-cli] itself.
That means you can perform any command like login, publish, and build.
Also, this action takes care of authentication when both `expo-username` and `expo-password` variables are defined.
With this Expo action, you have full access to the [Expo CLI][link-expo-cli] itself.
It allows you to fully automate the `expo publish` or `expo build` process, leaving you with more time available for your project.
There are some additional features included to make the usage of this action as simple as possible, like caching and authentication.
## Used variables
## Configuration options
This action is customizable through variables; they are defined in the [`action.yml`][link-expo-cli-action].
This action is customizable through variables; they are defined in the [`action.yml`](action.yml).
Here is a summary of all the variables that you can use and their purpose.
variable | description
--- | ---
`expo-username` | The username of your Expo account. _(you can hardcode this or use secrets)_
`expo-password` | The password of your Expo account. _**([use this with secrets][link-actions-secrets])**_
`expo-version` | The Expo CLI you want to use. _(can be any semver range, defaults to `latest`)_
`expo-packager` | The package manager you want to use to install the CLI. _(can be `npm` or `yarn`, defaults to `yarn`)_
`expo-cache` | If it should the actions cache, [read more about it here](#using-the-built-in-cache) _(can be `true` or `false`, defaults to `false`)_
`expo-cache-key` | An optional custom remote cache key _(**warning**, only use this when you know what you are doing)_
`expo-patch-watchers` | If it should patch the `fs.inotify.` limits causing `ENOSPC` errors on Linux. _(can be `true` or `false`, defaults to `true`)_
variable | default | description
--- | --- | ---
`expo-username` | - | The username of your Expo account _(e.g. `bycedric`)_
`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`)_
`expo-cache` | `false` | If it should the [GitHub actions (remote) cache]((#using-the-built-in-cache)).
`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).
> It's recommended to set the `expo-version` to avoid breaking changes when a new major version is released.
> For more info on how to use this, please read the [workflow syntax documentation][link-actions-syntax-with].
> Never hardcode your `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
@@ -61,7 +78,7 @@ jobs:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
@@ -77,8 +94,8 @@ jobs:
### Cache Expo CLI for other jobs
Below you can see a slightly modified version of the example above.
In this one, we enabled the built-in cache that will reuse a previous installed Expo CLI.
This skips the installation part and extracts the files directly, boosting the performance of your workflow.
In this one, we enabled the built-in cache that will reuse a previously installed Expo CLI.
It skips the installation part and extracts the files directly, boosting the performance of your workflow.
> You can [read more about the cache here](#using-the-built-in-cache)
@@ -93,7 +110,7 @@ jobs:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
@@ -110,8 +127,8 @@ jobs:
### Test PRs and publish a review version
Reviewing pull requests can take some time if you have to read every line of code.
To make this easier, you can publish the edited version of the PR using a dedicated release channel.
Below you can see an example of a workflow that publishes and comments when the app is ready for review.
To make this easier, you can publish the edited version of the PR using a [release channel][link-expo-release-channels].
Below you can see an example of a workflow that publishes and comments on te PR when the app is published.
```yml
name: Expo Review
@@ -121,7 +138,7 @@ jobs:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
@@ -143,7 +160,6 @@ jobs:
With GitHub Actions, it's reasonably easy to set up a matrix build and test the app on multiple environments.
These matrixes can help to make sure your app runs smoothly on a broad set of different development machines.
The action below is only running on pull requests to avoid unnecessary builds.
> If you don't need automatic authentication, you can omit the `expo-username` and `expo-password` variables.
@@ -159,7 +175,7 @@ jobs:
os: [ubuntu-latest, macOS-latest, windows-latest]
node: [10, 12, 13]
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
@@ -174,8 +190,7 @@ jobs:
### Test and build web every day at 08:00
You can also schedule jobs by using the cron syntax.
It helps you update or check your app now and then.
For example, the [Expo CLI Docker images uses this][link-docker-expo-cron] to make sure the images are up to date.
It can help to minimize the number of updates your users have to install.
```yml
name: Expo Daily CI
@@ -187,7 +202,7 @@ jobs:
name: Daily Continuous Integration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 12.x
@@ -203,48 +218,42 @@ jobs:
### Automatic Expo login
You need to authenticate for some Expo commands as `expo publish` and `expo build:*`.
This project has an additional feature to make this easy and secure.
The action uses the [`EXPO_CLI_PASSWORD`][link-expo-cli-password] variable internally to make this happen.
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.
> Note, this action only uses your credentials to authenticate with Expo. It doesn't store these anywhere.
### Using the built-in cache
As of writing, GitHub Actions lacks a feature to "cache" files and directories in 3rd party actions.
That's why we implemented the [Cypress fork of the `actions/cache`][link-actions-cache-cypress] to enable some sort of caching.
You can opt-in to this by setting the `expo-cache` variable to `true`.
If you know what you are doing and need more control, you can also define a custom cache key with `expo-cache-key`.
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.
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].
### ENOSPC errors on Linux
React Native bundles are created by the Metro bundler, even when using Expo.
Unfortunately, this Metro bundler requires quite some resources.
As of writing, GitHub Actions has some small default values for the `fs.inotify` settings.
Inside we included a patch that increases these limits for the "active workflow" run.
When you run `expo publish` or `expo build`, a new bundle is created.
Creating these bundles require quite some resources.
As of writing, GitHub actions has some small default values for the `fs.inotify` settings.
Inside this action, we included a patch that increases these limits for the current workflow.
It increases the `max_user_instances`, `max_user_watches` and `max_queued_events` to `524288`.
You can disable this patch by setting the `expo-patch-watchers` to `false`.
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
--- ---
<p align="center">
with :heart: <a href="https://bycedric.com" target="_blank">byCedric</a>
</p>
<div align="center">
<br />
with :heart: <strong>byCedric</strong>
<br />
</div>
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
[link-actions-cache]: https://github.com/actions/cache
[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-node]: https://github.com/actions/setup-node
[link-actions-secrets]: https://help.github.com/en/articles/virtual-environments-for-github-actions#creating-and-using-secrets-encrypted-variables
[link-actions-syntax-with]: https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepswith
[link-docker-expo]: https://github.com/bycedric/expo-cli-images
[link-docker-expo-cron]: https://github.com/byCedric/expo-cli-images/blob/d93389e52135d6a599853aed7893adc6a8b57c84/.github/workflows/daily-builds.yml#L5
[link-expo]: https://expo.io
[link-expo-cli]: https://docs.expo.io/versions/latest/workflow/expo-cli
[link-expo-cli-action]: action.yml
[link-expo-cli-password]: https://github.com/expo/expo-cli/blob/8ea616d8848a123270b97e226e33dcb3dde49653/packages/expo-cli/src/accounts.js#L94
[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/
[link-expo-cli-password]: https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/accounts.ts#L88-L90
[link-expo-release-channels]: https://docs.expo.io/distribution/release-channels/
[link-semver-playground]: https://semver.npmjs.com/
+1 -1
View File
@@ -8,7 +8,7 @@ branding:
runs:
using: node12
main: build/index.js
input:
inputs:
expo-version:
description: The Expo CLI version to install. (use any semver/dist-tag available)
default: latest
+7672 -13338
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -4,6 +4,7 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
-7214
View File
File diff suppressed because it is too large. Load diff
+16 -15
View File
@@ -1,7 +1,7 @@
{
"private": true,
"name": "expo-github-action",
"version": "5.0.0",
"version": "5.1.0",
"description": "Expo CLI in your GitHub Actions workflow",
"main": "build/index.js",
"repository": {
@@ -16,29 +16,30 @@
"homepage": "https://github.com/expo/expo-github-action#readme",
"scripts": {
"test": "jest",
"lint": "tsc --noEmit && eslint src/** tests/**",
"lint": "tsc --noEmit && eslint --ext ts ./src ./tests",
"build": "ncc build src/index.ts --out build"
},
"dependencies": {
"@actions/cache": "github:cypress-io/github-actions-cache#8bec6cc",
"@actions/core": "^1.2.0",
"@actions/exec": "^1.0.2",
"@actions/io": "^1.0.1",
"@actions/tool-cache": "^1.1.2",
"@actions/core": "^1.2.4",
"@actions/exec": "^1.0.4",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.3.4",
"libnpm": "^3.0.1"
},
"devDependencies": {
"@types/jest": "^24.0.25",
"@types/node": "^12.12.22",
"@typescript-eslint/eslint-plugin": "^2.13.0",
"@typescript-eslint/parser": "^2.13.0",
"@zeit/ncc": "^0.20.5",
"@types/jest": "^25.2.1",
"@types/node": "^13.13.5",
"@typescript-eslint/eslint-plugin": "^2.31.0",
"@typescript-eslint/parser": "^2.31.0",
"@zeit/ncc": "^0.22.1",
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.2.0",
"eslint-plugin-jest": "^23.9.0",
"husky": "^3.1.0",
"jest": "^24.9.0",
"ts-jest": "^24.2.0",
"typescript": "^3.7.4"
"jest": "^26.0.1",
"jest-circus": "^26.0.1",
"ts-jest": "^25.5.0",
"typescript": "^3.8.3"
},
"husky": {
"hooks": {
+6 -16
View File
@@ -1,5 +1,4 @@
import { restoreCache, saveCache } from '@actions/cache/lib';
import * as core from '@actions/core';
import * as toolCache from '@actions/tool-cache';
import path from 'path';
import os from 'os';
@@ -11,7 +10,7 @@ import os from 'os';
* @see https://github.com/actions/toolkit/issues/47
*/
export async function fromLocalCache(version: string) {
return toolCache.find('expo-cli', version, os.arch());
return toolCache.find('expo-cli', version);
}
/**
@@ -21,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) {
return toolCache.cacheDir(root, 'expo-cli', version, os.arch());
return toolCache.cacheDir(root, 'expo-cli', version);
}
/**
@@ -32,15 +31,10 @@ export async function fromRemoteCache(version: string, packager: string, customC
// 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);
try {
const hit = await restoreCache(target, cacheKey, cacheKey);
if (hit) {
return target;
}
} catch (error) {
core.setFailed(error.message);
if (hit) {
return target;
}
}
@@ -51,11 +45,7 @@ export async function fromRemoteCache(version: string, packager: string, customC
export async function toRemoteCache(source: string, version: string, packager: string, customCacheKey?: string) {
const cacheKey = customCacheKey || getRemoteKey(version, packager);
try {
await saveCache(source, cacheKey);
} catch (error) {
core.setFailed(error.message);
}
await saveCache(source, cacheKey);
}
/**
+2 -1
View File
@@ -1,3 +1,4 @@
import * as core from '@actions/core';
import { run } from './run';
run();
run().catch(core.setFailed);
+97
View File
@@ -0,0 +1,97 @@
import * as remoteCache from '@actions/cache/lib';
import * as toolCache from '@actions/tool-cache';
import os from 'os';
import * as cache from '../src/cache';
import * as utils from './utils';
describe('fromLocalCache', () => {
it('fetches the version specific cache', async () => {
const path = '/path/to/local/cache';
// todo: check why jest wants `never` instead of `string`
const find = jest.spyOn(toolCache, 'find').mockResolvedValue(path as never);
const result = await cache.fromLocalCache('3.20.1');
expect(result).toBe(path);
expect(find).toBeCalledWith('expo-cli', '3.20.1');
});
});
describe('toLocalCache', () => {
it('stores the version specific cache', async () => {
const path = '/path/to/local/cache';
const root = '/path/from/source';
const cacheDir = jest.spyOn(toolCache, 'cacheDir').mockResolvedValue(path);
const result = await cache.toLocalCache(root, '3.20.1');
expect(result).toBe(path);
expect(cacheDir).toBeCalledWith(root, 'expo-cli', '3.20.1');
});
});
describe('fromRemoteCache', () => {
const spy = {
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
};
beforeAll(() => {
utils.setEnv('RUNNER_TOOL_CACHE', '/cache/path');
});
afterAll(() => {
utils.restoreEnv();
});
it('restores remote cache with default key', async () => {
expect(await cache.fromRemoteCache('3.20.1', 'yarn')).toBeUndefined();
expect(remoteCache.restoreCache).toBeCalledWith(
`/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(
`/cache/path/expo-cli/3.20.0/${os.arch()}`,
'custom-cache-key',
'custom-cache-key',
);
});
it('returns path when remote cache exists', async () => {
spy.restore.mockResolvedValueOnce(true);
await expect(cache.fromRemoteCache('3.20.1', 'npm')).resolves.toBe(
`/cache/path/expo-cli/3.20.1/${os.arch()}`,
);
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache restore failed');
spy.restore.mockRejectedValueOnce(error);
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).rejects.toBe(error);
});
});
describe('toRemoteCache', () => {
const spy = {
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
};
it('saves remote cache with default key', async () => {
expect(await cache.toRemoteCache('/local/path', '3.20.1', 'npm')).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith(
'/local/path',
`expo-cli-${process.platform}-${os.arch()}-npm-3.20.1`,
);
});
it('saves remote cache with custom key', async () => {
expect(await cache.toRemoteCache('/local/path', '3.20.1', 'yarn', 'custom-cache-key')).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith('/local/path', 'custom-cache-key');
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache save failed');
spy.save.mockRejectedValueOnce(error);
await expect(cache.toRemoteCache('/local/path', '3.20.1', 'yarn')).rejects.toBe(error);
});
});
+11 -4
View File
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as expo from '../src/expo';
import { setPlatform, resetPlatform } from './utils';
import * as utils from './utils';
describe('authenticate', () => {
const spy = {
@@ -22,7 +22,7 @@ describe('authenticate', () => {
});
it('executes login command with password through environment', async () => {
process.env['TEST_INCLUDED'] = 'hellyeah';
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await expo.authenticate('bycedric', 'mypassword');
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo');
@@ -33,13 +33,20 @@ describe('authenticate', () => {
EXPO_CLI_PASSWORD: 'mypassword',
},
});
utils.restoreEnv();
});
it('executes login command with `.cmd` suffix on windows', async () => {
setPlatform('win32');
utils.setPlatform('win32');
await expo.authenticate('bycedric', 'mypassword');
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
resetPlatform();
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);
});
});
+30 -25
View File
@@ -14,6 +14,7 @@ jest.mock('libnpm', () => registry);
jest.mock('../src/cache', () => cache);
import * as install from '../src/install';
import * as utils from './utils';
describe('resolve', () => {
it('fetches exact version of expo-cli', async () => {
@@ -24,19 +25,41 @@ describe('resolve', () => {
});
describe('install', () => {
it('installs path from cache', async () => {
it('installs path from local cache', async () => {
cache.fromLocalCache.mockResolvedValue('/cache/path');
const expoPath = await install.install({ version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe('/cache/path/node_modules/.bin');
});
it('installs path from packager and cache it', async () => {
process.env['RUNNER_TEMP'] = '/temp/path';
it('installs path from packager and cache it locally', async () => {
utils.setEnv('RUNNER_TEMP', '/temp/path');
cache.fromLocalCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue('/cache/path');
const expoPath = await install.install({ version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe('/cache/path/node_modules/.bin');
expect(cache.toLocalCache).toBeCalledWith('/temp/path', '3.0.10');
utils.restoreEnv();
});
it('installs path from remote cache', async () => {
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue('/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('/cache/path/node_modules/.bin');
expect(cache.fromRemoteCache).toBeCalledWith('3.20.0', 'npm', undefined);
});
it('installs path from packager and cache it remotely', async () => {
utils.setEnv('RUNNER_TEMP', '/temp/path');
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue('/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('/cache/path/node_modules/.bin');
expect(cache.toRemoteCache).toBeCalledWith('/cache/path', '3.20.1', 'npm', undefined);
utils.restoreEnv();
});
});
@@ -47,13 +70,14 @@ describe('fromPackager', () => {
});
it('creates temporary folder', async () => {
process.env['RUNNER_TEMP'] = '/temp/path';
utils.setEnv('RUNNER_TEMP', '/temp/path');
await install.fromPackager('latest', 'yarn');
expect(io.mkdirP).toBeCalledWith('/temp/path');
utils.restoreEnv();
});
it('installs expo with tool', async () => {
process.env['RUNNER_TEMP'] = '/temp/path';
utils.setEnv('RUNNER_TEMP', '/temp/path');
io.which.mockResolvedValue('npm');
const expoPath = await install.fromPackager('beta', 'npm');
expect(expoPath).toBe('/temp/path');
@@ -61,25 +85,6 @@ describe('fromPackager', () => {
expect(cli.exec.mock.calls[0][0]).toBe('npm');
expect(cli.exec.mock.calls[0][1]).toStrictEqual(['add', 'expo-cli@beta']);
expect(cli.exec.mock.calls[0][2]).toMatchObject({ cwd: '/temp/path' });
utils.restoreEnv();
});
});
// todo: move this to cache tests
// describe('fromCache', () => {
// it('uses cache for exact version', async () => {
// toolCache.find.mockResolvedValue('/cache/expo/path');
// const cachePath = await install.fromCache('3.0.10');
// expect(toolCache.find).toBeCalledWith('expo-cli', '3.0.10');
// expect(cachePath).toBe('/cache/expo/path');
// });
// });
// describe('toCache', () => {
// it('uses cache for installed folder', async () => {
// toolCache.cacheDir.mockResolvedValue('/cache/expo/path');
// const cachePath = await install.toCache('3.0.10', '/expo/install/path');
// expect(toolCache.cacheDir).toBeCalledWith('/expo/install/path', 'expo-cli', '3.0.10');
// expect(cachePath).toBe('/cache/expo/path');
// });
// });
+7 -7
View File
@@ -1,7 +1,7 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';
import * as system from '../src/system';
import { setPlatform, resetPlatform } from './utils';
import * as utils from './utils';
describe('patchWatchers', () => {
const spy = {
@@ -11,11 +11,11 @@ describe('patchWatchers', () => {
};
afterEach(() => {
resetPlatform();
utils.restorePlatform();
});
it('increses fs inotify settings with sysctl', async () => {
setPlatform('linux');
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');
@@ -26,7 +26,7 @@ describe('patchWatchers', () => {
it('warns for unsuccessful patches', async () => {
const error = new Error('Something went wrong');
spy.exec.mockRejectedValueOnce(error);
setPlatform('linux');
utils.setPlatform('linux');
await system.patchWatchers();
expect(core.warning).toBeCalledWith(expect.stringContaining('can\'t patch watchers'));
expect(core.warning).toBeCalledWith(
@@ -35,21 +35,21 @@ describe('patchWatchers', () => {
});
it('skips on windows platform', async () => {
setPlatform('win32');
utils.setPlatform('win32');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('skips on macos platform', async () => {
setPlatform('darwin');
utils.setPlatform('darwin');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping'));
expect(spy.exec).not.toHaveBeenCalled();
});
it('runs on linux platform', async () => {
setPlatform('linux');
utils.setPlatform('linux');
await system.patchWatchers();
expect(spy.info).toBeCalledWith(expect.stringContaining('Patching'));
expect(spy.exec).toHaveBeenCalled();
+18 -1
View File
@@ -12,6 +12,23 @@ export function setPlatform(platform: NodeJS.Platform) {
/**
* Revert the platform to the original one.
*/
export function resetPlatform() {
export function restorePlatform() {
setPlatform(originalPlatform);
}
// keep track of the original environment variables
const originalEnv = { ...process.env };
/**
* Change the environment variable for testing purposes.
*/
export function setEnv(name: string, value: string) {
process.env[name] = value;
}
/**
* Revert the environment variable changes.
*/
export function restoreEnv() {
process.env = originalEnv;
}
+5842
View File
File diff suppressed because it is too large. Load diff