Compare commits

..
26 Commits
Author SHA1 Message Date
Cedric van Putten 1b57c37e9b docs: add commands to contirbuting guide for updating v{major} tags 2021-06-17 14:13:56 +02:00
Cedric van Putten 76ce4de80e docs: update upstream reference in contributing guide 2021-06-17 14:11:07 +02:00
semantic-release-bot a888e4f311 chore: create new release 5.5.1
### [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))
2021-06-17 12:00:20 +00:00
Cedric van Putten 2662a5f0de fix: revert to node 12 for the action 2021-06-17 13:58:51 +02:00
semantic-release-bot d4dc05e178 chore: create new release 5.5.0
## [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))
2021-06-17 11:56:00 +00:00
Cedric van Putten 04e3b32e94 docs: add missing release step to contributing guide 2021-06-17 13:48:41 +02:00
Cedric van Putten a11a47a3e8 chore: mock the github actions warning to avoid leaking annotations (#96) 2021-06-17 13:45:18 +02:00
Cedric van Putten 79ebfbc3b8 chore: tweak the release workflow
It should be able to publish from master and main, plus checks if the build is up to date
2021-06-17 13:36:09 +02:00
Cedric van Putten 6b8c488fd6 chore: fix the allowed branches for semenatic release 2021-06-17 13:30:48 +02:00
Cedric van Putten f13b0ea032 feature: switch to node 14 for the action itself
Although this isn't a big feature, it does include new features from Node.
2021-06-17 13:27:07 +02:00
Cedric van Putten 6354b0a047 chore: add semantic release for easy versioning (#95)
* chore: add semantic release for easy versioning

* chore: add workflow to release a new version

* docs: add contributing guide for developers
2021-06-17 13:22:35 +02:00
Cedric van Putten da4e75428b refactor: simplify typescript config with community config (#94) 2021-06-17 13:05:01 +02:00
Cedric van Putten 6bc0bedbc7 refactor: update all dependencies to latest versions (#93)
* refactor: update actions cache to 1.0.7

- Make caching more verbose
- Use GNU tar on macOS if available
- Fixes permissions issue extracting archives with GNU tar on macOS

* refactor: update actions core to 1.4.0

- Prepend newline for set-output
- Added the getBooleanInput function
- Added the trimWhitespace option to getInput
- Added the getMultilineInput function

* refactor: update actions exec to 1.1.0

- Better error for bad cwd
- Add getExecOutput function
- Fix stdline dropping large output

* refactor: update actions io to 1.1.1

- Add findInPath method to locate all matching executables in the system path
- Fixed a bug where we incorrectly escaped paths for rmrf

* refactor: update actions tool-cache to 1.7.1

- Force overwrite on default when extracted compressed files
- Export isExplicitVersion and evaluateVersions functions
- Allow arbirtary headers when downloading tools to the tc
- Update to latest @actions/io verison
- Fallback to os-releases file to get linux version

* refactor: update jest to 27

* refactor: update node types to 14.17.3

* refactor: update semver and types to latest version

* refactor: update typescript to latest version

* refactor: update eslint to latest version

* refactor: update husky to 6.0.0

* chore: rebuild yarn lockfile and build files
2021-06-17 12:51:22 +02:00
Cedric van Putten 9c0e696251 fix: add support for environments without remote cache (#91) 2021-06-17 00:48:00 +02:00
Cedric van Putten 8275e8fa89 chore: release version 5.4.0 2021-01-12 15:20:04 +01:00
Cedric van Putten 4ec7251759 chore: update all dependencies to latest versions (#78) 2021-01-12 14:43:14 +01:00
Cedric van Putten 6c0f4d78ba chore: update readme to latest expo cli and node (#77) 2021-01-12 14:40:35 +01:00
Cedric van Putten 917e072b54 refactor: improve error handling with update check (#76) 2021-01-12 14:32:44 +01:00
Cedric van Putten ed7f67d90e refactor: update all dev dependencies to latest version (#71)
* refactor: use node 14 as primary version to build from

* refactor: add explicit return types to all files

* refactor: update all dev dependencies to latest version

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

* Run yarn upgrade

* Add handling for ReserveCacheError (#1)

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

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

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

No files matched your search

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