mirror of
https://github.com/expo/expo-github-action.git
synced 2026-11-15 17:32:45 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b57c37e9b | ||
|
|
76ce4de80e | ||
|
|
a888e4f311 | ||
|
|
2662a5f0de | ||
|
|
d4dc05e178 | ||
|
|
04e3b32e94 | ||
|
|
a11a47a3e8 | ||
|
|
79ebfbc3b8 | ||
|
|
6b8c488fd6 | ||
|
|
f13b0ea032 | ||
|
|
6354b0a047 | ||
|
|
da4e75428b | ||
|
|
6bc0bedbc7 | ||
|
|
9c0e696251 | ||
|
|
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,51 @@
|
||||
---
|
||||
name: Release
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release:
|
||||
description: 'type "release" to confirm creating a new release (main branch only)'
|
||||
required: false
|
||||
jobs:
|
||||
release:
|
||||
name: Release version
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Setup repo
|
||||
uses: actions/checkout@v2
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 14.x
|
||||
- name: Find cache
|
||||
id: yarn-cache-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
- name: Restore cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
- name: Install dependencies
|
||||
run: yarn install --frozen-lockfile --check-files
|
||||
- name: Lint package
|
||||
run: yarn lint
|
||||
- name: Test package
|
||||
run: yarn test
|
||||
- name: Build clean
|
||||
run: yarn clean
|
||||
- name: Build package
|
||||
run: yarn build
|
||||
- name: Build up-to-date
|
||||
run: git diff --stat --exit-code build
|
||||
- name: Test-run release
|
||||
if: success() && github.event.inputs.release != 'release'
|
||||
run: yarn semantic-release --dry-run
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Create release
|
||||
if: success() && github.event.inputs.release == 'release' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
||||
run: yarn semantic-release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -0,0 +1 @@
|
||||
_
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
. "$(dirname "$0")/_/husky.sh"
|
||||
|
||||
yarn build
|
||||
git add build
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"printWidth": 120,
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"jsxBracketSameLine": true,
|
||||
"trailingComma": "es5",
|
||||
"arrowParens": "avoid"
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
const rules = [
|
||||
{ type: 'feat', release: 'minor', title: 'New features' },
|
||||
{ type: 'feature', release: 'minor', title: 'New features' },
|
||||
{ type: 'fix', release: 'patch', title: 'Bug fixes' },
|
||||
{ type: 'refactor', release: 'patch', title: 'Code changes' },
|
||||
{ type: 'chore', release: 'patch', title: 'Other chores' },
|
||||
{ type: 'docs', release: 'patch', title: 'Documentation changes' },
|
||||
];
|
||||
|
||||
// Simple mapping to order the commit groups
|
||||
const sortMap = Object.fromEntries(rules.map((rule, index) => [rule.title, index]));
|
||||
|
||||
module.exports = {
|
||||
branches: ['main', 'master'],
|
||||
tagFormat: '${version}',
|
||||
plugins: [
|
||||
['@semantic-release/commit-analyzer', {
|
||||
preset: 'conventionalcommits',
|
||||
releaseRules: rules.map(({ type, release }) => ({ type, release })),
|
||||
}],
|
||||
['@semantic-release/release-notes-generator', {
|
||||
preset: 'conventionalcommits',
|
||||
presetConfig: {
|
||||
types: rules.map(({ type, title }) => ({ type, section: title })),
|
||||
},
|
||||
writerOpts: {
|
||||
commitGroupsSort: (a, z) => sortMap[a.title] - sortMap[z.title],
|
||||
},
|
||||
}],
|
||||
'@semantic-release/changelog',
|
||||
['@semantic-release/npm', { npmPublish: false }],
|
||||
['@semantic-release/git', {
|
||||
message: 'chore: create new release ${nextRelease.version}\n\n${nextRelease.notes}',
|
||||
assets: ['package.json', 'CHANGELOG.md'],
|
||||
}],
|
||||
'@semantic-release/github',
|
||||
],
|
||||
};
|
||||
@@ -1,3 +1,78 @@
|
||||
### [5.5.1](https://github.com/expo/expo-github-action/compare/5.5.0...5.5.1) (2021-06-17)
|
||||
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* revert to node 12 for the action ([2662a5f](https://github.com/expo/expo-github-action/commit/2662a5f0dec42d7a9c66b55f8ce937f37aaac9b4))
|
||||
|
||||
## [5.5.0](https://github.com/expo/expo-github-action/compare/5.4.0...5.5.0) (2021-06-17)
|
||||
|
||||
|
||||
### New features
|
||||
|
||||
* switch to node 14 for the action itself ([f13b0ea](https://github.com/expo/expo-github-action/commit/f13b0ea032efcf2e6689743879af6b3e1c72201d))
|
||||
|
||||
|
||||
### Bug fixes
|
||||
|
||||
* add support for environments without remote cache ([#91](https://github.com/expo/expo-github-action/issues/91)) ([9c0e696](https://github.com/expo/expo-github-action/commit/9c0e6962510d4e08c6429cac42f624c563675ee1))
|
||||
|
||||
|
||||
### Code changes
|
||||
|
||||
* simplify typescript config with community config ([#94](https://github.com/expo/expo-github-action/issues/94)) ([da4e754](https://github.com/expo/expo-github-action/commit/da4e75428b7c5ffd16e8b2c698f590313c741621))
|
||||
* update all dependencies to latest versions ([#93](https://github.com/expo/expo-github-action/issues/93)) ([6bc0bed](https://github.com/expo/expo-github-action/commit/6bc0bedbc75bb0d6743e4accf032cd01348d6775))
|
||||
|
||||
|
||||
### Other chores
|
||||
|
||||
* add semantic release for easy versioning ([#95](https://github.com/expo/expo-github-action/issues/95)) ([6354b0a](https://github.com/expo/expo-github-action/commit/6354b0a0477a72375cee808d8a5b6006d6e86e77))
|
||||
* fix the allowed branches for semenatic release ([6b8c488](https://github.com/expo/expo-github-action/commit/6b8c488fd6239c9a76d7f95355a58bc8b2a20ac4))
|
||||
* mock the github actions warning to avoid leaking annotations ([#96](https://github.com/expo/expo-github-action/issues/96)) ([a11a47a](https://github.com/expo/expo-github-action/commit/a11a47a3e8735a206eed196499604322b0bdc877))
|
||||
* tweak the release workflow ([79ebfbc](https://github.com/expo/expo-github-action/commit/79ebfbc3b83497f443fd65eb5bd33484e5519f64))
|
||||
|
||||
|
||||
### Documentation changes
|
||||
|
||||
* add missing release step to contributing guide ([04e3b32](https://github.com/expo/expo-github-action/commit/04e3b32e94e3abe9cd65d37c57a0cead55186970))
|
||||
|
||||
## [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
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# Contributing to Expo Github Action
|
||||
|
||||
## 📦 Download and Setup
|
||||
|
||||
1. [Fork](https://help.github.com/articles/fork-a-repo/) this repository to your own GitHub account and then [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device. (`git remote add upstream [email protected]:expo/expo-github-action.git` 😉)
|
||||
2. Make sure you have the following packages globally installed on your system:
|
||||
- [node](https://nodejs.org/) (active Node LTS or higher is recommended)
|
||||
- [yarn](https://yarnpkg.com/)
|
||||
3. Install the Node packages (`yarn install`)
|
||||
|
||||
## 🏎️ Running a custom version
|
||||
|
||||
To try out your changed with Github Action, you have [to reference your fork and/or branch or commit reference](https://docs.github.com/en/actions/learn-github-actions/finding-and-customizing-actions#using-release-management-for-your-custom-actions) in the workflow you want to try. After that, you have two options:
|
||||
|
||||
1. Run the workflow in Github Actions itself by triggering your workflow.
|
||||
2. Run the workflow locally with [nektos/act](https://github.com/nektos/act).
|
||||
|
||||
## ✅ Testing
|
||||
|
||||
Testing is done using [Jest](https://jestjs.io/https://jestjs.io/). Run `yarn test` to run Jest.
|
||||
|
||||
In CI we are running tests on multiple Node versions using Windows, Linux, and MacOS. Make sure they are passing for your PR.
|
||||
|
||||
## 📝 Writing a Commit Message
|
||||
|
||||
> If this is your first time committing to a large public repo, you could look through this neat tutorial: ["How to Write a Git Commit Message"](https://chris.beams.io/posts/git-commit/)
|
||||
|
||||
Commit messages are formatted using the [Conventional Commits](https://www.conventionalcommits.org/) format. You can take a look at [`.releaserc.js`](./.releaserc.js) for the allowed commit types.
|
||||
|
||||
```
|
||||
docs: fix typo in xxx
|
||||
feature: add support for SDK 40
|
||||
chore: add test-case for custom completions
|
||||
fix: improve logging for errors
|
||||
refactor: update loading icon
|
||||
```
|
||||
|
||||
## 🔎 Before Submitting a PR
|
||||
|
||||
To get your PR merged as fast as possible, please make sure you have done the following:
|
||||
|
||||
- Run `yarn lint --fix` to fix the formatting of the code. Ensure that `yarn lint` succeeds without errors or warnings.
|
||||
- Run `yarn test` to make sure all normal use cases are passing.
|
||||
- Run `yarn build` to ensure the build is up-to-date and runs correctly and without errors or warnings.
|
||||
|
||||
## 🚀 Releasing a new version
|
||||
|
||||
To release a new version for Github Actions, we have to create a new release in Github. You can run the `Release` workflow to generate a new version, changelog, and Github release.
|
||||
|
||||
After the exact version tag is created, update the `v{major}` tag to the latest major version. Make sure you are on the default branch at the commit of versioning.
|
||||
|
||||
```bash
|
||||
$ git checkout master
|
||||
$ git fetch --tags && git pull
|
||||
$ git tag --force v{major}
|
||||
$ git push --force --tags
|
||||
```
|
||||
@@ -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:
|
||||
|
||||
+144006
-56627
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,47 @@
|
||||
'use strict'
|
||||
|
||||
const ls = require('../ls.js')
|
||||
const get = require('../get.js')
|
||||
const put = require('../put.js')
|
||||
const rm = require('../rm.js')
|
||||
const verify = require('../verify.js')
|
||||
const setLocale = require('../lib/util/y.js').setLocale
|
||||
const clearMemoized = require('../lib/memoization.js').clearMemoized
|
||||
const tmp = require('../lib/util/tmp.js')
|
||||
|
||||
setLocale('en')
|
||||
|
||||
const x = module.exports
|
||||
|
||||
x.ls = cache => ls(cache)
|
||||
x.ls.stream = cache => ls.stream(cache)
|
||||
|
||||
x.get = (cache, key, opts) => get(cache, key, opts)
|
||||
x.get.byDigest = (cache, hash, opts) => get.byDigest(cache, hash, opts)
|
||||
x.get.sync = (cache, key, opts) => get.sync(cache, key, opts)
|
||||
x.get.sync.byDigest = (cache, key, opts) => get.sync.byDigest(cache, key, opts)
|
||||
x.get.stream = (cache, key, opts) => get.stream(cache, key, opts)
|
||||
x.get.stream.byDigest = (cache, hash, opts) => get.stream.byDigest(cache, hash, opts)
|
||||
x.get.copy = (cache, key, dest, opts) => get.copy(cache, key, dest, opts)
|
||||
x.get.copy.byDigest = (cache, hash, dest, opts) => get.copy.byDigest(cache, hash, dest, opts)
|
||||
x.get.info = (cache, key) => get.info(cache, key)
|
||||
x.get.hasContent = (cache, hash) => get.hasContent(cache, hash)
|
||||
x.get.hasContent.sync = (cache, hash) => get.hasContent.sync(cache, hash)
|
||||
|
||||
x.put = (cache, key, data, opts) => put(cache, key, data, opts)
|
||||
x.put.stream = (cache, key, opts) => put.stream(cache, key, opts)
|
||||
|
||||
x.rm = (cache, key) => rm.entry(cache, key)
|
||||
x.rm.all = cache => rm.all(cache)
|
||||
x.rm.entry = x.rm
|
||||
x.rm.content = (cache, hash) => rm.content(cache, hash)
|
||||
|
||||
x.setLocale = lang => setLocale(lang)
|
||||
x.clearMemoized = () => clearMemoized()
|
||||
|
||||
x.tmp = {}
|
||||
x.tmp.mkdir = (cache, opts) => tmp.mkdir(cache, opts)
|
||||
x.tmp.withTmp = (cache, opts, cb) => tmp.withTmp(cache, opts, cb)
|
||||
|
||||
x.verify = (cache, opts) => verify(cache, opts)
|
||||
x.verify.lastRun = cache => verify.lastRun(cache)
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"No cache entry for `%s` found in `%s`": "No cache entry for %s found in %s",
|
||||
"Integrity verification failed for %s (%s)": "Integrity verification failed for %s (%s)",
|
||||
"Bad data size: expected inserted data to be %s bytes, but got %s instead": "Bad data size: expected inserted data to be %s bytes, but got %s instead",
|
||||
"Cache input stream was empty": "Cache input stream was empty",
|
||||
"Integrity check failed:\n Wanted: %s\n Found: %s": "Integrity check failed:\n Wanted: %s\n Found: %s"
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
'use strict'
|
||||
|
||||
const ls = require('../ls.js')
|
||||
const get = require('../get.js')
|
||||
const put = require('../put.js')
|
||||
const rm = require('../rm.js')
|
||||
const verify = require('../verify.js')
|
||||
const setLocale = require('../lib/util/y.js').setLocale
|
||||
const clearMemoized = require('../lib/memoization.js').clearMemoized
|
||||
const tmp = require('../lib/util/tmp.js')
|
||||
|
||||
setLocale('es')
|
||||
|
||||
const x = module.exports
|
||||
|
||||
x.ls = cache => ls(cache)
|
||||
x.ls.flujo = cache => ls.stream(cache)
|
||||
|
||||
x.saca = (cache, clave, ops) => get(cache, clave, ops)
|
||||
x.saca.porHacheo = (cache, hacheo, ops) => get.byDigest(cache, hacheo, ops)
|
||||
x.saca.sinc = (cache, clave, ops) => get.sync(cache, clave, ops)
|
||||
x.saca.sinc.porHacheo = (cache, hacheo, ops) => get.sync.byDigest(cache, hacheo, ops)
|
||||
x.saca.flujo = (cache, clave, ops) => get.stream(cache, clave, ops)
|
||||
x.saca.flujo.porHacheo = (cache, hacheo, ops) => get.stream.byDigest(cache, hacheo, ops)
|
||||
x.sava.copia = (cache, clave, destino, opts) => get.copy(cache, clave, destino, opts)
|
||||
x.sava.copia.porHacheo = (cache, hacheo, destino, opts) => get.copy.byDigest(cache, hacheo, destino, opts)
|
||||
x.saca.info = (cache, clave) => get.info(cache, clave)
|
||||
x.saca.tieneDatos = (cache, hacheo) => get.hasContent(cache, hacheo)
|
||||
x.saca.tieneDatos.sinc = (cache, hacheo) => get.hasContent.sync(cache, hacheo)
|
||||
|
||||
x.mete = (cache, clave, datos, ops) => put(cache, clave, datos, ops)
|
||||
x.mete.flujo = (cache, clave, ops) => put.stream(cache, clave, ops)
|
||||
|
||||
x.rm = (cache, clave) => rm.entry(cache, clave)
|
||||
x.rm.todo = cache => rm.all(cache)
|
||||
x.rm.entrada = x.rm
|
||||
x.rm.datos = (cache, hacheo) => rm.content(cache, hacheo)
|
||||
|
||||
x.ponLenguaje = lang => setLocale(lang)
|
||||
x.limpiaMemoizado = () => clearMemoized()
|
||||
|
||||
x.tmp = {}
|
||||
x.tmp.mkdir = (cache, ops) => tmp.mkdir(cache, ops)
|
||||
x.tmp.hazdir = x.tmp.mkdir
|
||||
x.tmp.conTmp = (cache, ops, cb) => tmp.withTmp(cache, ops, cb)
|
||||
|
||||
x.verifica = (cache, ops) => verify(cache, ops)
|
||||
x.verifica.ultimaVez = cache => verify.lastRun(cache)
|
||||
x.verifica.últimaVez = x.verifica.ultimaVez
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"No cache entry for `%s` found in `%s`": "No existe ninguna entrada para «%s» en «%s»",
|
||||
"Integrity verification failed for %s (%s)": "Verificación de integridad falló para «%s» (%s)",
|
||||
"Bad data size: expected inserted data to be %s bytes, but got %s instead": "Tamaño incorrecto de datos: los datos insertados debieron haber sido %s octetos, pero fueron %s",
|
||||
"Cache input stream was empty": "El stream de entrada al caché estaba vacío"
|
||||
}
|
||||
+27
-24
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "expo-github-action",
|
||||
"version": "5.1.0",
|
||||
"version": "5.5.1",
|
||||
"description": "Expo CLI in your GitHub Actions workflow",
|
||||
"main": "build/index.js",
|
||||
"repository": {
|
||||
@@ -18,34 +18,37 @@
|
||||
"test": "jest",
|
||||
"lint": "tsc --noEmit && eslint --ext ts ./src ./tests",
|
||||
"build": "ncc build src/index.ts --out build",
|
||||
"clean": "rimraf build"
|
||||
"clean": "rimraf build",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/cache": "github:cypress-io/github-actions-cache#8bec6cc",
|
||||
"@actions/core": "^1.2.4",
|
||||
"@actions/exec": "^1.0.4",
|
||||
"@actions/io": "^1.0.2",
|
||||
"@actions/tool-cache": "^1.5.5",
|
||||
"libnpm": "^3.0.1"
|
||||
"@actions/cache": "^1.0.7",
|
||||
"@actions/core": "^1.4.0",
|
||||
"@actions/exec": "^1.1.0",
|
||||
"@actions/io": "^1.1.1",
|
||||
"@actions/tool-cache": "^1.7.1",
|
||||
"libnpm": "^3.0.1",
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.4",
|
||||
"@types/node": "^12.12.49",
|
||||
"@typescript-eslint/eslint-plugin": "^3.6.1",
|
||||
"@typescript-eslint/parser": "^3.6.1",
|
||||
"@semantic-release/changelog": "^5.0.1",
|
||||
"@semantic-release/git": "^9.0.0",
|
||||
"@tsconfig/node14": "^1.0.1",
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/node": "^14.17.3",
|
||||
"@types/semver": "^7.3.6",
|
||||
"@typescript-eslint/eslint-plugin": "^4.27.0",
|
||||
"@typescript-eslint/parser": "^4.27.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",
|
||||
"conventional-changelog-conventionalcommits": "^4.6.0",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"husky": "^6.0.0",
|
||||
"jest": "^27.0.4",
|
||||
"jest-circus": "^27.0.4",
|
||||
"rimraf": "^3.0.2",
|
||||
"ts-jest": "^26.1.2",
|
||||
"typescript": "^3.9.6"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "yarn build && git add build"
|
||||
}
|
||||
"semantic-release": "^17.4.4",
|
||||
"ts-jest": "^27.0.3",
|
||||
"typescript": "^4.3.3"
|
||||
}
|
||||
}
|
||||
+46
-10
@@ -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,14 +28,21 @@ 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);
|
||||
|
||||
if (hit) {
|
||||
return target;
|
||||
try {
|
||||
// When running with nektos/act, or other custom environments, the cache might not be set up.
|
||||
const hit = await restoreCache([target], cacheKey);
|
||||
if (hit) {
|
||||
return target;
|
||||
}
|
||||
} catch (error) {
|
||||
if (!handleRemoteCacheError(error)) {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,15 +50,43 @@ 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 (!handleRemoteCacheError(error)) {
|
||||
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}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle any incoming errors from cache methods.
|
||||
* This can include actual errors like `ReserveCacheErrors` or unavailability errors.
|
||||
* When the error is handled, it MUST provide feedback for the developer.
|
||||
*
|
||||
* @returns If the error was handled properly.
|
||||
*/
|
||||
function handleRemoteCacheError(error: Error): boolean {
|
||||
const isReserveCacheError = error instanceof ReserveCacheError;
|
||||
const isCacheUnavailable = error.message.toLowerCase().includes(
|
||||
'cache service url not found',
|
||||
);
|
||||
|
||||
if (isReserveCacheError || isCacheUnavailable) {
|
||||
core.warning('Skipping remote cache storage, encountered error:');
|
||||
core.warning(error.message);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
-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);
|
||||
}
|
||||
+48
-15
@@ -1,7 +1,9 @@
|
||||
import os from 'os';
|
||||
import { join } from 'path';
|
||||
import * as remoteCache from '@actions/cache/lib';
|
||||
import * as remoteCache from '@actions/cache';
|
||||
import * as core from '@actions/core';
|
||||
import * as toolCache from '@actions/tool-cache';
|
||||
|
||||
import * as cache from '../src/cache';
|
||||
import * as utils from './utils';
|
||||
|
||||
@@ -28,9 +30,14 @@ 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(),
|
||||
warning: jest.spyOn(core, 'warning').mockImplementation(),
|
||||
};
|
||||
});
|
||||
|
||||
beforeAll(() => {
|
||||
utils.setEnv('RUNNER_TOOL_CACHE', join('cache', 'path'));
|
||||
@@ -38,13 +45,14 @@ describe('fromRemoteCache', () => {
|
||||
|
||||
afterAll(() => {
|
||||
utils.restoreEnv();
|
||||
spy.restore.mockRestore();
|
||||
spy.warning.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 +60,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 +68,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())
|
||||
);
|
||||
});
|
||||
|
||||
@@ -70,24 +77,42 @@ describe('fromRemoteCache', () => {
|
||||
spy.restore.mockRejectedValueOnce(error);
|
||||
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).rejects.toBe(error);
|
||||
});
|
||||
|
||||
it('skips remote cache when unavailable', async () => {
|
||||
// see: https://github.com/actions/toolkit/blob/9167ce1f3a32ad495fc1dbcb574c03c0e013ae53/packages/cache/src/internal/cacheHttpClient.ts#L41
|
||||
const error = new Error('Cache Service Url not found, unable to restore cache.');
|
||||
spy.restore.mockRejectedValueOnce(error);
|
||||
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).resolves.toBeUndefined();
|
||||
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('toRemoteCache', () => {
|
||||
const spy = {
|
||||
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
|
||||
};
|
||||
let spy: { [key: string]: jest.SpyInstance } = {};
|
||||
|
||||
beforeEach(() => {
|
||||
spy = {
|
||||
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
|
||||
warning: jest.spyOn(core, 'warning').mockImplementation(),
|
||||
};
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
spy.save.mockRestore();
|
||||
spy.warning.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 () => {
|
||||
@@ -95,4 +120,12 @@ describe('toRemoteCache', () => {
|
||||
spy.save.mockRejectedValueOnce(error);
|
||||
await expect(cache.toRemoteCache(join('local', 'path'), '3.20.1', 'yarn')).rejects.toBe(error);
|
||||
});
|
||||
|
||||
it('skips remote cache when unavailable', async () => {
|
||||
// see: https://github.com/actions/toolkit/blob/9167ce1f3a32ad495fc1dbcb574c03c0e013ae53/packages/cache/src/internal/cacheHttpClient.ts#L41
|
||||
const error = new Error('Cache Service Url not found, unable to restore cache.');
|
||||
spy.save.mockRejectedValueOnce(error);
|
||||
await expect(cache.toRemoteCache(join('local', 'path'), '3.20.1', 'yarn')).resolves.toBeUndefined();
|
||||
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
|
||||
});
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
+3
-8
@@ -1,17 +1,12 @@
|
||||
{
|
||||
"extends": "./node_modules/@tsconfig/node14/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"target": "es6",
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"outDir": "./build",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"noImplicitAny": false,
|
||||
"esModuleInterop": true
|
||||
"noImplicitAny": false
|
||||
},
|
||||
"exclude": [
|
||||
"build",
|
||||
"node_modules",
|
||||
"tests/**"
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user