Compare commits

...
37 Commits
Author SHA1 Message Date
Cedric van Putten f6b6254e5d fix: add specific azure externals to avoid bundling issues 2022-01-12 16:25:19 +01:00
Cedric van Putten 4908a48f1b chore: add manual trigger to the tests 2022-01-12 16:19:15 +01:00
Cedric van Putten 3f9e947963 refactor: use swc pack instead of ncc (#140)
* refactor: implement swc instead of ncc

* chore: tweak the swc implementation with externals

* chore: remove ncc from the project

* fix: update the entrypoint in the main action file

* chore: fix linting issues

* chore: add swc folder to ignore list

* chore: update gitignore list

* fix: force-remove sourcemaps from the build

Unfortunately, it seems that we cant disable this in swc pack
2022-01-12 16:14:27 +01:00
Cedric van Putten ee415b027a chore: simplify review and update build detection (#142)
Because we now have e2e tests for macos, ubuntu, and windows, we dont need to lint on this anymore
2022-01-12 15:57:34 +01:00
Cedric van Putten 414c1693e6 chore: add basic e2e test workflow for main action (#141) 2022-01-12 15:28:56 +01:00
Cedric van Putten 4f28493708 refactor: replace libnpm with npm cli (#139)
* refactor: add npm version resolver

* refactor: replace libnpm with npm cli execution

* refactor: remove libnpm from project

* chore: fix linting issues

* chore: rebuild project
2022-01-12 02:15:39 +01:00
Cedric van Putten 3134e26b3a refactor: update the outdated workflows and use node 16 (#138)
* refactor: update the outdated workflows and use node 16

* refactor: naming tweak
2022-01-11 21:15:31 +01:00
Cedric van Putten 3bf9181edb refactor: upgrade to node 16 github actions runtime (#137) 2022-01-11 18:48:29 +01:00
Cedric van Putten 39b0d361f7 chore: remove husky and improve ci build message (#128)
* chore: remove husky and improve ci build message

* chore: remove the additional macos build check
2021-11-17 12:58:42 +01:00
Cedric van Putten f1fe877592 refactor: use boolean input instead of manual conversion (#127)
* refactor: use boolean input instead of manual conversion

* refactor: update setup test with less manual mocks

* chore: upgrade to latest actions core version

* fix: clean up the mock input util

* chore: rebuild from macos

* fix: add text to gitattributes

* chore: remove built files

* chore: add build files back
2021-11-17 12:48:22 +01:00
Cedric van Putten ff2ff0f980 refactor: use spaces for indentation (#126)
* chore: move over to spaces in editorconfig

* chore: move over to spaces in eslint

* chore: reformat all files with spaces

* chore: fix wrong editorconfig setting

* chore: rebuild files
2021-11-16 08:15:51 -08:00
Bartosz Kaszubowski 1cfa7bbd9e chore: lint root files with prettier and eslint (#125)
* chore: hook up Prettier, lint root files, reformat

* fix prettier checks on Windows

* remove redundant string
2021-11-16 07:15:14 -08:00
Cedric van Putten 8a7306a978 refactor: allow multiple entrypoints for different sub-actions (#121)
* feature: add perform action to run actions on GitHub

* refactor: move default entrypoint to actions folder

* refactor: upgrade ncc and add multiple entrypoints

* chore: rebuild action files

* core: force-write lf in build files

* chore: rebuild from macos
2021-11-16 05:48:51 -08:00
Bartosz Kaszubowski c20146f3b7 chore: clean up tsconfig and eslint rules (#123) 2021-11-16 05:34:16 -08:00
Cedric van Putten a9b9cfef50 chore: always use lf for build files (#122)
* chore: add build files to lf conversions

* chore: delete all built files

* chore: rebuild all files

* chore: rebuild from macos
2021-11-16 05:33:34 -08:00
Bartosz Kaszubowski 3b3e6b8031 chore: update setup-node action to v2 release (#119) 2021-11-16 04:42:18 -08:00
Bartosz Kaszubowski 186ef0011a chore: upgrade dev dependencies and rebuild action (#120) 2021-11-16 04:36:42 -08:00
Cedric van Putten 45b79a05ef chore: rebuild project 2021-11-15 12:00:31 +01:00
Cedric van Putten 0b1822a935 docs: fix broken sup element in readme 2021-11-15 02:22:11 -08:00
Frieder Bluemle b60246939f docs: fix github capitalization (#116) 2021-11-15 02:20:06 -08:00
Cedric van Putten b099f17d58 chore: rebuild project after dependency bumps 2021-09-22 13:35:10 +02:00
dependabot[bot] 50c0ef9028 chore: bump semver-regex from 3.1.2 to 3.1.3 (#114)
Bumps [semver-regex](https://github.com/sindresorhus/semver-regex) from 3.1.2 to 3.1.3.
- [Release notes](https://github.com/sindresorhus/semver-regex/releases)
- [Commits](https://github.com/sindresorhus/semver-regex/commits)

---
updated-dependencies:
- dependency-name: semver-regex
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-22 13:31:04 +02:00
dependabot[bot] 92ec93fa37 chore: bump tmpl from 1.0.4 to 1.0.5 (#115)
Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/daaku/nodejs-tmpl/releases)
- [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5)

---
updated-dependencies:
- dependency-name: tmpl
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-22 13:30:53 +02:00
dependabot[bot] 5f5673ba77 chore: bump tar from 4.4.13 to 4.4.19 (#112)
Bumps [tar](https://github.com/npm/node-tar) from 4.4.13 to 4.4.19.
- [Release notes](https://github.com/npm/node-tar/releases)
- [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md)
- [Commits](https://github.com/npm/node-tar/compare/v4.4.13...v4.4.19)

---
updated-dependencies:
- dependency-name: tar
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-22 13:30:44 +02:00
Juwan Wheatley 1c8e5a21e9 docs: update expo.io links to expo.dev (#111) 2021-09-12 18:37:01 +02:00
Daniel Eriksson 3ba667b43f docs: update node version reference in readme (#107) 2021-08-23 21:26:26 +02:00
Nick f14253ea9c docs: fix unsplash comment on pr branch reference (#110) 2021-08-23 21:25:46 +02:00
Cedric van Putten a2d9b1cadf chore: clean up master references in release and workflows (#104)
* chore: update master to main branch in ci workflow

* chore: remove master branch check from release flow

* chore: remove master branch from release config
2021-06-22 21:17:28 +02:00
Matthew Ondash def44e2c77 docs: use main branch to update v{major} tag (#103) 2021-06-22 21:13:40 +02:00
semantic-release-bot c3c02de017 chore: create new release 6.0.0
## [6.0.0](https://github.com/expo/expo-github-action/compare/5.5.1...6.0.0) (2021-06-22)

### ⚠ BREAKING CHANGES

* Github Action inputs are changed to allow both Expo and EAS CLI.

### New features

* add support for eas cli installs ([#98](https://github.com/expo/expo-github-action/issues/98)) ([04692c3](https://github.com/expo/expo-github-action/commit/04692c3cb1f7ad977f62841ca0bb175c903f653f))

### Other chores

* update node to 14 and 16 in ci ([#100](https://github.com/expo/expo-github-action/issues/100)) ([a03876e](https://github.com/expo/expo-github-action/commit/a03876e3c556bea147f2be007eac911bf78c9b23))

### Documentation changes

* add commands to contirbuting guide for updating v{major} tags ([1b57c37](https://github.com/expo/expo-github-action/commit/1b57c37e9bdfe92e183befb3595debc64da672f0))
* update readme for v6 release ([#101](https://github.com/expo/expo-github-action/issues/101)) ([8b43bae](https://github.com/expo/expo-github-action/commit/8b43bae073f280d4fa76aa174642ad46febe985c))
* update upstream reference in contributing guide ([76ce4de](https://github.com/expo/expo-github-action/commit/76ce4de80ea89b343404cdabadc922882af80487))
2021-06-22 14:32:09 +00:00
Cedric van Putten 8b43bae073 docs: update readme for v6 release (#101)
* docs: update readme for v6 release

* docs: update all master references to main

* docs: update references to v6

* docs: fix link to eas build example
2021-06-22 16:27:07 +02:00
Cedric van Putten a03876e3c5 chore: update node to 14 and 16 in ci (#100) 2021-06-22 15:30:18 +02:00
Cedric van Putten 04692c3cb1 feature!: add support for eas cli installs (#98)
* feature!: add support for eas cli installs

* refactor: update the action metadata

* docs: update documentation to include eas examples

* fix: breaking change detection for semantic release

* docs: add notion about latest eas version

BREAKING CHANGE: Github Action inputs are changed to allow both Expo and EAS CLI.
2021-06-22 14:48:17 +02:00
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
47 changed files with 14783 additions and 163262 deletions

No files matched your search

+1 -9
View File
@@ -3,14 +3,6 @@ root = true
[*]
charset = utf-8
end_of_line = lf
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
indent_style = space
trim_trailing_whitespace = false
[*.yml]
indent_size = 2
indent_style = space
insert_final_newline = true
+14 -25
View File
@@ -1,27 +1,16 @@
module.exports = {
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
'jest',
],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': [
'error', { 'accessibility': 'no-public' },
],
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@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',
},
ignorePatterns: ['/build/**', 'node_modules/**'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest', 'prettier'],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'@typescript-eslint/no-var-requires': 'off',
'prettier/prettier': 'error',
},
};
+6
View File
@@ -0,0 +1,6 @@
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
# These files are text and should be normalized (Convert crlf => lf)
build/** text eol=lf
-55
View File
@@ -1,55 +0,0 @@
---
name: CI
on:
push:
branches: [master]
pull_request:
types: [opened, synchronize]
jobs:
build:
name: Test and build
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: [12, 14]
os:
- macos-latest
- ubuntu-latest
- windows-latest
include:
- node: 14
os: macos-latest
checkUpToDate: true
- node: 14
os: ubuntu-latest
checkUpToDate: true
steps:
- name: Setup repo
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Find cache
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Restore cache
uses: actions/cache@v2
with:
path: ${{ steps.yarn-cache-dir-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
if: ${{ matrix.checkUpToDate }}
run: git diff --stat --exit-code build
+25 -33
View File
@@ -1,51 +1,43 @@
---
name: Release
name: release
on:
workflow_dispatch:
inputs:
release:
description: 'type "release" to confirm creating a new release (main branch only)'
description: 'type "release" to create the release (main branch only)'
required: false
concurrency:
group: release
cancel-in-progress: true
env:
release: ${{ github.ref == 'refs/heads/main' && github.event.inputs.release == 'release' }}
jobs:
release:
name: Release version
runs-on: ubuntu-latest
steps:
- name: Setup repo
- name: 🏗 Setup repo
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
- name: 🏗 Setup Node
uses: actions/setup-node@v2
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
node-version: 16.x
cache: 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'
- name: 📋 Dry-running release
if: ${{ !env.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')
- name: 📋 Release code
if: ${{ env.release }}
run: yarn semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+56
View File
@@ -0,0 +1,56 @@
name: review
on:
push:
branches: [main]
pull_request:
types: [opened, synchronize]
concurrency:
group: review-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
strategy:
matrix:
node: [16.x]
runs-on: ubuntu-latest
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v2
- name: 🏗 Setup Node
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
cache: yarn
- name: 📦 Install dependencies
run: yarn install --frozen-lockfile --check-files
- name: ✅ Lint code
run: yarn lint
- name: 🧪 Test code
run: yarn test
- name: 👷 Build code
run: yarn clean && yarn build
- name: 🕵️ Validate build
id: diff
run: |
if [ "$(git diff --ignore-space-at-eol build/ | wc -l)" -gt "0" ]; then
echo "⚠️ Build is outdated"
echo " > run 'yarn clean', 'yarn build', and commit changes"
git diff
exit 1
fi
- name: 🗂 Upload build
uses: actions/upload-artifact@v2
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: build
path: build/
+45
View File
@@ -0,0 +1,45 @@
name: test
on:
push:
branches: [main]
workflow_dispatch:
concurrency:
group: test-${{ github.ref }}
cancel-in-progress: true
jobs:
setup:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: 🏗 Setup repo
uses: actions/checkout@v2
- name: 🏗 Setup Expo
uses: ./
with:
eas-version: latest
eas-cache: true
expo-version: latest
expo-cache: true
token: ${{ secrets.EXPO_TOKEN }}
- name: 🧪 EAS installed
run: eas --version
- name: 🧪 EAS authenticated
run: eas whoami
- name: 🧪 Expo installed
run: expo --version
- name: 🧪 Expo authenticated
run: expo whoami
+50
View File
@@ -1 +1,51 @@
# SWC
.swc/
# macOS
.DS_Store
# Node
node_modules
npm-debug.log
yarn-error.log
package-lock.json
# Ruby
.direnv
# Emacs
*~
# Vim
.*.swp
.*.swo
.*.swn
.*.swm
# Sublime Text
*.sublime-project
*.sublime-workspace
# Xcode
*.pbxuser
!default.pbxuser
*.xccheckout
*.xcscmblueprint
xcuserdata
# Android Studio
*.iml
.gradle
.idea/libraries
.idea/workspace.xml
.idea/gradle.xml
.idea/misc.xml
.idea/modules.xml
.idea/vcs.xml
# Eclipse
.project
.settings
# VSCode
.history/
-1
View File
@@ -1 +0,0 @@
_
-5
View File
@@ -1,5 +0,0 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
yarn build
git add build
+3 -2
View File
@@ -2,7 +2,8 @@
"printWidth": 120,
"tabWidth": 2,
"singleQuote": true,
"jsxBracketSameLine": true,
"bracketSameLine": true,
"trailingComma": "es5",
"arrowParens": "avoid"
"arrowParens": "avoid",
"endOfLine": "auto"
}
+7 -2
View File
@@ -11,12 +11,17 @@ const rules = [
const sortMap = Object.fromEntries(rules.map((rule, index) => [rule.title, index]));
module.exports = {
branches: ['main', 'master'],
branches: ['main'],
tagFormat: '${version}',
plugins: [
['@semantic-release/commit-analyzer', {
preset: 'conventionalcommits',
releaseRules: rules.map(({ type, release }) => ({ type, release })),
releaseRules: [
{ breaking: true, release: 'major' },
{ revert: true, release: 'patch' },
].concat(
rules.map(({ type, release, breaking }) => ({ type, release, breaking }))
),
}],
['@semantic-release/release-notes-generator', {
preset: 'conventionalcommits',
+11
View File
@@ -0,0 +1,11 @@
{
"jsc": {
"target": "es2020",
"parser": {
"syntax": "typescript"
}
},
"module": {
"type": "commonjs"
}
}
+30
View File
@@ -1,3 +1,33 @@
## [6.0.0](https://github.com/expo/expo-github-action/compare/5.5.1...6.0.0) (2021-06-22)
### ⚠ BREAKING CHANGES
* GitHub Action inputs are changed to allow both Expo and EAS CLI.
### New features
* add support for eas cli installs ([#98](https://github.com/expo/expo-github-action/issues/98)) ([04692c3](https://github.com/expo/expo-github-action/commit/04692c3cb1f7ad977f62841ca0bb175c903f653f))
### Other chores
* update node to 14 and 16 in ci ([#100](https://github.com/expo/expo-github-action/issues/100)) ([a03876e](https://github.com/expo/expo-github-action/commit/a03876e3c556bea147f2be007eac911bf78c9b23))
### Documentation changes
* add commands to contirbuting guide for updating v{major} tags ([1b57c37](https://github.com/expo/expo-github-action/commit/1b57c37e9bdfe92e183befb3595debc64da672f0))
* update readme for v6 release ([#101](https://github.com/expo/expo-github-action/issues/101)) ([8b43bae](https://github.com/expo/expo-github-action/commit/8b43bae073f280d4fa76aa174642ad46febe985c))
* update upstream reference in contributing guide ([76ce4de](https://github.com/expo/expo-github-action/commit/76ce4de80ea89b343404cdabadc922882af80487))
### [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)
+13 -6
View File
@@ -1,8 +1,8 @@
# Contributing to Expo Github Action
# 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/vscode-expo.git` 😉)
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/)
@@ -10,9 +10,9 @@
## 🏎️ 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:
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.
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
@@ -45,6 +45,13 @@ To get your PR merged as fast as possible, please make sure you have done the fo
## 🚀 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.
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.
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 main
$ git fetch --tags && git pull
$ git tag --force v{major}
$ git push --force --tags
```
+92 -61
View File
@@ -1,19 +1,17 @@
<div align="center">
<h1>expo github action</h1>
<p></p>
<p>Publish, build or manage your <a href="https://github.com/expo/expo">Expo</a> app with Github Actions!</p>
<sup>
<p>Publish, build or manage your <a href="https://github.com/expo/expo">Expo</a> app with GitHub Actions!</p>
<p>
<a href="https://github.com/expo/expo-github-action/releases">
<img src="https://img.shields.io/github/release/expo/expo-github-action/all.svg?style=flat-square" alt="releases" />
</a>
<a href="https://github.com/expo/expo-github-action/actions">
<img src="https://img.shields.io/github/workflow/status/expo/expo-github-action/CI/master.svg?style=flat-square" alt="builds" />
<img src="https://img.shields.io/github/workflow/status/expo/expo-github-action/CI/main.svg?style=flat-square" alt="builds" />
</a>
<a href="https://github.com/expo/expo-github-action/blob/master/LICENSE.md">
<a href="https://github.com/expo/expo-github-action/blob/main/LICENSE.md">
<img src="https://img.shields.io/github/license/expo/expo-github-action?style=flat-square" alt="license" />
</a>
</sup>
<br />
</p>
<p align="center">
<a href="https://github.com/expo/expo-github-action#configuration-options"><b>Usage</b></a>
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
@@ -21,14 +19,13 @@
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
<a href="https://github.com/expo/expo-github-action#things-to-know"><b>Caveats</b></a>
&nbsp;&nbsp;&mdash;&nbsp;&nbsp;
<a href="https://github.com/expo/expo-github-action/blob/master/CHANGELOG.md"><b>Changelog</b></a>
<a href="https://github.com/expo/expo-github-action/blob/main/CHANGELOG.md"><b>Changelog</b></a>
</p>
<br />
</div>
## What's inside?
With this Expo action, you have full access to the [Expo CLI][link-expo-cli] itself.
With this Expo action, you have full access to [Expo CLI][link-expo-cli] and [EAS CLI][link-eas-cli] itself.
It allows you to fully automate the `expo publish` or `expo build` process, leaving you with more time available for your project.
There are some additional features included to make the usage of this action as simple as possible, like caching and authentication.
@@ -37,59 +34,62 @@ There are some additional features included to make the usage of this action as
This action is customizable through variables; they are defined in the [`action.yml`](action.yml).
Here is a summary of all the variables that you can use and their purpose.
variable | 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`)_
`expo-cache` | `false` | If it should use the [GitHub actions (remote) cache](#using-the-built-in-cache).
`expo-cache-key` | - | An optional custom (remote) cache key. _(**use with caution**)_
`expo-patch-watchers` | `true` | If it should [patch the `fs.inotify.` limits](#enospc-errors-on-linux).
| variable | default | description |
| ---------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `expo-version` | - | [Expo CLI](https://github.com/expo/expo-cli) version to install, skips when omitted. |
| `expo-cache` | `false` | If it should use the [GitHub actions (remote) cache](#using-the-built-in-cache). |
| `expo-cache-key` | - | An optional custom (remote) cache key. _(**use with caution**)_ |
| `eas-version` | - | [EAS CLI](https://github.com/expo/eas-cli) version to install, skips when omitted. (`latest` is recommended) |
| `eas-cache` | `false` | If it should use the [GitHub actions (remote) cache](#using-the-built-in-cache). |
| `eas-cache-key` | - | An optional custom (remote) cache key. _(**use with caution**)_ |
| `packager` | `yarn` | The package manager to use. _(e.g. `npm`)_ |
| `token` | - | The token of your Expo account _(e.g. [`${{ secrets.EXPO_TOKEN }}`][link-actions-secrets])_ |
| `username` | - | The username of your Expo account _(e.g. `bycedric`)_ |
| `password` | - | The password of your Expo account _(e.g. [`${{ secrets.EXPO_CLI_PASSWORD }}`][link-actions-secrets])_ |
| `patch-watchers` | `true` | If it should [patch the `fs.inotify.` limits](#enospc-errors-on-linux). |
> 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.
> Using `latest` for `eas-version` is recommened, you should always have the latest version of this CLI installed.
## Example workflows
Before you dive into the workflow examples, you should know the basics of GitHub Actions.
You can read more about this in the [GitHub Actions documentation][link-actions].
1. [Publish on any push to master](#publish-on-any-push-to-master)
1. [Publish on any push to main](#publish-on-any-push-to-main)
2. [Cache Expo CLI for other jobs](#cache-expo-cli-for-other-jobs)
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)
3. [Creating a new EAS build](#creating-a-new-eas-build)
4. [Test PRs and publish a review version](#test-prs-and-publish-a-review-version)
5. [Test PRs on multiple nodes and systems](#test-prs-on-multiple-nodes-and-systems)
6. [Test and build web every day at 08:00](#test-and-build-web-every-day-at-0800)
7. [Authenticate using credentials](#authenticate-using-credentials)
### Publish on any push to master
### Publish on any push to main
Below you can see the example configuration to publish whenever the master branch is updated.
The workflow listens to the `push` event and sets up Node 12 using the [Setup Node Action][link-actions-node].
It also authenticates the Expo project by defining both `expo-username` and `expo-password`.
Below you can see the example configuration to publish whenever the main branch is updated.
The workflow listens to the `push` event and sets up Node 14 using the [Setup Node Action][link-actions-node].
It also auto-authenticates when the `token` is provided.
```yml
name: Expo Publish
on:
push:
branches:
- master
- main
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
token: ${{ secrets.EXPO_TOKEN }}
- run: yarn install
- run: expo publish
```
@@ -107,26 +107,56 @@ name: Expo Publish
on:
push:
branches:
- master
- main
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
expo-cache: true
token: ${{ secrets.EXPO_TOKEN }}
- run: yarn install
- run: expo publish
```
### Creating a new EAS build
You can also install [EAS](https://docs.expo.dev/eas/) CLI with this GitHub Action.
Below we've swapped `expo-version` with `eas-version`, but you can also use them together.
Both the `token` and `username`/`password` is shared between both Expo and EAS CLI.
> We recommend using `latest` for `eas-version` to always have the most up-to-date version.
```yml
name: EAS build
on:
push:
branches:
- main
jobs:
build:
name: Create new build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v6
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- run: yarn install
- run: eas build
```
### Test PRs and publish a review version
Reviewing pull requests can take some time if you have to read every line of code.
@@ -142,21 +172,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
expo-username: ${{ secrets.EXPO_CLI_USERNAME }}
expo-password: ${{ secrets.EXPO_CLI_PASSWORD }}
token: ${{ secrets.EXPO_TOKEN }}
- run: yarn install
- run: expo publish --release-channel=pr-${{ github.event.number }}
- uses: unsplash/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
msg: App is ready for review, you can [see it here](https://expo.io/@bycedric/use-expo?release-channel=pr-${{ github.event.number }}).
msg: App is ready for review, you can [see it here](https://expo.dev/@bycedric/use-expo?release-channel=pr-${{ github.event.number }}).
```
### Test PRs on multiple nodes and systems
@@ -164,7 +193,7 @@ jobs:
With GitHub Actions, it's reasonably easy to set up a matrix build and test the app on multiple environments.
These matrixes can help to make sure your app runs smoothly on a broad set of different development machines.
> If you don't need automatic authentication, you can omit the `expo-username` and `expo-password` variables.
> If you don't need automatic authentication, you can omit the `token` variables.
```yml
name: Expo CI
@@ -179,10 +208,10 @@ jobs:
node: [10, 12, 13]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
- run: yarn install
@@ -206,10 +235,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
- run: yarn install
@@ -217,30 +246,31 @@ jobs:
- run: expo build:web
```
### Authenticate using an Expo token
### Authenticate using credentials
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.
Instead of using an access token, you can also authenticate using credentials.
This is only possible when Expo CLI is installed.
```yml
name: Expo Publish
on:
push:
branches:
- master
- main
jobs:
publish:
name: Install and publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14.x
- uses: expo/expo-github-action@v5
- uses: expo/expo-github-action@v6
with:
expo-version: 4.x
expo-token: ${{ secrets.EXPO_TOKEN }}
username: ${{ secrets.EXPO_CLI_USERNAME }}
password: ${{ secrets.EXPO_CLI_PASSWORD }}
- run: yarn install
- run: expo publish
```
@@ -263,7 +293,7 @@ Under the hood, it uses the [`@action/cache`][link-actions-cache-package] packag
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].
> Note, this cache will count towards your [repo cache limit][link-actions-cache-limit]. The Expo and EAS CLI are stored in different caches.
### ENOSPC errors on Linux
@@ -272,7 +302,7 @@ Creating these bundles require quite some resources.
As of writing, GitHub actions has some small default values for the `fs.inotify` settings.
Inside this action, we included a patch that increases these limits for the current workflow.
It increases the `max_user_instances`, `max_user_watches` and `max_queued_events` to `524288`.
You can disable this patch by setting the `expo-patch-watchers` to `false`.
You can disable this patch by setting the `patch-watchers` to `false`.
<div align="center">
<br />
@@ -285,7 +315,8 @@ You can disable this patch by setting the `expo-patch-watchers` to `false`.
[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/
[link-expo-cli]: https://docs.expo.dev/workflow/expo-cli/
[link-expo-cli-password]: https://github.com/expo/expo-cli/blob/master/packages/expo-cli/src/accounts.ts#L88-L90
[link-expo-release-channels]: https://docs.expo.io/distribution/release-channels/
[link-expo-release-channels]: https://docs.expo.dev/distribution/release-channels/
[link-eas-cli]: https://github.com/expo/eas-cli#readme
[link-semver-playground]: https://semver.npmjs.com/
+24 -18
View File
@@ -6,26 +6,32 @@ branding:
icon: terminal
color: gray-dark
runs:
using: node14
main: build/index.js
using: node16
main: build/setup.js
inputs:
expo-version:
description: The Expo CLI version to install. (use any semver/dist-tag available)
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:
description: The package manager used to install the Expo CLI. (can be yarn or npm)
default: yarn
expo-patch-watchers:
description: If Expo should fix the default watchers limit, helps with ENOSPC errors. (can be true or false)
default: true
description: The Expo CLI version to install (use any semver/dist-tag available).
expo-cache:
description: If Expo should be stored in the GitHub Actions cache (can be true or false)
description: If Expo CLI should be stored in the GitHub Actions cache.
default: false
expo-cache-key:
description: A custom remote cache key to use (best to let GitHub Actions handle it)
description: A custom remote cache key to use for Expo CLI.
eas-version:
description: The EAS CLI version to install (use any semver/dist-tag available).
eas-cache:
description: If EAS CLI should be stored in the GitHub Actions cache.
default: false
eas-cache-key:
description: A custom remote cache key to use for EAS CLI.
username:
description: Your Expo username, for authentication.
token:
description: Your Expo token, for authentication. (use with secrets)
password:
description: Your Expo password, for authentication. (use with secrets)
packager:
description: The package manager used to install the Expo CLI. (can be yarn or npm)
default: yarn
patch-watchers:
description: If Expo should fix the default watchers limit, helps with ENOSPC errors. (can be true or false)
default: true
-24
View File
@@ -1,24 +0,0 @@
if (module !== require.main) {
throw new Error("This file should not be loaded with require()")
}
if (!process.getuid || !process.getgid) {
throw new Error("this file should not be called without uid/gid support")
}
var argv = process.argv.slice(2)
, user = argv[0] || process.getuid()
, group = argv[1] || process.getgid()
if (!isNaN(user)) user = +user
if (!isNaN(group)) group = +group
console.error([user, group])
try {
process.setgid(group)
process.setuid(user)
console.log(JSON.stringify({uid:+process.getuid(), gid:+process.getgid()}))
} catch (ex) {
console.log(JSON.stringify({error:ex.message,errno:ex.errno}))
}
-160107
View File
File diff suppressed because it is too large. Load diff
-47
View File
@@ -1,47 +0,0 @@
'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
@@ -1,7 +0,0 @@
{
"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
@@ -1,49 +0,0 @@
'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
@@ -1,6 +0,0 @@
{
"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"
}
-47
View File
@@ -1,47 +0,0 @@
'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
@@ -1,7 +0,0 @@
{
"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
@@ -1,49 +0,0 @@
'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
@@ -1,6 +0,0 @@
{
"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"
}
+12574
View File
File diff suppressed because it is too large. Load diff
+10 -9
View File
@@ -1,11 +1,12 @@
/** @type {import('@jest/types').Config.InitialOptions} */
module.exports = {
verbose: true,
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
},
};
+53 -52
View File
@@ -1,54 +1,55 @@
{
"private": true,
"name": "expo-github-action",
"version": "5.5.0",
"description": "Expo CLI in your GitHub Actions workflow",
"main": "build/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo-github-action.git"
},
"author": "Cedric van Putten <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo-github-action/issues"
},
"homepage": "https://github.com/expo/expo-github-action#readme",
"scripts": {
"test": "jest",
"lint": "tsc --noEmit && eslint --ext ts ./src ./tests",
"build": "ncc build src/index.ts --out build",
"clean": "rimraf build",
"prepare": "husky install"
},
"dependencies": {
"@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": {
"@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",
"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",
"semantic-release": "^17.4.4",
"ts-jest": "^27.0.3",
"typescript": "^4.3.3"
}
"private": true,
"name": "expo-github-action",
"version": "6.0.0",
"description": "Expo CLI in your GitHub Actions workflow",
"main": "build/index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/expo/expo-github-action.git"
},
"author": "Cedric van Putten <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/expo/expo-github-action/issues"
},
"homepage": "https://github.com/expo/expo-github-action#readme",
"scripts": {
"test": "jest",
"lint": "tsc --noEmit && eslint .",
"build": "spack && rimraf build/*.map",
"clean": "rimraf build .swc"
},
"dependencies": {
"@actions/cache": "^1.0.7",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1",
"semver": "^7.3.5"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@swc/cli": "^0.1.55",
"@swc/core": "^1.2.128",
"@tsconfig/node16": "^1.0.2",
"@types/jest": "^27.0.2",
"@types/node": "^16.11.19",
"@types/semver": "^7.3.6",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^8.2.0",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"jest-circus": "^27.3.1",
"prettier": "^2.4.1",
"regenerator-runtime": "^0.13.9",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.4",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
}
}
+40
View File
@@ -0,0 +1,40 @@
const { config } = require('@swc/core/spack');
const { readdirSync } = require('fs');
const { resolve, basename, extname } = require('path');
module.exports = config({
target: 'node',
entry: actions(resolve(__dirname, 'src/actions')),
output: {
path: resolve(__dirname, 'build'),
},
externalModules: externals(),
});
/**
* Get all action entry points, in src/actions.
* This returns them as `{ [name]: absolutePath }`.
*/
function actions(dir) {
return Object.fromEntries(
readdirSync(dir, { withFileTypes: true })
.filter(entity => entity.isFile())
.map(entity => {
const actionName = basename(entity.name, extname(entity.name));
const actionFile = resolve(dir, entity.name);
return [actionName, actionFile];
})
);
}
/**
* Get all external modules that should not be bundled.
*
* Note, currently `@actions/cache` can't be bundled by SWC due to modules issues in `@azure/*`:
* > internal error: entered unreachable code: module item found but is_es6 is false
*
* @see https://github.com/expo/expo-github-action/pull/62
*/
function externals() {
return ['@azure/storage-blob', '@azure/ms-rest-js'];
}
+61
View File
@@ -0,0 +1,61 @@
import { addPath, getBooleanInput, getInput, group, info } from '@actions/core';
import { install } from '../install';
import { resolveVersion } from '../packager';
import * as tools from '../tools';
// Auto-execute in GitHub actions
tools.performAction(setupAction);
export async function setupAction(): Promise<void> {
const expoVersion = await installCli('expo-cli');
const easVersion = await installCli('eas-cli');
await group('Checking current authenticated account', () =>
tools.maybeAuthenticate({
cli: expoVersion ? 'expo-cli' : easVersion ? 'eas-cli' : undefined,
token: getInput('token') || undefined,
username: getInput('username') || undefined,
password: getInput('password') || undefined,
})
);
if (!getInput('patch-watchers') || getBooleanInput('patch-watchers') !== false) {
await group('Patching system watchers for the `ENOSPC` error', () => tools.maybePatchWatchers());
}
}
async function installCli(name: tools.PackageName): Promise<string | void> {
const shortName = tools.getBinaryName(name);
const inputVersion = getInput(`${shortName}-version`);
const packager = getInput('packager') || 'yarn';
if (!inputVersion) {
return info(`Skipping installation of ${name}, \`${shortName}-version\` not provided.`);
}
const version = await resolveVersion(name, inputVersion);
const cache = getBooleanInput(`${shortName}-cache`);
try {
const path = await group(
cache
? `Installing ${name} (${version}) from cache or with ${packager}`
: `Installing ${name} (${version}) with ${packager}`,
() =>
install({
packager,
version,
cache,
package: name,
cacheKey: getInput(`${shortName}-cache-key`) || undefined,
})
);
addPath(path);
} catch (error) {
tools.handleError(name, error);
}
return version;
}
+42 -40
View File
@@ -4,14 +4,18 @@ import * as toolCache from '@actions/tool-cache';
import path from 'path';
import os from 'os';
import type { InstallConfig } from './install';
export type CacheConfig = Omit<InstallConfig, 'cache'>;
/**
* Get the path to the `expo-cli` from cache, if any.
* Note, this cache is **NOT** shared between jobs.
*
* @see https://github.com/actions/toolkit/issues/47
*/
export async function fromLocalCache(version: string): Promise<string | undefined> {
return toolCache.find('expo-cli', version);
export async function fromLocalCache(config: CacheConfig): Promise<string | undefined> {
return toolCache.find(config.package, config.version);
}
/**
@@ -20,53 +24,53 @@ export async function fromLocalCache(version: string): Promise<string | undefine
*
* @see https://github.com/actions/toolkit/issues/47
*/
export async function toLocalCache(root: string, version: string): Promise<string> {
return toolCache.cacheDir(root, 'expo-cli', version);
export async function toLocalCache(root: string, config: CacheConfig): Promise<string> {
return toolCache.cacheDir(root, config.package, config.version);
}
/**
* 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): 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);
export async function fromRemoteCache(config: CacheConfig): 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'] || '', config.package, config.version, os.arch());
const cacheKey = config.cacheKey || getRemoteKey(config);
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;
}
}
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;
}
}
}
/**
* 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): Promise<void> {
const cacheKey = customCacheKey || getRemoteKey(version, packager);
export async function toRemoteCache(source: string, config: CacheConfig): Promise<void> {
const cacheKey = config.cacheKey || getRemoteKey(config);
try {
await saveCache([source], cacheKey);
} catch (error) {
if (!handleRemoteCacheError(error)) {
throw error;
}
}
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): string {
return `expo-cli-${process.platform}-${os.arch()}-${packager}-${version}`;
function getRemoteKey(config: Omit<CacheConfig, 'cacheKey'>): string {
return `${config.package}-${process.platform}-${os.arch()}-${config.packager}-${config.version}`;
}
/**
@@ -77,16 +81,14 @@ function getRemoteKey(version: string, packager: string): string {
* @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',
);
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;
}
if (isReserveCacheError || isCacheUnavailable) {
core.warning('Skipping remote cache storage, encountered error:');
core.warning(error.message);
return true;
}
return false;
return false;
}
-4
View File
@@ -1,4 +0,0 @@
import { run } from './run';
import { handleError } from './tools';
run().catch(handleError);
+31 -24
View File
@@ -4,12 +4,19 @@ import * as io from '@actions/io';
import * as path from 'path';
import { fromLocalCache, fromRemoteCache, toLocalCache, toRemoteCache } from './cache';
import { PackageName } from './tools';
export type InstallConfig = {
version: string;
packager: string;
cache?: boolean;
cacheKey?: string;
/** The exact version to install */
version: string;
/** The name of the package to install */
package: PackageName;
/** The packager to install with, likely to be `yarn` or `npm` */
packager: string;
/** If remote caching is enabled or not */
cache?: boolean;
/** The custom remote cache key */
cacheKey?: string;
};
/**
@@ -18,36 +25,36 @@ export type InstallConfig = {
* It returns the path where Expo is installed.
*/
export async function install(config: InstallConfig): Promise<string> {
let root: string | undefined = await fromLocalCache(config.version);
let root: string | undefined = await fromLocalCache(config);
if (!root && config.cache) {
root = await fromRemoteCache(config.version, config.packager, config.cacheKey);
} else {
core.info('Skipping remote cache, not enabled...');
}
if (!root && config.cache) {
root = await fromRemoteCache(config);
} else {
core.info('Skipping remote cache, not enabled...');
}
if (!root) {
root = await fromPackager(config.version, config.packager);
root = await toLocalCache(root, config.version);
if (!root) {
root = await fromPackager(config);
root = await toLocalCache(root, config);
if (config.cache) {
await toRemoteCache(root, config.version, config.packager, config.cacheKey);
}
}
if (config.cache) {
await toRemoteCache(root, config);
}
}
return path.join(root, 'node_modules', '.bin');
return path.join(root, 'node_modules', '.bin');
}
/**
* 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): Promise<string> {
const root = process.env['RUNNER_TEMP'] || '';
const tool = await io.which(packager);
export async function fromPackager(config: InstallConfig): Promise<string> {
const root = process.env['RUNNER_TEMP'] || '';
const tool = await io.which(config.packager);
await io.mkdirP(root);
await cli.exec(tool, ['add', `expo-cli@${version}`], { cwd: root });
await io.mkdirP(root);
await cli.exec(tool, ['add', `${config.package}@${config.version}`], { cwd: root });
return root;
return root;
}
+30
View File
@@ -0,0 +1,30 @@
import { exec } from '@actions/exec';
/**
* Resolve a package with version range to an exact version.
* This is useful to invalidate the cache _and_ using dist-tags or version ranges.
* It executes `npm info` and parses the latest manifest.
*/
export async function resolveVersion(name: string, range: string): Promise<string> {
let stdout = '';
try {
await exec('npm', ['info', `${name}@${range}`, 'version', '--json'], {
silent: true,
listeners: {
stdout(data) {
stdout += data.toString();
},
},
});
} catch (error) {
throw new Error(`Could not resolve version "${range}" of "${name}", reason:\n${error.message || error}`);
}
// thanks npm, for returning a "x.x.x" json value...
if (stdout.startsWith('"')) {
stdout = `[${stdout}]`;
}
return JSON.parse(stdout).at(-1);
}
-43
View File
@@ -1,43 +0,0 @@
import { addPath, getInput, group } from '@actions/core';
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 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 group(
'Patching system watchers for the `ENOSPC` error',
() => maybePatchWatchers(),
);
}
}
+85 -57
View File
@@ -2,22 +2,24 @@ 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');
import { resolveVersion } from './packager';
type AuthenticateOptions = {
token?: string;
username?: string;
password?: string;
export type PackageName = 'expo-cli' | 'eas-cli';
export type AuthenticateOptions = {
cli?: PackageName;
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`.
* Convert `expo-cli` or `eas-cli` to just their binary name.
* For windows we have to use `<bin>.cmd`, toolkit will handle the Windows binary with that.
*/
export async function resolveVersion(version: string): Promise<string> {
return (await registry.manifest(`expo-cli@${version}`)).version;
export function getBinaryName(name: PackageName, forWindows = false): string {
const bin = name.toLowerCase().replace('-cli', '');
return forWindows ? `${bin}.cmd` : bin;
}
/**
@@ -25,27 +27,37 @@ export async function resolveVersion(version: string): Promise<string> {
* 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) {
if (options.cli) {
const bin = getBinaryName(options.cli, process.platform === 'win32');
await cli.exec(bin, ['whoami'], {
env: { ...process.env, EXPO_TOKEN: options.token },
});
} else {
core.info("Skipping token validation: no CLI installed, can't run `whoami`.");
}
if (options.token) {
await cli.exec(bin, ['whoami'], {
env: { ...process.env, EXPO_TOKEN: options.token },
});
return core.exportVariable('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;
}
if (options.username || options.password) {
if (options.cli !== 'expo-cli') {
return core.warning(
'Skipping authentication: only Expo CLI supports programmatic credentials, use `token` instead.'
);
}
core.info('Skipping authentication: `expo-token`, `expo-username`, and/or `expo-password` not set...');
if (!options.username || !options.password) {
return core.info('Skipping authentication: `username` and/or `password` not set...');
}
const bin = getBinaryName(options.cli, process.platform === 'win32');
await cli.exec(bin, ['login', `--username=${options.username}`], {
env: { ...process.env, EXPO_CLI_PASSWORD: options.password },
});
}
core.info('Skipping authentication: `token`, `username`, and/or `password` not set...');
}
/**
@@ -56,22 +68,22 @@ export async function maybeAuthenticate(options: AuthenticateOptions = {}): Prom
* @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...');
}
if (process.platform !== 'linux') {
return core.info('Skipping patch for watchers, not running on Linux...');
}
core.info('Patching system watchers for the `ENOSPC` error...');
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');
}
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');
}
}
/**
@@ -79,26 +91,42 @@ export async function maybePatchWatchers(): Promise<void> {
* 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');
export async function maybeWarnForUpdate(name: PackageName): Promise<void> {
const binaryName = getBinaryName(name);
const latest = await resolveVersion(name, 'latest');
const current = await resolveVersion(name, core.getInput(`${getBinaryName(name)}-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"`);
}
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 "${binaryName}-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
}
export async function handleError(name: PackageName, error: Error) {
try {
await maybeWarnForUpdate(name);
} catch {
// If this fails, ignore it
}
core.setFailed(error);
core.setFailed(error);
}
/**
* Auto-execute the action if it's not running in a test environment.
* This is useful to test the action, without running it in tests.
* The method can also be mocked.
*/
export function performAction(action: () => Promise<void>) {
if (process.env.JEST_WORKER_ID) {
return Promise.resolve(null);
}
return action();
}
+132
View File
@@ -0,0 +1,132 @@
import { getToolsMock, mockInput } from '../utils';
jest.mock('../../src/tools', () => getToolsMock());
jest.mock('../../src/packager', () => ({
async resolveVersion(_: string, version: string) {
return version;
},
}));
import * as core from '@actions/core';
import * as install from '../../src/install';
import * as tools from '../../src/tools';
import { setupAction } from '../../src/actions/setup';
describe(setupAction, () => {
describe('patch watchers', () => {
it('patches the system when set to true', async () => {
mockInput({ 'patch-watchers': 'true' });
await setupAction();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('patches the system when not set', async () => {
mockInput({ 'patch-watchers': '' });
await setupAction();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('skips the system patch when set to false', async () => {
mockInput({ 'patch-watchers': 'false' });
await setupAction();
expect(tools.maybePatchWatchers).not.toHaveBeenCalled();
});
});
describe('authentication', () => {
it('authenticates with provided credentials', async () => {
mockInput({ username: 'bycedric', password: 'mypassword' });
await setupAction();
expect(tools.maybeAuthenticate).toBeCalledWith({ username: 'bycedric', password: 'mypassword' });
});
it('authenticates with provided token', async () => {
mockInput({ token: 'ABC123' });
await setupAction();
expect(tools.maybeAuthenticate).toBeCalledWith({ token: 'ABC123' });
});
});
['expo', 'eas'].forEach(cliName => {
const packageName = `${cliName}-cli`;
let installMock: jest.SpyInstance;
beforeEach(() => {
installMock = jest.spyOn(install, 'install').mockImplementation();
});
afterEach(() => {
installMock.mockRestore();
});
describe(packageName, () => {
it(`skips installation without \`${cliName}-version\``, async () => {
mockInput();
await setupAction();
expect(installMock).not.toBeCalledWith({ package: packageName });
});
it('installs with yarn by default', async () => {
mockInput({ [`${cliName}-version`]: 'latest' });
await setupAction();
expect(installMock).toBeCalledWith({
package: packageName,
version: 'latest',
packager: 'yarn',
cache: false,
});
});
it('installs provided version with npm', async () => {
mockInput({ [`${cliName}-version`]: '3.0.10', packager: 'npm' });
await setupAction();
expect(installMock).toBeCalledWith({
package: packageName,
version: '3.0.10',
packager: 'npm',
cache: false,
});
});
it('installs with yarn and cache enabled', async () => {
mockInput({
packager: 'yarn',
[`${cliName}-version`]: '4.2.0',
[`${cliName}-cache`]: 'true',
});
await setupAction();
expect(installMock).toBeCalledWith({
package: packageName,
version: '4.2.0',
packager: 'yarn',
cache: true,
});
});
it('installs with yarn and custom cache key', async () => {
mockInput({
packager: 'yarn',
[`${cliName}-version`]: '4.2.0',
[`${cliName}-cache`]: 'true',
[`${cliName}-cache-key`]: 'custom-key',
});
await setupAction();
expect(installMock).toBeCalledWith({
package: packageName,
version: '4.2.0',
packager: 'yarn',
cache: true,
cacheKey: 'custom-key',
});
});
it('installs path to global path', async () => {
installMock.mockResolvedValue(`/${cliName}/install/path`);
const addPathSpy = jest.spyOn(core, 'addPath').mockImplementation();
await setupAction();
expect(addPathSpy).toBeCalledWith(`/${cliName}/install/path`);
});
});
});
});
+123 -101
View File
@@ -7,125 +7,147 @@ import * as toolCache from '@actions/tool-cache';
import * as cache from '../src/cache';
import * as utils from './utils';
describe('fromLocalCache', () => {
it('fetches the version specific cache', async () => {
const path = join('path', 'to', 'local', 'cache');
// todo: check why jest wants `never` instead of `string`
const find = jest.spyOn(toolCache, 'find').mockResolvedValue(path as never);
const result = await cache.fromLocalCache('3.20.1');
expect(result).toBe(path);
expect(find).toBeCalledWith('expo-cli', '3.20.1');
});
describe(cache.fromLocalCache, () => {
it('fetches the version specific cache', async () => {
const path = join('path', 'to', 'local', 'cache');
// todo: check why jest wants `never` instead of `string`
const find = jest.spyOn(toolCache, 'find').mockResolvedValue(path as never);
const result = await cache.fromLocalCache({ package: 'eas-cli', version: '4.2.0', packager: 'npm' });
expect(result).toBe(path);
expect(find).toBeCalledWith('eas-cli', '4.2.0');
});
});
describe('toLocalCache', () => {
it('stores the version specific cache', async () => {
const path = join('path', 'to', 'local', 'cache');
const root = join('path', 'from', 'source');
const cacheDir = jest.spyOn(toolCache, 'cacheDir').mockResolvedValue(path);
const result = await cache.toLocalCache(root, '3.20.1');
expect(result).toBe(path);
expect(cacheDir).toBeCalledWith(root, 'expo-cli', '3.20.1');
});
describe(cache.toLocalCache, () => {
it('stores the version specific cache', async () => {
const path = join('path', 'to', 'local', 'cache');
const root = join('path', 'from', 'source');
const cacheDir = jest.spyOn(toolCache, 'cacheDir').mockResolvedValue(path);
const result = await cache.toLocalCache(root, { package: 'expo-cli', version: '4.2.0', packager: 'yarn' });
expect(result).toBe(path);
expect(cacheDir).toBeCalledWith(root, 'expo-cli', '4.2.0');
});
});
describe('fromRemoteCache', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
describe(cache.fromRemoteCache, () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});
beforeEach(() => {
spy = {
restore: jest.spyOn(remoteCache, 'restoreCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});
beforeAll(() => {
utils.setEnv('RUNNER_TOOL_CACHE', join('cache', 'path'));
});
beforeAll(() => {
utils.setEnv('RUNNER_TOOL_CACHE', join('cache', 'path'));
});
afterAll(() => {
utils.restoreEnv();
spy.restore.mockRestore();
spy.warning.mockRestore();
});
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`,
);
});
it('restores remote cache with default key', async () => {
expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: '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`
);
});
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',
);
});
it('restores remote cache with custom key', async () => {
expect(
await cache.fromRemoteCache({
package: 'eas-cli',
version: '4.2.0',
packager: 'yarn',
cacheKey: 'custom-cache-key',
})
).toBeUndefined();
expect(remoteCache.restoreCache).toBeCalledWith(
[join('cache', 'path', 'eas-cli', '4.2.0', os.arch())],
'custom-cache-key'
);
});
it('returns path when remote cache exists', async () => {
spy.restore.mockResolvedValueOnce(true);
await expect(cache.fromRemoteCache('3.20.1', 'npm')).resolves.toBe(
join('cache', 'path', 'expo-cli', '3.20.1', os.arch())
);
});
it('returns path when remote cache exists', async () => {
spy.restore.mockResolvedValueOnce(true);
expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: 'npm' })).toBe(
join('cache', 'path', 'expo-cli', '3.20.1', os.arch())
);
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache restore failed');
spy.restore.mockRejectedValueOnce(error);
await expect(cache.fromRemoteCache('3.20.1', 'yarn')).rejects.toBe(error);
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache restore failed');
spy.restore.mockRejectedValueOnce(error);
await expect(cache.fromRemoteCache({ package: 'eas-cli', version: '3.20.1', packager: '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'));
});
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);
expect(await cache.fromRemoteCache({ package: 'expo-cli', version: '3.20.1', packager: 'yarn' })).toBeUndefined();
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
});
});
describe('toRemoteCache', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
describe(cache.toRemoteCache, () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = {
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});
beforeEach(() => {
spy = {
save: jest.spyOn(remoteCache, 'saveCache').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});
afterAll(() => {
spy.save.mockRestore();
spy.warning.mockRestore();
});
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`
);
});
it('saves remote cache with default key', async () => {
expect(
await cache.toRemoteCache(join('local', 'path'), { package: 'eas-cli', version: '3.20.1', packager: 'npm' })
).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith(
[join('local', 'path')],
`eas-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');
});
it('saves remote cache with custom key', async () => {
expect(
await cache.toRemoteCache(join('local', 'path'), {
package: 'eas-cli',
version: '3.20.1',
packager: 'yarn',
cacheKey: 'custom-cache-key',
})
).toBeUndefined();
expect(remoteCache.saveCache).toBeCalledWith([join('local', 'path')], 'custom-cache-key');
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache save failed');
spy.save.mockRejectedValueOnce(error);
await expect(cache.toRemoteCache(join('local', 'path'), '3.20.1', 'yarn')).rejects.toBe(error);
});
it('fails when remote cache throws', async () => {
const error = new Error('Remote cache save failed');
spy.save.mockRejectedValueOnce(error);
await expect(
cache.toRemoteCache(join('local', 'path'), { package: 'expo-cli', version: '3.20.1', packager: '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'));
});
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'), { package: 'expo-cli', version: '3.20.1', packager: 'yarn' })
).resolves.toBeUndefined();
expect(spy.warning).toHaveBeenCalledWith(expect.stringContaining('Skipping remote cache'));
});
});
+70 -56
View File
@@ -1,10 +1,10 @@
const cli = { exec: jest.fn() };
const io = { mkdirP: jest.fn(), which: jest.fn() };
const cache = {
fromLocalCache: jest.fn(),
fromRemoteCache: jest.fn(),
toLocalCache: jest.fn(),
toRemoteCache: jest.fn(),
fromLocalCache: jest.fn(),
fromRemoteCache: jest.fn(),
toLocalCache: jest.fn(),
toRemoteCache: jest.fn(),
};
jest.mock('@actions/exec', () => cli);
@@ -17,64 +17,78 @@ import * as install from '../src/install';
import * as utils from './utils';
describe('install', () => {
it('installs path from local cache', async () => {
cache.fromLocalCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
});
it('installs path from local cache', async () => {
cache.fromLocalCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ package: 'expo-cli', version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
});
it('installs path from packager and cache it locally', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
cache.fromLocalCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.toLocalCache).toBeCalledWith(join('temp', 'path'), '3.0.10');
utils.restoreEnv();
});
it('installs path from packager and cache it locally', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
cache.fromLocalCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ package: 'expo-cli', version: '3.0.10', packager: 'npm' });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.toLocalCache).toBeCalledWith(join('temp', 'path'), {
package: 'expo-cli',
version: '3.0.10',
packager: 'npm',
});
utils.restoreEnv();
});
it('installs path from remote cache', async () => {
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(join('cache', 'path'));
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.1', 'npm', undefined);
});
it('installs path from remote cache', async () => {
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ package: 'eas-cli', version: '4.2.0', packager: 'yarn', cache: true });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.fromRemoteCache).toBeCalledWith({
package: 'eas-cli',
version: '4.2.0',
packager: 'yarn',
cache: true,
});
});
it('installs path from packager and cache it remotely', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue(join('cache', 'path'));
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);
utils.restoreEnv();
});
it('installs path from packager and cache it remotely', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
cache.fromLocalCache.mockResolvedValue(undefined);
cache.fromRemoteCache.mockResolvedValue(undefined);
cache.toLocalCache.mockResolvedValue(join('cache', 'path'));
const expoPath = await install.install({ package: 'expo-cli', version: '3.20.1', packager: 'npm', cache: true });
expect(expoPath).toBe(join('cache', 'path', 'node_modules', '.bin'));
expect(cache.toRemoteCache).toBeCalledWith(join('cache', 'path'), {
package: 'expo-cli',
version: '3.20.1',
packager: 'npm',
cache: true,
});
utils.restoreEnv();
});
});
describe('fromPackager', () => {
it('resolves tool path', async () => {
await install.fromPackager('3.0.10', 'npm');
expect(io.which).toBeCalledWith('npm');
});
it('resolves tool path', async () => {
await install.fromPackager({ package: 'expo-cli', version: '3.0.10', packager: 'npm' });
expect(io.which).toBeCalledWith('npm');
});
it('creates temporary folder', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
await install.fromPackager('latest', 'yarn');
expect(io.mkdirP).toBeCalledWith(join('temp', 'path'));
utils.restoreEnv();
});
it('creates temporary folder', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
await install.fromPackager({ package: 'eas-cli', version: 'latest', packager: 'yarn' });
expect(io.mkdirP).toBeCalledWith(join('temp', 'path'));
utils.restoreEnv();
});
it('installs expo with tool', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
io.which.mockResolvedValue('npm');
const expoPath = await install.fromPackager('beta', 'npm');
expect(expoPath).toBe(join('temp', 'path'));
expect(cli.exec).toBeCalled();
expect(cli.exec.mock.calls[0][0]).toBe('npm');
expect(cli.exec.mock.calls[0][1]).toStrictEqual(['add', 'expo-cli@beta']);
expect(cli.exec.mock.calls[0][2]).toMatchObject({ cwd: join('temp', 'path') });
utils.restoreEnv();
});
it('installs expo with tool', async () => {
utils.setEnv('RUNNER_TEMP', join('temp', 'path'));
io.which.mockResolvedValue('npm');
const expoPath = await install.fromPackager({ package: 'eas-cli', version: 'beta', packager: 'npm' });
expect(expoPath).toBe(join('temp', 'path'));
expect(cli.exec).toBeCalled();
expect(cli.exec.mock.calls[0][0]).toBe('npm');
expect(cli.exec.mock.calls[0][1]).toStrictEqual(['add', 'eas-cli@beta']);
expect(cli.exec.mock.calls[0][2]).toMatchObject({ cwd: join('temp', 'path') });
utils.restoreEnv();
});
});
+27
View File
@@ -0,0 +1,27 @@
import { valid as validVersion } from 'semver';
import { resolveVersion } from '../src/packager';
describe(resolveVersion, () => {
it('resolves expo-cli@^2.0.0 to 2.21.2', async () => {
await expect(resolveVersion('expo-cli', '^2.0.0')).resolves.toBe('2.21.2');
});
it('resolves expo-cli@~3.15.0 to 3.15.5', async () => {
await expect(resolveVersion('expo-cli', '~3.15.0')).resolves.toBe('3.15.5');
});
it('resolves eas-cli@~0.33.0 to 0.33.1', async () => {
await expect(resolveVersion('eas-cli', '~0.33.0')).resolves.toBe('0.33.1');
});
it('resolves expo-cli@latest to a valid version', async () => {
const version = await resolveVersion('expo-cli', 'latest');
expect(validVersion(version)).not.toBeNull();
});
it('rejects donotpublishthispackageoryouwillbefired with proper error', async () => {
await expect(resolveVersion('donotpublishthispackageoryouwillbefired', 'latest')).rejects.toThrow(
'Could not resolve version "latest" of "donotpublishthispackageoryouwillbefired"'
);
});
});
-108
View File
@@ -1,108 +0,0 @@
const core = {
addPath: jest.fn(),
getInput: jest.fn(),
group: (message: string, action: () => Promise<any>) => action()
};
const exec = { exec: jest.fn() };
const install = { install: 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/tools', () => tools);
jest.mock('../src/install', () => install);
import { run } from '../src/run';
interface MockInputProps {
version?: string;
packager?: string;
token?: string;
username?: string;
password?: string;
patchWatchers?: string;
cache?: string;
cacheKey?: string;
}
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-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 '';
}
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
core.getInput = input as any;
};
describe('run', () => {
it('installs latest expo-cli with yarn by default', async () => {
await run();
expect(install.install).toBeCalledWith({ version: 'latest', packager: 'yarn', cache: false });
});
it('installs provided version expo-cli with npm', async () => {
mockInput({ version: '3.0.10', packager: 'npm' });
await run();
expect(install.install).toBeCalledWith({ version: '3.0.10', packager: 'npm', cache: false });
});
it('installs path to global path', async () => {
install.install.mockResolvedValue('/expo/install/path');
await run();
expect(core.addPath).toBeCalledWith('/expo/install/path');
});
it('patches the system when set to true', async () => {
mockInput({ patchWatchers: 'true' });
await run();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('patches the system when not set', async () => {
mockInput({ patchWatchers: '' });
await run();
expect(tools.maybePatchWatchers).toHaveBeenCalled();
});
it('skips the system patch when set to false', async () => {
mockInput({ patchWatchers: 'false' });
await run();
expect(tools.maybePatchWatchers).not.toHaveBeenCalled();
});
it('authenticates with provided credentials', async () => {
mockInput({ username: 'bycedric', password: 'mypassword', patchWatchers: 'false' });
await run();
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' });
});
});
+278 -232
View File
@@ -1,282 +1,328 @@
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 packager from '../src/packager';
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(tools.getBinaryName, () => {
it('returns expo for `expo-cli`', () => {
expect(tools.getBinaryName('expo-cli')).toBe('expo');
});
it('returns eas for `eas-cli`', () => {
expect(tools.getBinaryName('eas-cli')).toBe('eas');
});
it('returns eas.cmd for `eas-cli` for windows', () => {
expect(tools.getBinaryName('eas-cli', true)).toBe('eas.cmd');
});
});
describe('maybeAuthenticate', () => {
const token = 'ABC123';
const username = 'bycedric';
const password = 'mypassword';
describe(tools.maybeAuthenticate, () => {
const token = 'ABC123';
const username = 'bycedric';
const password = 'mypassword';
describe('with token', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
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(),
};
});
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();
});
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('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('executes whoami command with token through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await tools.maybeAuthenticate({ token, cli: 'expo-cli' });
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('fails when token is incorrect', async () => {
const error = new Error('Not logged in');
spy.exec.mockRejectedValue(error);
await expect(tools.maybeAuthenticate({ token, cli: 'expo-cli' })).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('skips validation without cli', async () => {
await tools.maybeAuthenticate({ token });
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping token validation'));
});
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` on macos', async () => {
utils.setPlatform('darwin');
await tools.maybeAuthenticate({ token, cli: 'expo-cli' });
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();
});
});
it('executes whoami command with `eas` on ubuntu', async () => {
utils.setPlatform('linux');
await tools.maybeAuthenticate({ token, cli: 'eas-cli' });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('eas');
utils.restorePlatform();
});
describe('credentials', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
it('executes whoami command with `expo.cmd` on windows', async () => {
utils.setPlatform('win32');
await tools.maybeAuthenticate({ token, cli: 'expo-cli' });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
beforeEach(() => {
spy = {
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
};
});
describe('credentials', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
afterAll(() => {
spy.exec.mockRestore();
spy.info.mockRestore();
});
beforeEach(() => {
spy = {
exec: jest.spyOn(cli, 'exec').mockImplementation(),
info: jest.spyOn(core, 'info').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
};
});
it('skips authentication without credentials', async () => {
await tools.maybeAuthenticate();
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
afterAll(() => {
spy.exec.mockRestore();
spy.info.mockRestore();
spy.warning.mockRestore();
});
it('skips authentication without password', async () => {
await tools.maybeAuthenticate({ username });
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
it('skips authentication without cli', async () => {
await tools.maybeAuthenticate({});
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('skips authentication without credentials', async () => {
await tools.maybeAuthenticate({ cli: 'expo-cli' });
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
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('skips authentication without password', async () => {
await tools.maybeAuthenticate({ username, cli: 'expo-cli' });
expect(spy.exec).not.toBeCalled();
expect(spy.info).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
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('skips authentication with credentials for eas-cli', async () => {
await tools.maybeAuthenticate({ username, password, cli: 'eas-cli' });
expect(spy.exec).not.toBeCalled();
expect(spy.warning).toBeCalledWith(expect.stringContaining('Skipping authentication'));
});
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 password through environment', async () => {
utils.setEnv('TEST_INCLUDED', 'hellyeah');
await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' });
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('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();
});
});
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, cli: 'expo-cli' })).rejects.toBe(error);
});
it('executes login command with `expo` on macos', async () => {
utils.setPlatform('darwin');
await tools.maybeAuthenticate({ username, password, cli: 'expo-cli' });
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, cli: 'expo-cli' });
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, cli: 'expo-cli' });
expect(spy.exec).toBeCalled();
expect(spy.exec.mock.calls[0][0]).toBe('expo.cmd');
utils.restorePlatform();
});
});
});
describe('maybePatchWatchers', () => {
let spy: { [key: string]: jest.SpyInstance } = {};
describe(tools.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(),
};
});
beforeEach(() => {
spy = {
info: jest.spyOn(core, 'info').mockImplementation(),
warning: jest.spyOn(core, 'warning').mockImplementation(),
exec: jest.spyOn(cli, 'exec').mockImplementation(),
};
});
afterEach(() => {
utils.restorePlatform();
});
afterEach(() => {
utils.restorePlatform();
});
afterAll(() => {
spy.info.mockRestore();
spy.warning.mockRestore();
spy.exec.mockRestore();
});
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('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('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 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('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();
});
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 } = {};
describe(tools.maybeWarnForUpdate, () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = { warning: jest.spyOn(core, 'warning').mockImplementation() };
});
beforeEach(() => {
spy = {
warning: jest.spyOn(core, 'warning').mockImplementation(),
resolveVersion: jest.spyOn(packager, 'resolveVersion').mockImplementation(),
};
});
afterAll(() => {
spy.warning.mockRestore();
});
afterAll(() => {
spy.warning.mockRestore();
spy.resolveVersion.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('is silent when major version is up to date', async () => {
spy.resolveVersion.mockResolvedValueOnce('4.1.0').mockResolvedValueOnce('4.0.1');
await tools.maybeWarnForUpdate('eas-cli');
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"');
})
it('warns when major version is outdated', async () => {
spy.resolveVersion.mockResolvedValueOnce('4.1.0').mockResolvedValueOnce('3.0.1');
await tools.maybeWarnForUpdate('expo-cli');
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 } = {};
describe(tools.handleError, () => {
let spy: { [key: string]: jest.SpyInstance } = {};
beforeEach(() => {
spy = { setFailed: jest.spyOn(core, 'setFailed').mockImplementation() };
});
beforeEach(() => {
spy = {
setFailed: jest.spyOn(core, 'setFailed').mockImplementation(),
resolveVersion: jest.spyOn(packager, 'resolveVersion').mockImplementation(),
};
});
afterAll(() => {
spy.setFailed.mockRestore();
});
afterAll(() => {
spy.setFailed.mockRestore();
spy.resolveVersion.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('marks the job as failed with expo-cli', async () => {
const error = new Error('test');
spy.resolveVersion.mockResolvedValue('4.0.0');
await tools.handleError('expo-cli', 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);
});
it('fails with original error when update warning failed', async () => {
const error = new Error('test');
spy.resolveVersion.mockRejectedValue(new Error('npm issue'));
await tools.handleError('eas-cli', error);
expect(core.setFailed).toBeCalledWith(error);
});
});
describe(tools.performAction, () => {
it('skips the test in a jest environment', async () => {
utils.setEnv('JEST_WORKER_ID', '69');
const action = jest.fn();
const result = await tools.performAction(action);
expect(result).toBeNull();
expect(action).not.toBeCalled();
utils.restoreEnv();
});
it('runs the test outside a jest environment', async () => {
utils.setEnv('JEST_WORKER_ID', '');
const action = jest.fn();
const result = await tools.performAction(action);
expect(result).toBeUndefined();
expect(action).toBeCalled();
utils.restoreEnv();
});
});
+28 -4
View File
@@ -1,3 +1,5 @@
import * as core from '@actions/core';
// keep track of the original one to revert the platform
const originalPlatform = process.platform;
@@ -6,14 +8,14 @@ const originalPlatform = process.platform;
* With this you can fake the `process.platform`.
*/
export function setPlatform(platform: NodeJS.Platform): void {
Object.defineProperty(process, 'platform', { value: platform });
Object.defineProperty(process, 'platform', { value: platform });
}
/**
* Revert the platform to the original one.
*/
export function restorePlatform(): void {
setPlatform(originalPlatform);
setPlatform(originalPlatform);
}
// keep track of the original environment variables
@@ -23,12 +25,34 @@ const originalEnv = { ...process.env };
* Change the environment variable for testing purposes.
*/
export function setEnv(name: string, value: string): void {
process.env[name] = value;
process.env[name] = value;
}
/**
* Revert the environment variable changes.
*/
export function restoreEnv(): void {
process.env = originalEnv;
process.env = originalEnv;
}
/**
* Get a mocked version of the tools.
*/
export function getToolsMock() {
return {
getBinaryName: jest.fn(v => v.replace('-cli', '')),
maybeAuthenticate: jest.fn(),
maybePatchWatchers: jest.fn(),
maybeWarnForUpdate: jest.fn(),
handleError: jest.fn(),
performAction: jest.fn(),
};
}
/**
* Mock both the input and boolean input methods from `@actions/core`.
*/
export function mockInput(inputs: Record<string, string> = {}) {
jest.spyOn(core, 'getInput').mockImplementation(name => inputs[name]);
jest.spyOn(core, 'getBooleanInput').mockImplementation(name => inputs[name] === 'true');
}
+2 -2
View File
@@ -1,9 +1,9 @@
{
"extends": "./node_modules/@tsconfig/node14/tsconfig.json",
"extends": "./node_modules/@tsconfig/node16/tsconfig.json",
"compilerOptions": {
"outDir": "./build",
"rootDir": "./src",
"noImplicitAny": false
"useUnknownInCatchVariables": false
},
"exclude": [
"build",
+820 -1964
View File
File diff suppressed because it is too large. Load diff