Compare commits

...
Author SHA1 Message Date
Szymon Dziedzic 137f9d4ac7 v5.0.0 2023-08-28 14:20:36 +02:00
Szymon Dziedzic 2ac863a9e3 upgrade eas-cli-local-build-plugin to 1.0.39 2023-08-28 14:19:20 +02:00
Quinlan Jung 11be9eba49 [ENG-9685][eas-cli] create a linked channel on build if not exists (#2017)
* [eas-cli] create linked channel on build

* refactor

* update CHANGELOG.md

* amend doc block
2023-08-25 12:07:59 -07:00
Will Schurman b36db15601 [eas-cli][updates] configure updates as well when somebody tries to run a build with channel set (#2016) 2023-08-25 09:14:29 -07:00
Piotr Szeremeta 93c5dc1a32 [ENG-9422] nvmrc support for setting node version (#1998)
* [ENG-9422][eas-cli] Use .nvmrc to set node version

* update CHANGELOG.md
2023-08-25 15:46:55 +02:00
Szymon Dziedzic c86550c0c8 [eas-cli][eas-json] add developmentClient to metadata (#2015)
* [eas-cli][eas-json] add `developmentClient` to metadata

* update CHANGELOG.md
2023-08-25 13:26:33 +02:00
Brent Vatne 36b4296d3c [.github] Add issue template config 2023-08-24 17:09:47 -07:00
Brent Vatne 8c08541ca3 Create SECURITY.md 2023-08-24 17:06:03 -07:00
Will Schurman 5a1406d39c [eas-cli] Add info to EAS Update asset upload process about asset counts and limits (#2013) 2023-08-24 09:22:30 -07:00
Radosław Krzemień 78ea88cc5f [eas-cli] [ENG-7591] Detect not provisioned devices (#2011)
* [eas-cli] Detect not provisioned devices

After selecting devices to be provisioned and making a call to App Store Connect API the result is compared with the list of chosen devices. If any are missing, a message is displayed to the user

See: https://linear.app/expo/issue/ENG-7591/detect-processing-devices-on-apple-developer-portal-and-dont-allow-the

* [eas-cli] Adjust message

Updated the message with the link to the devices page in the Apple Developer portal

See: https://linear.app/expo/issue/ENG-7591/detect-processing-devices-on-apple-developer-portal-and-dont-allow-the

* update CHANGELOG.md
2023-08-24 15:35:48 +02:00
Will Schurman 6cb02d0ccd [eas-cli][eas-update] Support republishing roll back to embedded updates (#2006) 2023-08-15 11:39:24 -04:00
Will Schurman d6c7623718 [eas-cli][eas-update] Add rollback disambiguation command (#2004) 2023-08-15 11:36:18 -04:00
Quinlan Jung 32142b4fe8 [eas-cli] more branch mapping utils (#2003)
* [eas-cli] more branch mapping utils

* update CHANGELOG.md
2023-08-14 14:51:29 -07:00
Will Schurman 6bdee0f395 [eas-cli][update] Only export at most ios and android dist (#2002) 2023-08-14 17:28:06 -04:00
Quinlan Jung baf94a21c3 [eas-cli] more branch map utility functions (#2001)
* [eas-cli] more branch map utility functions

* update CHANGELOG.md

* feedback
2023-08-11 11:35:47 -07:00
Radoslaw Krzemien 162d64bce6 Revert "[eas-cli] Update oclif version"
This reverts commit d16c1fc757.
2023-08-11 12:22:56 +02:00
Radoslaw Krzemien d16c1fc757 [eas-cli] Update oclif version
Updated oclif version

See: https://linear.app/expo/issue/ENG-9175/update-oclif-in-eas-cli
2023-08-11 12:22:17 +02:00
Expo CI e42ea7e2ec update CHANGELOG.md 2023-08-10 10:26:10 +00:00
Szymon Dziedzic 5fea1ad16e v4.1.2 2023-08-10 12:12:49 +02:00
Szymon Dziedzic 2a57a2eb3d upgrade eas-cli-local-build-plugin to 1.0.38 2023-08-10 12:12:41 +02:00
Quinlan Jung 5628b78523 [eas-cli] make branch mapping utility files have no dependencies (#1993)
* [eas-cli] generalize branch mapping utils

* make standalone

* update CHANGELOG.md
2023-08-09 15:32:19 -07:00
Expo CI 19d1e6bffd update CHANGELOG.md 2023-08-08 18:36:49 +00:00
Quinlan Jung 88b068511c v4.1.1 2023-08-08 11:28:16 -07:00
Quinlan Jung 842efcf3ab upgrade eas-cli-local-build-plugin to 1.0.35 2023-08-08 11:28:02 -07:00
Quinlan Jung f5f08aa506 [eas-cli] rollouts websupport (#1997)
* [eas-cli] rollouts websupport

* update CHANGELOG.md

* fix changelog
2023-08-08 11:26:18 -07:00
Expo CI 9f7f412cfb update CHANGELOG.md 2023-08-08 13:19:03 +00:00
Szymon Dziedzic e369ec1e25 v4.1.0 2023-08-08 15:10:39 +02:00
Szymon Dziedzic b353441f31 upgrade eas-cli-local-build-plugin to 1.0.34 2023-08-08 15:10:24 +02:00
Szymon Dziedzic 4db35e73c6 [eas-cli] bump @expo/steps version (#1995) 2023-08-08 15:02:33 +02:00
Szymon Dziedzic 10bc872dc9 [eas-json][eas-cli] add global withoutCredentials property to eas.json (#1994)
* [eas-json][eas-cli] add global `withoutCredentials` property to `eas.json`

* update CHANGELOG.md

* fix tests
2023-08-08 14:13:25 +02:00
Szymon Dziedzic fedc39ea48 [eas-cli] pass iOS credentials to custom builds (#1989)
* [eas-cli] pass iOS credentials to custom builds

* update CHANGELOG.md
2023-08-08 13:55:18 +02:00
Expo CI 6046723769 update CHANGELOG.md 2023-08-08 08:39:19 +00:00
Quinlan Jung afaee9df38 v4.0.1 2023-08-07 16:28:14 -07:00
Quinlan Jung de39d6f00d [eas-cli] account for empty branch mapping (#1992)
* [eas-cli] account for empty branch mapping

* update CHANGELOG.md
2023-08-07 16:24:32 -07:00
Expo CI 401751fffa update CHANGELOG.md 2023-08-07 20:40:01 +00:00
Quinlan Jung 7f7f1c6a9a v4.0.0 2023-08-07 13:31:43 -07:00
Quinlan Jung 279d6716d2 [ENG-9617][eas-cli] release rollout into developer preview (#1986)
* [eas-cli] release rollout into developer preview

* update CHANGELOG.md
2023-08-07 13:14:52 -07:00
Quinlan Jung 92977d9a53 [ENG-9666][eas-cli] rollouts: link fyi (#1991)
* [eas-cli] rollouts: link fyi:

* update CHANGELOG.md
2023-08-07 13:14:25 -07:00
Quinlan Jung 31871a9eda [ENG-9614][eas-cli] rollout ux improvements (#1984)
* [eas-cli] rollout ux improvements

* more efficient 'only one' detection

* update CHANGELOG.md

* fix tsc

* amend tests to account for new behaviour
2023-08-07 12:59:16 -07:00
Quinlan Jung f122f42149 [eas-ci] rollouts: fix fp precision (#1985)
* [eas-ci] rollouts: fix fp precision

* update CHANGELOG.md
2023-08-07 10:51:26 -07:00
Quinlan Jung a9a49d6b97 [eas-cli] more grammar fixes (#1980)
* replace 'route', no more plate emoji

replace plate emoji

more grammar nits

* update CHANGELOG.md

* szdziedzic feedback

* wschurman feedback

* send -> put

* put -> remain
2023-08-04 12:59:58 -07:00
Quinlan Jung 1d94414334 [ENG-9603][eas-cli] rollout edit edge case (#1981)
* [eas-cli] rollout edit edge case

* update CHANGELOG.md

* warn only

* warn only

* lint
2023-08-04 12:27:01 -07:00
Quinlan Jung 0b73dc32f6 [eas-cli] use 'roll out' instead of rollout for verbs (#1979)
* [eas-cli] use 'roll out' instead of rollout for verbs

* update CHANGELOG.md
2023-08-04 11:30:03 -07:00
Radosław Krzemień ef8ad24639 [eas-cli] [ENG-8475] Add option to add current device automatically (#1943)
* [eas-cli] Add option to add current device automatically

Added a new option to `device:create` command to add a current device by automatically grabbing the provisioning UDID of the current Apple Silicon machine. If the current machine is not Apple Silicon, the command fails with proper message. If the user does not proceed when prompted it also fails since trying again with the same UDID does not make much sense

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Adjust log messages

Improved the log message from testing phase

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Fix test

The `currentMachineMethod` tests used to be platform dependent, since the function checks for the architecture of the machine. This check is now mocked to make the tests platform agnostic

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Adjust message

On failed arch check the message was displayed twice, now it is displayed once

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Fix tests

The tests were still platform dependent since the system profiler is only viable for Macs. This should fix it

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Remove timeout

Jest.timeout was leftover from testing

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Re-generate gql schema

Generated schema again from production

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Re-generate gql schema

Generated schema again from production

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Fix test

Fix test that was failing after re-generating gql schema

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Add mac device class

Added the mac apple device class and made it default for current machine method

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Generate gql schema

Generated the schema again after merge from main

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Remove `arch` check

More systems than Apple Silicon can have `arch` of `arm64`

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* update CHANGELOG.md

* [eas-cli] Set mac device class automatically

It doesn't make sense to give the user choice of device class if we previously check if the current machine is an Apple Silicon Mac

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Remove unused import

Import became redundant after last changes

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Check for platform

Updated the apple silicon check to check the platform as well

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Update command description

The command description had a typo and mentioned only iPhones and iPads

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli

* [eas-cli] Remove unused import

Remove unused import

See: https://linear.app/expo/issue/ENG-8475/investigate-grabbing-registering-macos-provisioning-udid-from-eas-cli
2023-08-04 14:28:13 +02:00
Will Schurman 24dbe6e7cc [eas-cli] Fix rollout-preview ending with republish with code signing (#1978) 2023-08-03 15:30:04 -07:00
Expo CI aad026febb update CHANGELOG.md 2023-08-03 18:07:08 +00:00
Quinlan Jung 6ae8125c0e v3.18.3 2023-08-03 10:58:19 -07:00
Quinlan Jung 87d143b310 [ENG-8715][eas-cli] get channel:{view,list,edit} to play nice with rollouts (#1974)
* [eas-cli] get channel:{view,list,edit} to play nice with rollouts

* tests

* update CHANGELOG.md
2023-08-03 10:55:20 -07:00
Will Schurman 346dee9ea5 [eas-cli] Fix republishing with code signing (#1973) 2023-08-03 10:48:47 -07:00
Quinlan Jung 4308d21927 [eas-cli] rollout relationships (#1972)
* [eas-cli] rollout relationships

* update CHANGELOG.md
2023-08-03 10:18:18 -07:00
Expo CI 207f623338 update CHANGELOG.md 2023-08-03 12:53:11 +00:00
Szymon Dziedzic 601101844c v3.18.2 2023-08-03 14:43:28 +02:00
Szymon Dziedzic 7027eaa974 upgrade eas-cli-local-build-plugin to 1.0.33 2023-08-03 14:43:17 +02:00
Szymon Dziedzic b3203345ea Revert "[ENG-9422][eas-cli] Use .nvmrc to set node version (#1954)" (#1976)
* Revert "[ENG-9422][eas-cli] Use .nvmrc to set node version (#1954)"

This reverts commit 0b5194b1a5.

* update CHANGELOG.md
2023-08-03 14:35:28 +02:00
Szymon Dziedzic 5ed2d01146 [eas-cli][metadata] use just a comma to concatenate keywords (#1967)
* [eas-cli][metadata] use just a comma to concatenate keywords

* update CHANGELOG.md
2023-08-03 14:30:24 +02:00
Szymon Dziedzic 6fc64d337f fix changelog once again 2023-08-03 14:22:49 +02:00
Szymon Dziedzic f7ed4cfa20 fix changelog 2023-08-03 13:22:09 +02:00
Expo CI 47968a1b8b update CHANGELOG.md 2023-08-03 02:14:06 +00:00
Quinlan Jung 7c779b3dc0 v3.18.1 2023-08-02 19:04:22 -07:00
Quinlan Jung 50474ec5e9 [eas-cli] fix update:republish group id (#1971)
* [eas-cli] fix update:republish group id

* update CHANGELOG.md
2023-08-02 15:20:33 -07:00
Quinlan Jung 46ff97f173 [ENG-8616][eas-cli] change update default runtime policy (#1968)
* [eas-cli] change update default runtime policy

* update CHANGELOG.md
2023-08-02 14:59:09 -07:00
Szymon Dziedzic b263dffbde update and fix changelog 2023-08-02 23:53:24 +02:00
Quinlan Jung 8d57828f7e [ENG-9441][eas-cli] channel:rollout-unstable (#1966)
* [eas-cli] eas channel:rollout-unstable

* json unsupport

* update CHANGELOG.md

* fix tsc

* fix test

* fix lint

* new selectors using filter pagination

* replace selectors

* remove unused stuff

* branch mapping tests

* add tests for relay utilities and selectors

* at is not shipped in node14

* pr feedback
2023-08-02 14:40:40 -07:00
Szymon Dziedzic fd9561cfc3 v3.18.0 2023-08-02 23:33:31 +02:00
Szymon Dziedzic 93ce451bc7 upgrade eas-cli-local-build-plugin to 1.0.31 2023-08-02 23:33:14 +02:00
Szymon Dziedzic 554e433548 update @expo/steps and @expo/eas-build-job (#1970) 2023-08-02 23:24:35 +02:00
Szymon Dziedzic 12a1cb7011 [ENG-9482][eas-cli] provide credentials for custom Android builds (#1969)
* [eas-cli] provide credentials for custom Android builds

* update CHANGELOG.md
2023-08-02 18:06:41 +02:00
Patryk FrydaandPatryk Fryda 360de90eea [eas-cli] fix 'manged' typo in ios target (#1961)
Co-authored-by: Patryk Fryda <[email protected]>
2023-07-31 17:08:12 +02:00
Quinlan Jung ea02fcebda [eas-cli] select existing rollouts and channels (#1958)
* [eas-cli] select existing rollouts and channels

* update CHANGELOG.md
2023-07-28 09:27:17 -07:00
Piotr Szeremeta 0b5194b1a5 [ENG-9422][eas-cli] Use .nvmrc to set node version (#1954)
* [ENG-9422][eas-cli] Use .nvmrc to set node version

* update CHANGELOG.md
2023-07-28 12:26:03 +02:00
Quinlan Jung 05799aba9c [eas-cli] more branch mapping utility (#1957)
* [eas-cli] more branch mapping utility

* update CHANGELOG.md
2023-07-27 17:05:00 -07:00
Expo CI 2cece65dbf update CHANGELOG.md 2023-07-27 14:32:42 +00:00
Szymon Dziedzic 17b6b4ec45 v3.17.1 2023-07-27 15:37:26 +02:00
Szymon Dziedzic 4f892c66e7 [eas-cli] update @expo/steps version (#1956) 2023-07-27 15:15:09 +02:00
Quinlan Jung fd99365655 [eas-cli] fetch entire relay compliant dataset (#1955)
* [eas-cli] fetch entire relay compliant dataset

* update CHANGELOG.md
2023-07-26 20:48:21 -07:00
Quinlan Jung 7dca2c8021 [eas-cli] revert UpdateBranchWithCurrentGroupFragment (#1952)
* [eas-ci] revert UpdateBranchWithCurrentGroupFragment

* update CHANGELOG.md
2023-07-26 10:32:11 -07:00
98 changed files with 7852 additions and 1483 deletions

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Expo Developers Discord
url: https://chat.expo.dev/
about: Join other developers in discussions regarding Expo and EAS.
+114
View File
@@ -6,13 +6,127 @@ This is the log of notable changes to EAS CLI and related packages.
### 🛠 Breaking changes
- Only export at most ios and android dist for EAS updates. ([#2002](https://github.com/expo/eas-cli/pull/2002) by [@wschurman](https://github.com/wschurman))
### 🎉 New features
- Add rollback disambiguation command. ([#2004](https://github.com/expo/eas-cli/pull/2004) by [@wschurman](https://github.com/wschurman))
- Detect devices that fail to be provisioned, list them to the user and show the explanation message with the link to the devices page to check actual status. ([#2011](https://github.com/expo/eas-cli/pull/2011) by [@radoslawkrzemien](https://github.com/radoslawkrzemien))
- Add info to EAS Update asset upload process about asset counts and limits. ([#2013](https://github.com/expo/eas-cli/pull/2013) by [@wschurman](https://github.com/wschurman))
- .nvmrc support for setting node version. ([#1954](https://github.com/expo/eas-cli/pull/1954) by [@khamilowicz](https://github.com/khamilowicz))
### 🐛 Bug fixes
- Support republishing roll back to embedded updates. ([#2006](https://github.com/expo/eas-cli/pull/2006) by [@wschurman](https://github.com/wschurman))
- Configure updates as well when somebody tries to run a build with channel set. ([#2016](https://github.com/expo/eas-cli/pull/2016) by [@wschurman](https://github.com/wschurman))
### 🧹 Chores
- More branch map utility functions. ([#2001](https://github.com/expo/eas-cli/pull/2001) by [@quinlanj](https://github.com/quinlanj))
- More branch mapping utils. ([#2003](https://github.com/expo/eas-cli/pull/2003) by [@quinlanj](https://github.com/quinlanj))
- Create a linked channel on build if not exists. ([#2017](https://github.com/expo/eas-cli/pull/2017) by [@quinlanj](https://github.com/quinlanj))
- Add `developmentClient` to metadata. ([#2015](https://github.com/expo/eas-cli/pull/2015) by [@szdziedzic](https://github.com/szdziedzic))
## [4.1.2](https://github.com/expo/eas-cli/releases/tag/v4.1.2) - 2023-08-10
### 🧹 Chores
- Make branch mapping utility files have no dependencies. ([#1993](https://github.com/expo/eas-cli/pull/1993) by [@quinlanj](https://github.com/quinlanj))
## [4.1.1](https://github.com/expo/eas-cli/releases/tag/v4.1.1) - 2023-08-08
### 🧹 Chores
- Logger to say website support is coming soon for rollouts. ([#1997](https://github.com/expo/eas-cli/pull/1997) by [@quinlanj](https://github.com/quinlanj))
## [4.1.0](https://github.com/expo/eas-cli/releases/tag/v4.1.0) - 2023-08-08
### 🎉 New features
- Pass credentials to custom iOS builds. ([#1989](https://github.com/expo/eas-cli/pull/1989) by [@szdziedzic](https://github.com/szdziedzic))
- Add the `withoutCredentials` option as a common build profile field in `eas.json`. ([#1994](https://github.com/expo/eas-cli/pull/1994) by [@szdziedzic](https://github.com/szdziedzic))
## [4.0.1](https://github.com/expo/eas-cli/releases/tag/v4.0.1) - 2023-08-08
### 🐛 Bug fixes
- Fix `eas channel:*` to work with empty branch mappings. ([#1992](https://github.com/expo/eas-cli/pull/1992) by [@quinlanj](https://github.com/quinlanj))
## [4.0.0](https://github.com/expo/eas-cli/releases/tag/v4.0.0) - 2023-08-07
### 🛠 Breaking changes
- Release redesigned `eas channel:rollout` into developer preview. The set of flag arguments are different, in addition to the workflow. ([#1986](https://github.com/expo/eas-cli/pull/1986) by [@quinlanj](https://github.com/quinlanj))
### 🎉 New features
- Option to add current Apple Silicon device without the need to manually provide the provisioning UDID. ([#1943](https://github.com/expo/eas-cli/pull/1943) by [@radoslawkrzemien](https://github.com/radoslawkrzemien))
### 🐛 Bug fixes
- Fix rollout-preview ending with republish with code signing. ([#1978](https://github.com/expo/eas-cli/pull/1978) by [@wschurman](https://github.com/wschurman))
- Rollouts: fix fp precision. ([#1985](https://github.com/expo/eas-cli/pull/1985) by [@quinlanj](https://github.com/quinlanj))
### 🧹 Chores
- Fixing more grammar errors. ([#1980](https://github.com/expo/eas-cli/pull/1980) by [@quinlanj](https://github.com/quinlanj))
- Handle rollout edit edge case. ([#1981](https://github.com/expo/eas-cli/pull/1981) by [@quinlanj](https://github.com/quinlanj))
- Linked expo.fyi rollout article. ([#1991](https://github.com/expo/eas-cli/pull/1991) by [@quinlanj](https://github.com/quinlanj))
- Rollout ux improvements. ([#1984](https://github.com/expo/eas-cli/pull/1984) by [@quinlanj](https://github.com/quinlanj))
## [3.18.3](https://github.com/expo/eas-cli/releases/tag/v3.18.3) - 2023-08-03
### 🐛 Bug fixes
- Fix republishing with code signing. ([#1973](https://github.com/expo/eas-cli/pull/1973) by [@wschurman](https://github.com/wschurman))
### 🧹 Chores
- Add relationships flag to rollouts-preview. ([#1972](https://github.com/expo/eas-cli/pull/1972) by [@quinlanj](https://github.com/quinlanj))
- Get channel:{view,list,edit} to play nice with rollouts. ([#1974](https://github.com/expo/eas-cli/pull/1974) by [@quinlanj](https://github.com/quinlanj))
- Use 'roll out' instead of rollout for verbs. ([#1979](https://github.com/expo/eas-cli/pull/1979) by [@quinlanj](https://github.com/quinlanj))
## [3.18.2](https://github.com/expo/eas-cli/releases/tag/v3.18.2) - 2023-08-03
### 🐛 Bug fixes
- Revert adding `.nvmrc` support for setting node version. ([#1976](https://github.com/expo/eas-cli/pull/1976) by [@szdziedzic](https://github.com/szdziedzic))
### 🧹 Chores
- Use just a comma instead of `, ` when concatenating `keywords` in `eas metadata`. ([#1967](https://github.com/expo/eas-cli/pull/1967) by [@szdziedzic](https://github.com/szdziedzic))
## [3.18.1](https://github.com/expo/eas-cli/releases/tag/v3.18.1) - 2023-08-03
### 🐛 Bug fixes
- Pass correct group into `update:republish`. ([#1971](https://github.com/expo/eas-cli/pull/1971) by [@quinlanj](https://github.com/quinlanj))
### 🧹 Chores
- Make new rollouts version available for internal dogfooding. ([#1966](https://github.com/expo/eas-cli/pull/1966) by [@quinlanj](https://github.com/quinlanj))
- Change default runtime version policy for EAS Update to appVersion. ([#1968](https://github.com/expo/eas-cli/pull/1968) by [@quinlanj](https://github.com/quinlanj))
## [3.18.0](https://github.com/expo/eas-cli/releases/tag/v3.18.0) - 2023-08-02
### 🎉 New features
- .nvmrc support for setting node version. ([#1954](https://github.com/expo/eas-cli/pull/1954) by [@khamilowicz](https://github.com/khamilowicz))
- Provide credentials for custom Android builds. ([#1969](https://github.com/expo/eas-cli/pull/1969) by [@szdziedzic](https://github.com/szdziedzic))
### 🧹 Chores
- More branch mapping utility. ([#1957](https://github.com/expo/eas-cli/pull/1957) by [@quinlanj](https://github.com/quinlanj))
- Utility classes to select existing rollouts and channels. ([#1958](https://github.com/expo/eas-cli/pull/1958) by [@quinlanj](https://github.com/quinlanj))
## [3.17.1](https://github.com/expo/eas-cli/releases/tag/v3.17.1) - 2023-07-27
### 🧹 Chores
- Unify channel graphql query types. ([#1949](https://github.com/expo/eas-cli/pull/1949) by [@quinlanj](https://github.com/quinlanj))
- Revert UpdateBranchWithCurrentGroupFragment. ([#1952](https://github.com/expo/eas-cli/pull/1952) by [@quinlanj](https://github.com/quinlanj))
- Fetch entire relay compliant dataset. ([#1953](https://github.com/expo/eas-cli/pull/1953) by [@quinlanj](https://github.com/quinlanj))
## [3.17.0](https://github.com/expo/eas-cli/releases/tag/v3.17.0) - 2023-07-24
+5
View File
@@ -0,0 +1,5 @@
# Security Policy
## Reporting a Vulnerability
Instead of opening a GitHub issue for security vulnerabilities, send an email to our secure inbox: secure@expo.io.
+1 -1
View File
@@ -1,6 +1,6 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"version": "3.17.0",
"version": "5.0.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
+76 -65
View File
@@ -133,7 +133,7 @@ ALIASES
$ eas login
```
_See code: [src/commands/account/login.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/account/login.ts)_
_See code: [src/commands/account/login.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/account/login.ts)_
## `eas account:logout`
@@ -150,7 +150,7 @@ ALIASES
$ eas logout
```
_See code: [src/commands/account/logout.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/account/logout.ts)_
_See code: [src/commands/account/logout.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/account/logout.ts)_
## `eas account:view`
@@ -167,7 +167,7 @@ ALIASES
$ eas whoami
```
_See code: [src/commands/account/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/account/view.ts)_
_See code: [src/commands/account/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/account/view.ts)_
## `eas analytics [STATUS]`
@@ -181,7 +181,7 @@ DESCRIPTION
display or change analytics settings
```
_See code: [src/commands/analytics.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/analytics.ts)_
_See code: [src/commands/analytics.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/analytics.ts)_
## `eas autocomplete [SHELL]`
@@ -231,7 +231,7 @@ DESCRIPTION
create a branch
```
_See code: [src/commands/branch/create.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/branch/create.ts)_
_See code: [src/commands/branch/create.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/branch/create.ts)_
## `eas branch:delete [NAME]`
@@ -252,7 +252,7 @@ DESCRIPTION
delete a branch
```
_See code: [src/commands/branch/delete.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/branch/delete.ts)_
_See code: [src/commands/branch/delete.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/branch/delete.ts)_
## `eas branch:list`
@@ -272,7 +272,7 @@ DESCRIPTION
list all branches
```
_See code: [src/commands/branch/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/branch/list.ts)_
_See code: [src/commands/branch/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/branch/list.ts)_
## `eas branch:rename`
@@ -292,7 +292,7 @@ DESCRIPTION
rename a branch
```
_See code: [src/commands/branch/rename.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/branch/rename.ts)_
_See code: [src/commands/branch/rename.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/branch/rename.ts)_
## `eas branch:view [NAME]`
@@ -315,7 +315,7 @@ DESCRIPTION
view a branch
```
_See code: [src/commands/branch/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/branch/view.ts)_
_See code: [src/commands/branch/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/branch/view.ts)_
## `eas build`
@@ -345,7 +345,7 @@ DESCRIPTION
start a build
```
_See code: [src/commands/build/index.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/index.ts)_
_See code: [src/commands/build/index.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/index.ts)_
## `eas build:cancel [BUILD_ID]`
@@ -362,7 +362,7 @@ DESCRIPTION
cancel a build
```
_See code: [src/commands/build/cancel.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/cancel.ts)_
_See code: [src/commands/build/cancel.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/cancel.ts)_
## `eas build:configure`
@@ -379,7 +379,7 @@ DESCRIPTION
configure the project to support EAS Build
```
_See code: [src/commands/build/configure.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/configure.ts)_
_See code: [src/commands/build/configure.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/configure.ts)_
## `eas build:inspect`
@@ -414,7 +414,7 @@ DESCRIPTION
inspect the state of the project at specific build stages, useful for troubleshooting
```
_See code: [src/commands/build/inspect.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/inspect.ts)_
_See code: [src/commands/build/inspect.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/inspect.ts)_
## `eas build:list`
@@ -452,7 +452,7 @@ DESCRIPTION
list all builds for your project
```
_See code: [src/commands/build/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/list.ts)_
_See code: [src/commands/build/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/list.ts)_
## `eas build:resign`
@@ -478,7 +478,7 @@ DESCRIPTION
re-sign a build archive
```
_See code: [src/commands/build/resign.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/resign.ts)_
_See code: [src/commands/build/resign.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/resign.ts)_
## `eas build:run`
@@ -502,7 +502,7 @@ DESCRIPTION
run simulator/emulator builds from eas-cli
```
_See code: [src/commands/build/run.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/run.ts)_
_See code: [src/commands/build/run.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/run.ts)_
## `eas build:submit`
@@ -551,7 +551,7 @@ DESCRIPTION
get the latest version from EAS servers
```
_See code: [src/commands/build/version/get.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/version/get.ts)_
_See code: [src/commands/build/version/get.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/version/get.ts)_
## `eas build:version:set`
@@ -570,7 +570,7 @@ DESCRIPTION
update version of an app
```
_See code: [src/commands/build/version/set.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/version/set.ts)_
_See code: [src/commands/build/version/set.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/version/set.ts)_
## `eas build:version:sync`
@@ -589,7 +589,7 @@ DESCRIPTION
update a version in native code with a value stored on EAS servers
```
_See code: [src/commands/build/version/sync.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/version/sync.ts)_
_See code: [src/commands/build/version/sync.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/version/sync.ts)_
## `eas build:view [BUILD_ID]`
@@ -606,7 +606,7 @@ DESCRIPTION
view a build for your project
```
_See code: [src/commands/build/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/build/view.ts)_
_See code: [src/commands/build/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/build/view.ts)_
## `eas channel:create [NAME]`
@@ -627,7 +627,7 @@ DESCRIPTION
create a channel
```
_See code: [src/commands/channel/create.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/channel/create.ts)_
_See code: [src/commands/channel/create.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/channel/create.ts)_
## `eas channel:edit [NAME]`
@@ -649,7 +649,7 @@ DESCRIPTION
point a channel at a new branch
```
_See code: [src/commands/channel/edit.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/channel/edit.ts)_
_See code: [src/commands/channel/edit.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/channel/edit.ts)_
## `eas channel:list`
@@ -669,7 +669,7 @@ DESCRIPTION
list all channels
```
_See code: [src/commands/channel/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/channel/list.ts)_
_See code: [src/commands/channel/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/channel/list.ts)_
## `eas channel:rollout [CHANNEL]`
@@ -677,23 +677,31 @@ Roll a new branch out on a channel incrementally.
```
USAGE
$ eas channel:rollout [CHANNEL] [--branch <value>] [--percent <value>] [--end] [--json --non-interactive]
$ eas channel:rollout [CHANNEL] [--action create|edit|end] [--percent <value>] [--outcome
republish-and-revert|revert] [--branch <value>] [--runtime-version <value>] [--private-key-path <value>] [--json
--non-interactive]
ARGUMENTS
CHANNEL channel on which the rollout should be done
FLAGS
--branch=<value> branch to rollout
--end end the rollout
--json Enable JSON output, non-JSON messages will be printed to stderr.
--non-interactive Run the command in non-interactive mode.
--percent=<value> percent of users to send to the new branch
--action=(create|edit|end) Rollout action to perform
--branch=<value> Branch to roll out. Use with --action=create
--json Enable JSON output, non-JSON messages will be printed to stderr.
--non-interactive Run the command in non-interactive mode.
--outcome=(republish-and-revert|revert) End outcome of rollout. Use with --action=end
--percent=<value> Percent of users to send to the new branch. Use with --action=edit or
--action=create
--private-key-path=<value> File containing the PEM-encoded private key corresponding to the certificate
in expo-updates' configuration. Defaults to a file named "private-key.pem" in
the certificate's directory.
--runtime-version=<value> Runtime version to target. Use with --action=create
DESCRIPTION
Roll a new branch out on a channel incrementally.
```
_See code: [src/commands/channel/rollout.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/channel/rollout.ts)_
_See code: [src/commands/channel/rollout.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/channel/rollout.ts)_
## `eas channel:view [NAME]`
@@ -716,7 +724,7 @@ DESCRIPTION
view a channel
```
_See code: [src/commands/channel/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/channel/view.ts)_
_See code: [src/commands/channel/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/channel/view.ts)_
## `eas config`
@@ -737,7 +745,7 @@ DESCRIPTION
display project configuration (app.json + eas.json)
```
_See code: [src/commands/config.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/config.ts)_
_See code: [src/commands/config.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/config.ts)_
## `eas credentials`
@@ -754,7 +762,7 @@ DESCRIPTION
manage credentials
```
_See code: [src/commands/credentials.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/credentials.ts)_
_See code: [src/commands/credentials.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/credentials.ts)_
## `eas device:create`
@@ -768,7 +776,7 @@ DESCRIPTION
register new Apple Devices to use for internal distribution
```
_See code: [src/commands/device/create.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/device/create.ts)_
_See code: [src/commands/device/create.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/device/create.ts)_
## `eas device:delete`
@@ -788,7 +796,7 @@ DESCRIPTION
remove a registered device from your account
```
_See code: [src/commands/device/delete.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/device/delete.ts)_
_See code: [src/commands/device/delete.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/device/delete.ts)_
## `eas device:list`
@@ -809,7 +817,7 @@ DESCRIPTION
list all registered devices for your account
```
_See code: [src/commands/device/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/device/list.ts)_
_See code: [src/commands/device/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/device/list.ts)_
## `eas device:rename`
@@ -830,7 +838,7 @@ DESCRIPTION
rename a registered device
```
_See code: [src/commands/device/rename.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/device/rename.ts)_
_See code: [src/commands/device/rename.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/device/rename.ts)_
## `eas device:view [UDID]`
@@ -844,7 +852,7 @@ DESCRIPTION
view a device for your project
```
_See code: [src/commands/device/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/device/view.ts)_
_See code: [src/commands/device/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/device/view.ts)_
## `eas diagnostics`
@@ -858,7 +866,7 @@ DESCRIPTION
display environment info
```
_See code: [src/commands/diagnostics.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/diagnostics.ts)_
_See code: [src/commands/diagnostics.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/diagnostics.ts)_
## `eas help [COMMAND]`
@@ -946,7 +954,7 @@ DESCRIPTION
validate the local store configuration
```
_See code: [src/commands/metadata/lint.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/metadata/lint.ts)_
_See code: [src/commands/metadata/lint.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/metadata/lint.ts)_
## `eas metadata:pull`
@@ -963,7 +971,7 @@ DESCRIPTION
generate the local store configuration from the app stores
```
_See code: [src/commands/metadata/pull.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/metadata/pull.ts)_
_See code: [src/commands/metadata/pull.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/metadata/pull.ts)_
## `eas metadata:push`
@@ -980,7 +988,7 @@ DESCRIPTION
sync the local store configuration to the app stores
```
_See code: [src/commands/metadata/push.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/metadata/push.ts)_
_See code: [src/commands/metadata/push.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/metadata/push.ts)_
## `eas open`
@@ -994,7 +1002,7 @@ DESCRIPTION
open the project page in a web browser
```
_See code: [src/commands/open.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/open.ts)_
_See code: [src/commands/open.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/open.ts)_
## `eas project:info`
@@ -1008,7 +1016,7 @@ DESCRIPTION
information about the current project
```
_See code: [src/commands/project/info.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/project/info.ts)_
_See code: [src/commands/project/info.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/project/info.ts)_
## `eas project:init`
@@ -1030,7 +1038,7 @@ ALIASES
$ eas init
```
_See code: [src/commands/project/init.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/project/init.ts)_
_See code: [src/commands/project/init.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/project/init.ts)_
## `eas secret:create`
@@ -1053,7 +1061,7 @@ DESCRIPTION
create an environment secret on the current project or owner account
```
_See code: [src/commands/secret/create.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/secret/create.ts)_
_See code: [src/commands/secret/create.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/secret/create.ts)_
## `eas secret:delete`
@@ -1071,7 +1079,7 @@ DESCRIPTION
delete an environment secret by ID
```
_See code: [src/commands/secret/delete.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/secret/delete.ts)_
_See code: [src/commands/secret/delete.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/secret/delete.ts)_
## `eas secret:list`
@@ -1085,7 +1093,7 @@ DESCRIPTION
list environment secrets available for your current app
```
_See code: [src/commands/secret/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/secret/list.ts)_
_See code: [src/commands/secret/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/secret/list.ts)_
## `eas secret:push`
@@ -1105,7 +1113,7 @@ DESCRIPTION
read environment secrets from env file and store on the server
```
_See code: [src/commands/secret/push.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/secret/push.ts)_
_See code: [src/commands/secret/push.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/secret/push.ts)_
## `eas submit`
@@ -1135,7 +1143,7 @@ ALIASES
$ eas build:submit
```
_See code: [src/commands/submit.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/submit.ts)_
_See code: [src/commands/submit.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/submit.ts)_
## `eas update`
@@ -1168,7 +1176,7 @@ DESCRIPTION
publish an update group
```
_See code: [src/commands/update/index.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/index.ts)_
_See code: [src/commands/update/index.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/index.ts)_
## `eas update:configure`
@@ -1186,7 +1194,7 @@ DESCRIPTION
configure the project to support EAS Update
```
_See code: [src/commands/update/configure.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/configure.ts)_
_See code: [src/commands/update/configure.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/configure.ts)_
## `eas update:delete GROUPID`
@@ -1207,7 +1215,7 @@ DESCRIPTION
delete all the updates in an update group
```
_See code: [src/commands/update/delete.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/delete.ts)_
_See code: [src/commands/update/delete.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/delete.ts)_
## `eas update:list`
@@ -1229,7 +1237,7 @@ DESCRIPTION
view the recent updates
```
_See code: [src/commands/update/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/list.ts)_
_See code: [src/commands/update/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/list.ts)_
## `eas update:republish`
@@ -1238,22 +1246,25 @@ roll back to an existing update
```
USAGE
$ eas update:republish [--channel <value> | --branch <value> | --group <value>] [-m <value>] [-p android|ios|all]
[--json --non-interactive]
[--private-key-path <value>] [--json --non-interactive]
FLAGS
-m, --message=<value> Short message describing the republished update
-m, --message=<value> Short message describing the republished update group
-p, --platform=(android|ios|all) [default: all]
--branch=<value> Branch name to select an update to republish from
--channel=<value> Channel name to select an update to republish from
--branch=<value> Branch name to select an update group to republish from
--channel=<value> Channel name to select an update group to republish from
--group=<value> Update group ID to republish
--json Enable JSON output, non-JSON messages will be printed to stderr.
--non-interactive Run the command in non-interactive mode.
--private-key-path=<value> File containing the PEM-encoded private key corresponding to the certificate in
expo-updates' configuration. Defaults to a file named "private-key.pem" in the
certificate's directory.
DESCRIPTION
roll back to an existing update
```
_See code: [src/commands/update/republish.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/republish.ts)_
_See code: [src/commands/update/republish.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/republish.ts)_
## `eas update:view GROUPID`
@@ -1273,7 +1284,7 @@ DESCRIPTION
update group details
```
_See code: [src/commands/update/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/update/view.ts)_
_See code: [src/commands/update/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/update/view.ts)_
## `eas webhook:create`
@@ -1294,7 +1305,7 @@ DESCRIPTION
create a webhook
```
_See code: [src/commands/webhook/create.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/webhook/create.ts)_
_See code: [src/commands/webhook/create.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/webhook/create.ts)_
## `eas webhook:delete [ID]`
@@ -1314,7 +1325,7 @@ DESCRIPTION
delete a webhook
```
_See code: [src/commands/webhook/delete.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/webhook/delete.ts)_
_See code: [src/commands/webhook/delete.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/webhook/delete.ts)_
## `eas webhook:list`
@@ -1332,7 +1343,7 @@ DESCRIPTION
list webhooks
```
_See code: [src/commands/webhook/list.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/webhook/list.ts)_
_See code: [src/commands/webhook/list.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/webhook/list.ts)_
## `eas webhook:update`
@@ -1354,7 +1365,7 @@ DESCRIPTION
update a webhook
```
_See code: [src/commands/webhook/update.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/webhook/update.ts)_
_See code: [src/commands/webhook/update.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/webhook/update.ts)_
## `eas webhook:view ID`
@@ -1371,7 +1382,7 @@ DESCRIPTION
view a webhook
```
_See code: [src/commands/webhook/view.ts](https://github.com/expo/eas-cli/blob/v3.17.0/packages/eas-cli/src/commands/webhook/view.ts)_
_See code: [src/commands/webhook/view.ts](https://github.com/expo/eas-cli/blob/v5.0.0/packages/eas-cli/src/commands/webhook/view.ts)_
## `eas whoami`
+1366 -99
View File
File diff suppressed because it is too large. Load diff
+4 -4
View File
@@ -1,7 +1,7 @@
{
"name": "eas-cli",
"description": "EAS command line tool",
"version": "3.17.0",
"version": "5.0.0",
"author": "Expo <[email protected]>",
"bin": {
"eas": "./bin/run"
@@ -13,8 +13,8 @@
"@expo/config": "8.1.2",
"@expo/config-plugins": "7.2.4",
"@expo/config-types": "49.0.0",
"@expo/eas-build-job": "1.0.13",
"@expo/eas-json": "3.17.0",
"@expo/eas-build-job": "1.0.39",
"@expo/eas-json": "5.0.0",
"@expo/json-file": "8.2.37",
"@expo/multipart-body-parser": "1.1.0",
"@expo/osascript": "2.0.33",
@@ -27,7 +27,7 @@
"@expo/results": "1.0.0",
"@expo/rudder-sdk-node": "1.1.1",
"@expo/spawn-async": "1.7.0",
"@expo/steps": "1.0.25",
"@expo/steps": "1.0.34",
"@expo/timeago.js": "1.0.0",
"@oclif/core": "1.23.2",
"@oclif/plugin-autocomplete": "1.3.10",
@@ -0,0 +1,12 @@
import { UpdateBranchBasicInfoFragment } from '../../graphql/generated';
export const testBasicBranchInfo: UpdateBranchBasicInfoFragment = {
id: 'c4fec95d-7ab1-4d35-bfe6-fe7ff05beda9',
name: 'development',
__typename: 'UpdateBranch',
};
export const testBasicBranchInfo2: UpdateBranchBasicInfoFragment = {
id: '43ccb8a4-8aaa-47f0-9790-dcc80933441b',
name: 'preview',
__typename: 'UpdateBranch',
};
@@ -0,0 +1,107 @@
import { EASUpdateAction, EASUpdateContext, NonInteractiveError } from '../../eas-update/utils';
import { UpdateBranchBasicInfoFragment } from '../../graphql/generated';
import { BranchQuery } from '../../graphql/queries/BranchQuery';
import {
Connection,
Edge,
FilterPagination,
QueryParams,
selectPaginatedAsync,
} from '../../utils/relay';
/**
* Select a branch for the project.
*
* @constructor
* @param {function} options.filterPredicate - A predicate to filter the branches that are shown to the user. It takes a branchInfo object as a parameter and returns a boolean.
* @param {string} options.printedType - The type of branch printed to the user. Defaults to 'branch'.
* @param {number} options.pageSize - The number of branches to show per page. Defaults to 100.
* @param {function} options.beforeEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called before each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @param {function} options.afterEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called after each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @args willFetchAgain If the query will fetch again to get a complete page.
*/
export class SelectBranch implements EASUpdateAction<UpdateBranchBasicInfoFragment | null> {
constructor(
private options: {
filterPredicate?: (branchInfo: UpdateBranchBasicInfoFragment) => boolean;
printedType?: string;
pageSize?: number;
beforeEachFilterQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<UpdateBranchBasicInfoFragment>[]
) => void;
afterEachFilterQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<UpdateBranchBasicInfoFragment>[],
willFetchAgain: boolean
) => void;
} = {}
) {}
async queryAsync(
ctx: EASUpdateContext,
queryParams: QueryParams
): Promise<Connection<UpdateBranchBasicInfoFragment>> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
return await BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync(graphqlClient, {
appId: projectId,
...queryParams,
});
}
async filterQueryAsync(
ctx: EASUpdateContext,
queryParams: QueryParams,
filterPredicate: (branchInfo: UpdateBranchBasicInfoFragment) => boolean
): Promise<Connection<UpdateBranchBasicInfoFragment>> {
const queryAsync = async (
queryParams: QueryParams
): Promise<Connection<UpdateBranchBasicInfoFragment>> =>
await this.queryAsync(ctx, queryParams);
return await FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery: this.options.beforeEachFilterQuery,
afterEachQuery: this.options.afterEachFilterQuery,
});
}
public async runAsync(ctx: EASUpdateContext): Promise<UpdateBranchBasicInfoFragment | null> {
const { nonInteractive } = ctx;
const { filterPredicate } = this.options;
const printedType = this.options.printedType ?? 'branch';
const pageSize = this.options.pageSize ?? 100;
if (nonInteractive) {
throw new NonInteractiveError(
`${printedType} selection cannot be run in non-interactive mode.`
);
}
const queryAsync = async (
queryParams: QueryParams
): Promise<Connection<UpdateBranchBasicInfoFragment>> =>
filterPredicate
? this.filterQueryAsync(ctx, queryParams, filterPredicate)
: this.queryAsync(ctx, queryParams);
const getTitleAsync = async (branchInfo: UpdateBranchBasicInfoFragment): Promise<string> =>
branchInfo.name;
return await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
}
}
@@ -0,0 +1,92 @@
import { createCtxMock } from '../../../eas-update/__tests__/fixtures';
import { NonInteractiveError } from '../../../eas-update/utils';
import { UpdateBranchBasicInfoFragment } from '../../../graphql/generated';
import { BranchQuery } from '../../../graphql/queries/BranchQuery';
import { promptAsync } from '../../../prompts';
import { testBasicBranchInfo, testBasicBranchInfo2 } from '../../__tests__/fixtures';
import { SelectBranch } from '../SelectBranch';
jest.mock('../../../prompts');
jest.mock('../../../graphql/queries/BranchQuery');
describe(SelectBranch, () => {
afterEach(() => {
jest.clearAllMocks();
});
it('returns null if project has no branchs', async () => {
const ctx = createCtxMock();
jest.mocked(BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const selectBranch = new SelectBranch();
const branch = await selectBranch.runAsync(ctx);
expect(branch).toBeNull();
});
it('still prompts if project has only one branch', async () => {
const ctx = createCtxMock();
jest.mocked(BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [{ node: testBasicBranchInfo, cursor: 'cursor' }],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicBranchInfo,
}));
const selectBranch = new SelectBranch();
const branch = await selectBranch.runAsync(ctx);
expect(branch).toBe(testBasicBranchInfo);
expect(promptAsync).toHaveBeenCalledTimes(1);
});
it('returns the selected branch', async () => {
jest.mocked(BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [
{ node: testBasicBranchInfo, cursor: 'cursor' },
{ node: testBasicBranchInfo2, cursor: 'cursor' },
],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicBranchInfo,
}));
const ctx = createCtxMock();
const selectBranch = new SelectBranch();
const branch = await selectBranch.runAsync(ctx);
expect(branch).toBe(testBasicBranchInfo);
});
it('returns the only available branch with a filter', async () => {
jest.mocked(BranchQuery.listBranchesBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [
{ node: testBasicBranchInfo, cursor: 'cursor' },
{ node: testBasicBranchInfo2, cursor: 'cursor' },
],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const ctx = createCtxMock();
const selectBranch = new SelectBranch({
filterPredicate: (branchInfo: UpdateBranchBasicInfoFragment) =>
branchInfo === testBasicBranchInfo,
});
const branch = await selectBranch.runAsync(ctx);
expect(branch).toBe(testBasicBranchInfo);
});
it('throws an error in Non-Interactive Mode', async () => {
const ctx = createCtxMock({
nonInteractive: true,
});
const selectBranch = new SelectBranch();
// dont fail if users are running in non-interactive mode
await expect(selectBranch.runAsync(ctx)).rejects.toThrowError(NonInteractiveError);
});
});
+1 -2
View File
@@ -124,8 +124,7 @@ export async function prepareAndroidBuildAsync(
}
function shouldProvideCredentials(ctx: BuildContext<Platform.ANDROID>): boolean {
const isCustomBuild = ctx.buildProfile.config !== undefined;
return !ctx.buildProfile.withoutCredentials && !isCustomBuild;
return !ctx.buildProfile.withoutCredentials;
}
async function ensureAndroidCredentialsAsync(
+1
View File
@@ -55,4 +55,5 @@ export interface BuildContext<T extends Platform> {
customBuildConfigMetadata?: CustomBuildConfigMetadata;
android: T extends Platform.ANDROID ? AndroidBuildContext : undefined;
ios: T extends Platform.IOS ? IosBuildContext : undefined;
developmentClient: boolean;
}
@@ -60,6 +60,12 @@ export async function createBuildContextAsync<T extends Platform>({
const workflow = await resolveWorkflowAsync(projectDir, platform);
const accountId = account.id;
const runFromCI = getenv.boolish('CI', false);
const developmentClient =
buildProfile.developmentClient ??
(platform === Platform.ANDROID
? (buildProfile as BuildProfile<Platform.ANDROID>)?.gradleCommand === ':app:assembleDebug'
: (buildProfile as BuildProfile<Platform.IOS>)?.buildConfiguration === 'Debug') ??
false;
const credentialsCtx = new CredentialsContext({
projectInfo: { exp, projectId },
@@ -120,6 +126,7 @@ export async function createBuildContextAsync<T extends Platform>({
message,
runFromCI,
customBuildConfigMetadata,
developmentClient,
};
if (platform === Platform.ANDROID) {
const common = commonContext as CommonContext<Platform.ANDROID>;
@@ -55,6 +55,5 @@ export async function ensureIosCredentialsForBuildResignAsync(
}
function shouldProvideCredentials(buildCtx: BuildContext<Platform.IOS>): boolean {
const isCustomBuild = buildCtx.buildProfile.config !== undefined;
return !buildCtx.buildProfile.simulator && !isCustomBuild;
return !buildCtx.buildProfile.simulator && !buildCtx.buildProfile.withoutCredentials;
}
+1 -1
View File
@@ -6,7 +6,7 @@ import semver from 'semver';
import { ora } from '../ora';
const PLUGIN_PACKAGE_NAME = 'eas-cli-local-build-plugin';
const PLUGIN_PACKAGE_VERSION = '1.0.27';
const PLUGIN_PACKAGE_VERSION = '1.0.39';
export enum LocalBuildMode {
/**
+1
View File
@@ -63,6 +63,7 @@ export async function collectMetadataAsync<T extends Platform>(
runFromCI: ctx.runFromCI,
buildMode: ctx.buildProfile.config ? BuildMode.CUSTOM : BuildMode.BUILD,
customWorkflowName: ctx.customBuildConfigMetadata?.workflowName,
developmentClient: ctx.developmentClient,
};
return sanitizeMetadata(metadata);
}
@@ -1,3 +1,4 @@
import { ExpoConfig } from '@expo/config-types';
import { Platform, Workflow } from '@expo/eas-build-job';
import {
AppVersionSource,
@@ -13,6 +14,7 @@ import chalk from 'chalk';
import nullthrows from 'nullthrows';
import { Analytics } from '../analytics/AnalyticsManager';
import { createAndLinkChannelAsync, doesChannelExistAsync } from '../channel/queries';
import { DynamicConfigContextFn } from '../commandUtils/context/DynamicProjectConfigContextField';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
import {
@@ -38,9 +40,9 @@ import {
import { checkExpoSdkIsSupportedAsync } from '../project/expoSdk';
import { validateMetroConfigForManagedWorkflowAsync } from '../project/metroConfig';
import {
installExpoUpdatesAsync,
isExpoUpdatesInstalledAsDevDependency,
isExpoUpdatesInstalledOrAvailable,
isUsingEASUpdate,
validateAppVersionRuntimePolicySupportAsync,
} from '../project/projectUtils';
import {
@@ -57,6 +59,7 @@ import {
waitToCompleteAsync as waitForSubmissionsToCompleteAsync,
} from '../submit/submit';
import { printSubmissionDetailsUrls } from '../submit/utils/urls';
import { ensureEASUpdateIsConfiguredAsync } from '../update/configure';
import { validateBuildProfileConfigMatchesProjectConfigAsync } from '../update/utils';
import { Actor } from '../user/User';
import { downloadAndMaybeExtractAppAsync } from '../utils/download';
@@ -117,6 +120,7 @@ export async function runBuildAndSubmitAsync(
easJsonAccessor,
platforms,
profileName: flags.profile ?? undefined,
projectDir,
});
Log.log(
`Loaded "env" configuration for the "${buildProfiles[0].profileName}" profile: ${
@@ -183,6 +187,7 @@ export async function runBuildAndSubmitAsync(
platforms,
profileName: flags.submitProfile,
type: 'submit',
projectDir,
});
for (const startedBuild of startedBuilds) {
const submitProfile = nullthrows(
@@ -320,11 +325,26 @@ async function prepareAndStartBuildAsync({
);
if (buildProfile.profile.channel) {
await validateExpoUpdatesInstalledAsProjectDependencyAsync({
graphqlClient,
exp: buildCtx.exp,
projectId: buildCtx.projectId,
projectDir,
sdkVersion: buildCtx.exp.sdkVersion,
nonInteractive: flags.nonInteractive,
buildProfile,
});
if (isUsingEASUpdate(buildCtx.exp, buildCtx.projectId)) {
const doesChannelExist = await doesChannelExistAsync(graphqlClient, {
appId: buildCtx.projectId,
channelName: buildProfile.profile.channel,
});
if (!doesChannelExist) {
await createAndLinkChannelAsync(graphqlClient, {
appId: buildCtx.projectId,
channelName: buildProfile.profile.channel,
});
}
}
}
await validateAppVersionRuntimePolicySupportAsync(buildCtx.projectDir, buildCtx.exp);
@@ -447,11 +467,17 @@ async function maybeDownloadAndRunSimulatorBuildsAsync(
}
async function validateExpoUpdatesInstalledAsProjectDependencyAsync({
exp,
graphqlClient,
projectId,
projectDir,
buildProfile,
nonInteractive,
sdkVersion,
}: {
graphqlClient: ExpoGraphqlClient;
exp: ExpoConfig;
projectId: string;
projectDir: string;
buildProfile: ProfileData<'build'>;
nonInteractive: boolean;
@@ -467,18 +493,24 @@ async function validateExpoUpdatesInstalledAsProjectDependencyAsync({
);
} else if (nonInteractive) {
Log.warn(
`The build profile "${buildProfile.profileName}" has specified the channel "${buildProfile.profile.channel}", but the "expo-updates" package hasn't been installed. To use channels for your builds, install the "expo-updates" package by running "npx expo install expo-updates".`
`The build profile "${buildProfile.profileName}" has specified the channel "${buildProfile.profile.channel}", but the "expo-updates" package hasn't been installed. To use channels for your builds, install the "expo-updates" package by running "npx expo install expo-updates" followed by "eas update:configure".`
);
} else {
Log.warn(
`The build profile "${buildProfile.profileName}" specifies the channel "${buildProfile.profile.channel}", but the "expo-updates" package is missing. To use channels in your builds, install the "expo-updates" package.`
`The build profile "${buildProfile.profileName}" specifies the channel "${buildProfile.profile.channel}", but the "expo-updates" package is missing. To use channels in your builds, install the "expo-updates" package and run "eas update:configure".`
);
const installExpoUpdates = await confirmAsync({
message: `Would you like to install the "expo-updates" package?`,
message: `Would you like to install the "expo-updates" package and configure EAS Update now?`,
});
if (installExpoUpdates) {
await installExpoUpdatesAsync(projectDir, { silent: false });
Log.withTick('Installed expo-updates');
await ensureEASUpdateIsConfiguredAsync(graphqlClient, {
exp,
projectId,
projectDir,
platform: RequestedPlatform.All,
});
Log.withTick('Installed expo-updates and configured EAS Update.');
throw new Error('Command must be re-run to pick up new updates configuration.');
}
}
}
@@ -0,0 +1,22 @@
import { BranchBasicInfo, ChannelBasicInfo, UpdateChannelInfoWithBranches } from '../utils';
export const testChannelBasicInfo: ChannelBasicInfo = {
id: '9309afc2-9752-40db-8ef7-4abc10744c61',
name: 'production',
branchMapping:
'{"data":[{"branchId":"754bf17f-efc0-46ab-8a59-a03f20e53e9b","branchMappingLogic":{"operand":0.15,"clientKey":"rolloutToken","branchMappingOperator":"hash_lt"}},{"branchId":"6941a8dd-5c0a-48bc-8876-f49c88ed419f","branchMappingLogic":"true"}],"version":0}',
};
export const testBasicBranchInfo1: BranchBasicInfo = {
id: '754bf17f-efc0-46ab-8a59-a03f20e53e9b',
name: 'wrong-channel',
};
export const testBasicBranchInfo2: BranchBasicInfo = {
id: '6941a8dd-5c0a-48bc-8876-f49c88ed419f',
name: 'production',
};
export const channelInfoWithBranches: UpdateChannelInfoWithBranches<BranchBasicInfo> = {
...testChannelBasicInfo,
updateBranches: [testBasicBranchInfo1, testBasicBranchInfo2],
};
@@ -0,0 +1,70 @@
import {
emptyBranchMapping,
rolloutBranchMapping,
standardBranchMapping,
} from '../../rollout/__tests__/fixtures';
import {
BranchMappingValidationError,
assertVersion,
getAlwaysTrueBranchMapping,
getBranchMapping,
getEmptyBranchMapping,
getStandardBranchId,
isAlwaysTrueBranchMapping,
isEmptyBranchMapping,
} from '../branch-mapping';
import { testChannelBasicInfo } from './branch-mapping-fixtures';
describe(assertVersion, () => {
it('throws if the branch mapping is not the correct version', () => {
expect(() => assertVersion(testChannelBasicInfo, 5)).toThrowError(BranchMappingValidationError);
});
it('asserts the correct version', () => {
assertVersion(testChannelBasicInfo, 0);
expect(getBranchMapping(testChannelBasicInfo.branchMapping).version).toBe(0);
});
});
describe(getEmptyBranchMapping, () => {
it('gets an empty branch mapping', () => {
expect(isEmptyBranchMapping(getEmptyBranchMapping())).toBe(true);
});
});
describe(isEmptyBranchMapping, () => {
it('detects empty branch mappings', () => {
expect(isEmptyBranchMapping(emptyBranchMapping)).toBe(true);
expect(isEmptyBranchMapping(standardBranchMapping)).toBe(false);
expect(isEmptyBranchMapping(rolloutBranchMapping)).toBe(false);
});
});
describe(isAlwaysTrueBranchMapping, () => {
it('detects always true branch mappings', () => {
expect(isAlwaysTrueBranchMapping(standardBranchMapping)).toBe(true);
expect(isAlwaysTrueBranchMapping(rolloutBranchMapping)).toBe(false);
expect(isAlwaysTrueBranchMapping(emptyBranchMapping)).toBe(false);
});
});
describe(getAlwaysTrueBranchMapping, () => {
it('gets an always true branch mapping', () => {
const alwaysTrueBranchMapping = getAlwaysTrueBranchMapping('test-id');
expect(isAlwaysTrueBranchMapping(alwaysTrueBranchMapping)).toBe(true);
});
});
describe(getStandardBranchId, () => {
it('throws if the branch mapping is not a standard mapping', () => {
expect(() => getStandardBranchId(testChannelBasicInfo)).toThrowError(
BranchMappingValidationError
);
});
it('gets a standard branch id', () => {
const channelObjectWithStandardMapping = { ...testChannelBasicInfo };
channelObjectWithStandardMapping.branchMapping = JSON.stringify(standardBranchMapping);
expect(getStandardBranchId(channelObjectWithStandardMapping)).toBe(
standardBranchMapping.data[0].branchId
);
});
});
@@ -1,7 +1,7 @@
import { UpdateBranchWithCurrentGroupFragment } from '../../graphql/generated';
import { UpdateChannelObject } from '../../graphql/queries/ChannelQuery';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { UpdateBranchObject, UpdateChannelObject } from '../../graphql/queries/ChannelQuery';
export const testUpdateBranch1: UpdateBranchWithCurrentGroupFragment = {
export const testUpdateBranch1: UpdateBranchObject = {
id: '754bf17f-efc0-46ab-8a59-a03f20e53e9b',
name: 'wrong-channel',
updateGroups: [
@@ -61,7 +61,7 @@ export const testUpdateBranch1: UpdateBranchWithCurrentGroupFragment = {
__typename: 'UpdateBranch',
};
const testUpdateBranch2: UpdateBranchWithCurrentGroupFragment = {
export const testUpdateBranch2: UpdateBranchObject = {
id: '6941a8dd-5c0a-48bc-8876-f49c88ed419f',
name: 'production',
updateGroups: [
@@ -129,3 +129,19 @@ export const testChannelObject: UpdateChannelObject = {
updateBranches: [testUpdateBranch1, testUpdateBranch2],
__typename: 'UpdateChannel',
};
export const testBasicChannelInfo: UpdateChannelBasicInfoFragment = {
id: '9309afc2-9752-40db-8ef7-4abc10744c61',
name: 'production',
branchMapping:
'{"data":[{"branchId":"754bf17f-efc0-46ab-8a59-a03f20e53e9b","branchMappingLogic":{"operand":0.1,"clientKey":"rolloutToken","branchMappingOperator":"hash_lt"}},{"branchId":"6941a8dd-5c0a-48bc-8876-f49c88ed419f","branchMappingLogic":"true"}],"version":0}',
__typename: 'UpdateChannel',
};
export const testBasicChannelInfo2: UpdateChannelBasicInfoFragment = {
id: '9d5c7bf0-d52d-474c-9140-c1bad7f0de9d',
name: 'staging',
branchMapping:
'{"data":[{"branchId":"d7d68e32-d9c9-4a8d-8d1b-21e53100a5e8","branchMappingLogic":{"operand":0.1,"clientKey":"rolloutToken","branchMappingOperator":"hash_lt"}},{"branchId":"f9f708c2-0c91-4360-b2a4-0b61834aef4a","branchMappingLogic":"true"}],"version":0}',
__typename: 'UpdateChannel',
};
@@ -1,11 +1,11 @@
import { getUpdateBranch } from '../utils';
import { testChannelObject, testUpdateBranch1 } from './fixtures';
import { channelInfoWithBranches, testBasicBranchInfo1 } from './branch-mapping-fixtures';
describe(getUpdateBranch, () => {
it('gets the update branch', () => {
expect(getUpdateBranch(testChannelObject, '754bf17f-efc0-46ab-8a59-a03f20e53e9b')).toBe(
testUpdateBranch1
expect(getUpdateBranch(channelInfoWithBranches, '754bf17f-efc0-46ab-8a59-a03f20e53e9b')).toBe(
testBasicBranchInfo1
);
expect(() => getUpdateBranch(testChannelObject, 'not-a-branch-ID')).toThrow();
expect(() => getUpdateBranch(channelInfoWithBranches, 'not-a-branch-ID')).toThrow();
});
});
@@ -0,0 +1,107 @@
import { EASUpdateAction, EASUpdateContext, NonInteractiveError } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { ChannelQuery } from '../../graphql/queries/ChannelQuery';
import {
Connection,
Edge,
FilterPagination,
QueryParams,
selectPaginatedAsync,
} from '../../utils/relay';
/**
* Select a channel for the project.
*
* @constructor
* @param {function} options.filterPredicate - A predicate to filter the channels that are shown to the user. It takes a channelInfo object as a parameter and returns a boolean.
* @param {string} options.printedType - The type of channel printed to the user. Defaults to 'channel'.
* @param {number} options.pageSize - The number of channels to show per page. Defaults to 100.
* @param {function} options.beforeEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called before each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @param {function} options.afterEachFilterQuery Optional. If a filter predicate was specified, this callback function will be called after each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @args willFetchAgain If the query will fetch again to get a complete page.
*/
export class SelectChannel implements EASUpdateAction<UpdateChannelBasicInfoFragment | null> {
constructor(
private options: {
filterPredicate?: (channelInfo: UpdateChannelBasicInfoFragment) => boolean;
printedType?: string;
pageSize?: number;
beforeEachFilterQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<UpdateChannelBasicInfoFragment>[]
) => void;
afterEachFilterQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<UpdateChannelBasicInfoFragment>[],
willFetchAgain: boolean
) => void;
} = {}
) {}
async queryAsync(
ctx: EASUpdateContext,
queryParams: QueryParams
): Promise<Connection<UpdateChannelBasicInfoFragment>> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
return await ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync(graphqlClient, {
appId: projectId,
...queryParams,
});
}
async filterQueryAsync(
ctx: EASUpdateContext,
queryParams: QueryParams,
filterPredicate: (channelInfo: UpdateChannelBasicInfoFragment) => boolean
): Promise<Connection<UpdateChannelBasicInfoFragment>> {
const queryAsync = async (
queryParams: QueryParams
): Promise<Connection<UpdateChannelBasicInfoFragment>> =>
await this.queryAsync(ctx, queryParams);
return await FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery: this.options.beforeEachFilterQuery,
afterEachQuery: this.options.afterEachFilterQuery,
});
}
public async runAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment | null> {
const { nonInteractive } = ctx;
const { filterPredicate } = this.options;
const printedType = this.options.printedType ?? 'channel';
const pageSize = this.options.pageSize ?? 100;
if (nonInteractive) {
throw new NonInteractiveError(
`${printedType} selection cannot be run in non-interactive mode.`
);
}
const queryAsync = async (
queryParams: QueryParams
): Promise<Connection<UpdateChannelBasicInfoFragment>> =>
filterPredicate
? this.filterQueryAsync(ctx, queryParams, filterPredicate)
: this.queryAsync(ctx, queryParams);
const getTitleAsync = async (channelInfo: UpdateChannelBasicInfoFragment): Promise<string> =>
channelInfo.name;
return await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
}
}
@@ -0,0 +1,92 @@
import { createCtxMock } from '../../../eas-update/__tests__/fixtures';
import { NonInteractiveError } from '../../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../../graphql/generated';
import { ChannelQuery } from '../../../graphql/queries/ChannelQuery';
import { promptAsync } from '../../../prompts';
import { testBasicChannelInfo, testBasicChannelInfo2 } from '../../__tests__/fixtures';
import { SelectChannel } from '../SelectChannel';
jest.mock('../../../prompts');
jest.mock('../../../graphql/queries/ChannelQuery');
describe(SelectChannel, () => {
afterEach(() => {
jest.clearAllMocks();
});
it('returns null if project has no channels', async () => {
const ctx = createCtxMock();
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const selectChannel = new SelectChannel();
const channel = await selectChannel.runAsync(ctx);
expect(channel).toBeNull();
});
it('still prompts if project has only one channel', async () => {
const ctx = createCtxMock();
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [{ node: testBasicChannelInfo, cursor: 'cursor' }],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicChannelInfo,
}));
const selectChannel = new SelectChannel();
const channel = await selectChannel.runAsync(ctx);
expect(channel).toBe(testBasicChannelInfo);
expect(promptAsync).toHaveBeenCalledTimes(1);
});
it('returns the selected channel', async () => {
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [
{ node: testBasicChannelInfo, cursor: 'cursor' },
{ node: testBasicChannelInfo2, cursor: 'cursor' },
],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicChannelInfo,
}));
const ctx = createCtxMock();
const selectChannel = new SelectChannel();
const channel = await selectChannel.runAsync(ctx);
expect(channel).toBe(testBasicChannelInfo);
});
it('returns the only available channel with a filter', async () => {
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [
{ node: testBasicChannelInfo, cursor: 'cursor' },
{ node: testBasicChannelInfo2, cursor: 'cursor' },
],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const ctx = createCtxMock();
const selectChannel = new SelectChannel({
filterPredicate: (channelInfo: UpdateChannelBasicInfoFragment) =>
channelInfo === testBasicChannelInfo,
});
const channel = await selectChannel.runAsync(ctx);
expect(channel).toBe(testBasicChannelInfo);
});
it('throws an error in Non-Interactive Mode', async () => {
const ctx = createCtxMock({
nonInteractive: true,
});
const selectChannel = new SelectChannel();
// dont fail if users are running in non-interactive mode
await expect(selectChannel.runAsync(ctx)).rejects.toThrowError(NonInteractiveError);
});
});
+135 -6
View File
@@ -1,4 +1,4 @@
import assert from 'assert';
import { ChannelBasicInfo } from './utils';
// TODO(quin): move this into a common package with www
export type BranchMappingOperator =
@@ -35,6 +35,89 @@ export type BranchMapping = {
}[];
};
export type AlwaysTrueBranchMapping = {
version: number;
data: [
{
branchId: string;
branchMappingLogic: BranchMappingAlwaysTrue;
}
];
};
export type EmptyBranchMapping = {
version: number;
data: [];
};
export function getEmptyBranchMapping(): EmptyBranchMapping {
return {
version: 0,
data: [],
};
}
export function getAlwaysTrueBranchMapping(branchId: string): AlwaysTrueBranchMapping {
return {
version: 0,
data: [
{
branchId,
branchMappingLogic: 'true',
},
],
};
}
export function hasEmptyBranchMap(channelInfo: ChannelBasicInfo): boolean {
const branchMapping = getBranchMapping(channelInfo.branchMapping);
return isEmptyBranchMapping(branchMapping);
}
export function hasStandardBranchMap(channelInfo: ChannelBasicInfo): boolean {
const branchMapping = getBranchMapping(channelInfo.branchMapping);
return isAlwaysTrueBranchMapping(branchMapping);
}
export function getStandardBranchId(channelInfo: ChannelBasicInfo): string {
const branchMapping = getBranchMapping(channelInfo.branchMapping);
assertAlwaysTrueBranchMapping(branchMapping);
return getBranchIdFromStandardMapping(branchMapping);
}
export function isEmptyBranchMapping(
branchMapping: BranchMapping
): branchMapping is EmptyBranchMapping {
return branchMapping.data.length === 0;
}
export function isAlwaysTrueBranchMapping(
branchMapping: BranchMapping
): branchMapping is AlwaysTrueBranchMapping {
const numBranches = branchMapping.data.length;
if (numBranches !== 1) {
return false;
}
const branchMappingLogic = branchMapping.data[0].branchMappingLogic;
return isAlwaysTrue(branchMappingLogic);
}
function getBranchIdFromStandardMapping(branchMapping: AlwaysTrueBranchMapping): string {
return branchMapping.data[0].branchId;
}
export function getBranchIds(branchMapping: BranchMapping): string[] {
return branchMapping.data.map(data => data.branchId);
}
export function getBranchMapping(branchMappingString: string): BranchMapping {
try {
return JSON.parse(branchMappingString);
} catch {
throw new Error(`Could not parse branchMapping string into a JSON: "${branchMappingString}"`);
}
}
export function getNodesFromStatement(statement: BranchMappingStatement): BranchMappingNode[] {
return statement.slice(1) as BranchMappingNode[];
}
@@ -73,13 +156,59 @@ export function hashLtOperator(): BranchMappingOperator {
return 'hash_lt';
}
function isVersion(branchMapping: BranchMapping, version: number): boolean {
return branchMapping.version === version;
}
export function assertVersion(channelInfo: ChannelBasicInfo, version: number): void {
const branchMapping = getBranchMapping(channelInfo.branchMapping);
if (!isVersion(branchMapping, version)) {
throw new BranchMappingValidationError(
`Expected branch mapping version ${version}. Received: ${JSON.stringify(branchMapping)}`
);
}
}
export function assertStatement(node: BranchMappingNode): asserts node is BranchMappingStatement {
if (!isStatement(node)) {
throw new BranchMappingValidationError(
'Branch mapping node must be a statement. Received: ' + JSON.stringify(node)
);
}
}
export function assertNodeObject(node: BranchMappingNode): asserts node is BranchMappingObject {
assert(
isNodeObject(node),
'Branch mapping node must be an object. Received: ' + JSON.stringify(node)
);
if (!isNodeObject(node)) {
throw new BranchMappingValidationError(
'Branch mapping node must be an object. Received: ' + JSON.stringify(node)
);
}
}
export function assertNumber(operand: string | number | string[]): asserts operand is number {
assert(typeof operand === 'number', 'Expected a number. Received: ' + JSON.stringify(operand));
if (typeof operand !== 'number') {
throw new BranchMappingValidationError(
'Expected a number. Received: ' + JSON.stringify(operand)
);
}
}
export function assertString(operand: string | number | string[]): asserts operand is string {
if (typeof operand !== 'string') {
throw new BranchMappingValidationError(
'Expected a string. Received: ' + JSON.stringify(operand)
);
}
}
function assertAlwaysTrueBranchMapping(
branchMapping: BranchMapping
): asserts branchMapping is AlwaysTrueBranchMapping {
if (!isAlwaysTrueBranchMapping(branchMapping)) {
throw new BranchMappingValidationError(
'Expected standard branch mapping. Received: ' + JSON.stringify(branchMapping)
);
}
}
export class BranchMappingValidationError extends Error {}
@@ -0,0 +1,52 @@
import assert from 'assert';
import chalk from 'chalk';
import { UpdateChannelObject } from '../graphql/queries/ChannelQuery';
import Log from '../log';
import { getRollout, isRollout } from '../rollout/branch-mapping';
import {
FormattedBranchDescription,
formatBranch,
getUpdateGroupDescriptionsWithBranch,
} from '../update/utils';
import { assertVersion, hasEmptyBranchMap, hasStandardBranchMap } from './branch-mapping';
export function logChannelDetails(channel: UpdateChannelObject): void {
assertVersion(channel, 0);
assert(
hasEmptyBranchMap(channel) || hasStandardBranchMap(channel) || isRollout(channel),
'Only standard branch mappings and rollouts are supported.'
);
const branchDescription = channel.updateBranches.flatMap(branch => {
const updateGroupWithBranchDescriptions = getUpdateGroupDescriptionsWithBranch(
branch.updateGroups
);
const maybeRollout = isRollout(channel) ? getRollout(channel) : null;
let maybePercentOnBranch: number | undefined = undefined;
if (maybeRollout) {
maybePercentOnBranch =
maybeRollout.rolledOutBranchId === branch.id
? maybeRollout.percentRolledOut
: 100 - maybeRollout.percentRolledOut;
}
return updateGroupWithBranchDescriptions.map(
({ branch, ...updateGroup }): FormattedBranchDescription => ({
branch,
branchRolloutPercentage: maybePercentOnBranch,
update: updateGroup,
})
);
});
if (branchDescription.length === 0) {
Log.log(chalk.dim('No branches are pointed to this channel.'));
} else {
Log.log(
branchDescription
.map(description => formatBranch(description))
.join(`\n\n${chalk.dim('———')}\n\n`)
);
}
}
+104 -1
View File
@@ -2,6 +2,8 @@ import chalk from 'chalk';
import { print } from 'graphql';
import gql from 'graphql-tag';
import { createUpdateBranchOnAppAsync } from '../branch/queries';
import { BranchNotFoundError } from '../branch/utils';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
import { PaginatedQueryOptions } from '../commandUtils/pagination';
import { withErrorHandlingAsync } from '../graphql/client';
@@ -15,13 +17,16 @@ import { BranchQuery, UpdateBranchOnChannelObject } from '../graphql/queries/Bra
import { ChannelQuery, UpdateChannelObject } from '../graphql/queries/ChannelQuery';
import { UpdateChannelBasicInfoFragmentNode } from '../graphql/types/UpdateChannelBasicInfo';
import Log from '../log';
import { getDisplayNameForProjectIdAsync } from '../project/projectUtils';
import formatFields from '../utils/formatFields';
import { printJsonOnlyOutput } from '../utils/json';
import {
paginatedQueryWithConfirmPromptAsync,
paginatedQueryWithSelectPromptAsync,
} from '../utils/queries';
import { logChannelDetails } from './utils';
import { ChannelNotFoundError } from './errors';
import { logChannelDetails } from './print-utils';
import { ChannelBasicInfo } from './utils';
export const CHANNELS_LIMIT = 25;
@@ -264,3 +269,101 @@ export async function ensureChannelExistsAsync(
}
}
}
export async function doesChannelExistAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, channelName }: { appId: string; channelName: string }
): Promise<boolean> {
try {
await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId,
channelName,
});
} catch (err) {
if (err instanceof ChannelNotFoundError) {
return false;
}
throw err;
}
return true;
}
/**
*
* Creates a channel and links it to a branch with the same name.
*
* @param appId the app ID, also known as the project ID
* @param channelName the name of the channel to create
* @param shouldPrintJson print only the JSON output
*/
export async function createAndLinkChannelAsync(
graphqlClient: ExpoGraphqlClient,
{
appId,
channelName,
shouldPrintJson,
}: { appId: string; channelName: string; shouldPrintJson?: boolean }
): Promise<ChannelBasicInfo> {
let branchId: string;
let branchMessage: string;
try {
const branch = await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId,
name: channelName,
});
branchId = branch.id;
branchMessage = `We found a branch with the same name`;
} catch (error) {
if (error instanceof BranchNotFoundError) {
const newBranch = await createUpdateBranchOnAppAsync(graphqlClient, {
appId,
name: channelName,
});
branchId = newBranch.id;
branchMessage = `We also went ahead and made a branch with the same name`;
} else {
throw error;
}
}
const {
updateChannel: { createUpdateChannelForApp: newChannel },
} = await createChannelOnAppAsync(graphqlClient, {
appId,
channelName,
branchId,
});
if (!newChannel) {
throw new Error(
`Could not create channel with name ${channelName} on project with id ${appId}`
);
}
if (shouldPrintJson) {
printJsonOnlyOutput(newChannel);
} else {
Log.addNewLineIfNone();
Log.withTick(
`Created a new channel on project ${chalk.bold(
await getDisplayNameForProjectIdAsync(graphqlClient, appId)
)}`
);
Log.log(
formatFields([
{ label: 'Name', value: newChannel.name },
{ label: 'ID', value: newChannel.id },
])
);
Log.addNewLineIfNone();
Log.withTick(`${branchMessage} and have pointed the channel at it.`);
Log.log(
formatFields([
{ label: 'Name', value: newChannel.name },
{ label: 'ID', value: branchId },
])
);
}
return newChannel;
}
+18 -117
View File
@@ -1,129 +1,30 @@
import assert from 'assert';
import chalk from 'chalk';
export type ChannelBasicInfo = {
id: string;
name: string;
branchMapping: string;
};
export type BranchBasicInfo = {
id: string;
name: string;
};
import { UpdateBranchWithCurrentGroupFragment } from '../graphql/generated';
import { UpdateChannelObject } from '../graphql/queries/ChannelQuery';
import Log from '../log';
import {
FormattedBranchDescription,
formatBranch,
getUpdateGroupDescriptionsWithBranch,
} from '../update/utils';
import { BranchMapping, assertNodeObject, assertNumber, isNodeObject } from './branch-mapping';
export type UpdateChannelInfoWithBranches<Branch extends BranchBasicInfo> = ChannelBasicInfo & {
updateBranches: Branch[];
};
/**
* Get the branch mapping and determine whether it is a rollout.
* Ensure that the branch mapping is properly formatted.
*/
export function getBranchMapping(branchMappingString?: string): {
branchMapping: BranchMapping;
isRollout: boolean;
rolloutPercent?: number;
} {
if (!branchMappingString) {
throw new Error('Missing branch mapping.');
}
let branchMapping: BranchMapping;
try {
branchMapping = JSON.parse(branchMappingString);
} catch {
throw new Error(`Could not parse branchMapping string into a JSON: "${branchMappingString}"`);
}
assert(branchMapping, 'Branch Mapping must be defined.');
if (branchMapping.version !== 0) {
throw new Error('Branch mapping must be version 0.');
}
const isRollout = branchMapping.data.length === 2;
const branchMappingNode = branchMapping.data[0]?.branchMappingLogic;
let rolloutPercent: number | undefined;
if (isNodeObject(branchMappingNode)) {
assertNumber(branchMappingNode.operand);
rolloutPercent = branchMappingNode.operand;
}
switch (branchMapping.data.length) {
case 0:
break;
case 1:
if (branchMapping.data[0].branchMappingLogic !== 'true') {
throw new Error('Branch mapping logic for a single branch must be "true"');
}
break;
case 2:
assertNodeObject(branchMappingNode);
if (branchMappingNode.clientKey !== 'rolloutToken') {
throw new Error('Client key of initial branch mapping must be "rolloutToken"');
}
if (branchMappingNode.branchMappingOperator !== 'hash_lt') {
throw new Error('Branch mapping operator of initial branch mapping must be "hash_lt"');
}
if (rolloutPercent == null) {
throw new Error('Branch mapping is missing a "rolloutPercent"');
}
if (branchMapping.data[1].branchMappingLogic !== 'true') {
throw new Error('Branch mapping logic for a the second branch of a rollout must be "true"');
}
break;
default:
throw new Error('Branch mapping data must have length less than or equal to 2.');
}
return { branchMapping, isRollout, rolloutPercent };
}
export function logChannelDetails(channel: UpdateChannelObject): void {
const { branchMapping, isRollout, rolloutPercent } = getBranchMapping(channel.branchMapping);
if (branchMapping.data.length > 2) {
throw new Error('Branch Mapping data must have length less than or equal to 2.');
}
const rolloutBranchIds = branchMapping.data.map(data => data.branchId);
const branchDescription = channel.updateBranches.flatMap(branch => {
const updateGroupWithBranchDescriptions = getUpdateGroupDescriptionsWithBranch(
branch.updateGroups
);
const isRolloutBranch = isRollout && rolloutBranchIds.includes(branch.id);
const isBaseBranch = rolloutBranchIds.length > 0 && rolloutBranchIds[0] === branch.id;
let rolloutPercentNumber: number | undefined = undefined;
if (isRolloutBranch) {
rolloutPercentNumber = isBaseBranch ? rolloutPercent! * 100 : (1 - rolloutPercent!) * 100;
}
return updateGroupWithBranchDescriptions.map(
({ branch, ...updateGroup }): FormattedBranchDescription => ({
branch,
branchRolloutPercentage: rolloutPercentNumber,
update: updateGroup,
})
);
});
if (branchDescription.length === 0) {
Log.log(chalk.dim('No branches are pointed to this channel.'));
} else {
Log.log(
branchDescription
.map(description => formatBranch(description))
.join(`\n\n${chalk.dim('———')}\n\n`)
);
}
}
function getUpdateBranchNullable(
channel: UpdateChannelObject,
function getUpdateBranchNullable<Branch extends BranchBasicInfo>(
channel: UpdateChannelInfoWithBranches<Branch>,
branchId: string
): UpdateBranchWithCurrentGroupFragment | null {
): Branch | null {
const updateBranches = channel.updateBranches;
const updateBranch = updateBranches.find(branch => branch.id === branchId);
return updateBranch ?? null;
}
export function getUpdateBranch(
channel: UpdateChannelObject,
export function getUpdateBranch<Branch extends BranchBasicInfo>(
channel: UpdateChannelInfoWithBranches<Branch>,
branchId: string
): UpdateBranchWithCurrentGroupFragment {
): Branch {
const updateBranch = getUpdateBranchNullable(channel, branchId);
if (!updateBranch) {
throw new Error(
@@ -68,6 +68,7 @@ export default class BuildVersionGetView extends EasCommand {
easJsonAccessor,
platforms,
profileName: flags.profile ?? undefined,
projectDir,
});
const results: { [key in Platform]?: string } = {};
for (const { profile, platform } of buildProfiles) {
@@ -80,6 +80,7 @@ export default class BuildVersionSyncView extends EasCommand {
easJsonAccessor,
platforms,
profileName: flags.profile ?? undefined,
projectDir,
});
for (const profileInfo of buildProfiles) {
const { exp, projectId } = await getDynamicPrivateProjectConfigAsync({
@@ -1,16 +1,11 @@
import chalk from 'chalk';
import { createUpdateBranchOnAppAsync } from '../../branch/queries';
import { BranchNotFoundError } from '../../branch/utils';
import { createChannelOnAppAsync } from '../../channel/queries';
import { createAndLinkChannelAsync } from '../../channel/queries';
import EasCommand from '../../commandUtils/EasCommand';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { BranchQuery } from '../../graphql/queries/BranchQuery';
import Log from '../../log';
import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils';
import { promptAsync } from '../../prompts';
import formatFields from '../../utils/formatFields';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
import { enableJsonOutput } from '../../utils/json';
export default class ChannelCreate extends EasCommand {
static override description = 'create a channel';
@@ -60,69 +55,13 @@ export default class ChannelCreate extends EasCommand {
}));
}
let branchId: string;
let branchMessage: string;
try {
const branch = await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId: projectId,
name: channelName,
});
branchId = branch.id;
branchMessage = `We found a branch with the same name`;
} catch (error) {
if (error instanceof BranchNotFoundError) {
const newBranch = await createUpdateBranchOnAppAsync(graphqlClient, {
appId: projectId,
name: channelName,
});
branchId = newBranch.id;
branchMessage = `We also went ahead and made a branch with the same name`;
} else {
throw error;
}
}
const {
updateChannel: { createUpdateChannelForApp: newChannel },
} = await createChannelOnAppAsync(graphqlClient, {
await createAndLinkChannelAsync(graphqlClient, {
appId: projectId,
channelName,
branchId,
shouldPrintJson: jsonFlag,
});
if (!newChannel) {
throw new Error(
`Could not create channel with name ${channelName} on project with id ${projectId}`
);
}
if (jsonFlag) {
printJsonOnlyOutput(newChannel);
} else {
Log.addNewLineIfNone();
Log.withTick(
`Created a new channel on project ${chalk.bold(
await getDisplayNameForProjectIdAsync(graphqlClient, projectId)
)}`
);
Log.log(
formatFields([
{ label: 'Name', value: newChannel.name },
{ label: 'ID', value: newChannel.id },
])
);
Log.addNewLineIfNone();
Log.withTick(`${branchMessage} and have pointed the channel at it.`);
Log.log(
formatFields([
{ label: 'Name', value: newChannel.name },
{ label: 'ID', value: branchId },
])
);
Log.addNewLineIfNone();
Log.log(chalk.bold('You can now update your app by publishing!'));
}
Log.addNewLineIfNone();
Log.log(chalk.bold('You can now update your app by publishing!'));
}
}
@@ -4,6 +4,7 @@ import { print } from 'graphql';
import gql from 'graphql-tag';
import { selectBranchOnAppAsync } from '../../branch/queries';
import { hasEmptyBranchMap, hasStandardBranchMap } from '../../channel/branch-mapping';
import { selectChannelOnAppAsync } from '../../channel/queries';
import EasCommand from '../../commandUtils/EasCommand';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
@@ -18,6 +19,7 @@ import { BranchQuery } from '../../graphql/queries/BranchQuery';
import { ChannelQuery } from '../../graphql/queries/ChannelQuery';
import { UpdateChannelBasicInfoFragmentNode } from '../../graphql/types/UpdateChannelBasicInfo';
import Log from '../../log';
import { isRollout } from '../../rollout/branch-mapping';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
export async function updateChannelBranchMappingAsync(
@@ -98,8 +100,10 @@ export default class ChannelEdit extends EasCommand {
paginatedQueryOptions: { json, nonInteractive, offset: 0 },
});
if (existingChannel.updateBranches.length > 1) {
if (isRollout(existingChannel)) {
throw new Error('There is a rollout in progress. Manage it with "channel:rollout" instead.');
} else if (!hasStandardBranchMap(existingChannel) && !hasEmptyBranchMap(existingChannel)) {
throw new Error('Only standard branch mappings can be edited with this command.');
}
const branch = branchFlag
+141 -448
View File
@@ -1,306 +1,49 @@
import { Flags } from '@oclif/core';
import chalk from 'chalk';
import { selectBranchOnAppAsync } from '../../branch/queries';
import {
BranchMapping,
BranchMappingObject,
assertNodeObject,
assertNumber,
} from '../../channel/branch-mapping';
import { selectChannelOnAppAsync } from '../../channel/queries';
import { getBranchMapping } from '../../channel/utils';
import EasCommand from '../../commandUtils/EasCommand';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { UpdateBranch } from '../../graphql/generated';
import { BranchQuery } from '../../graphql/queries/BranchQuery';
import { ChannelQuery, UpdateChannelObject } from '../../graphql/queries/ChannelQuery';
import Log from '../../log';
import { getDisplayNameForProjectIdAsync } from '../../project/projectUtils';
import { promptAsync, selectAsync } from '../../prompts';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
import { updateChannelBranchMappingAsync } from './edit';
import { NonInteractiveOptions as CreateRolloutNonInteractiveOptions } from '../../rollout/actions/CreateRollout';
import { NonInteractiveOptions as EditRolloutNonInteractiveOptions } from '../../rollout/actions/EditRollout';
import {
EndOutcome,
GeneralOptions as EndRolloutGeneralOptions,
NonInteractiveOptions as EndRolloutNonInteractiveOptions,
} from '../../rollout/actions/EndRollout';
import { ManageRolloutActions } from '../../rollout/actions/ManageRollout';
import { NonInteractiveRollout } from '../../rollout/actions/NonInteractiveRollout';
import {
MainMenuActions,
RolloutActions,
RolloutMainMenu,
} from '../../rollout/actions/RolloutMainMenu';
async function promptForRolloutPercentAsync({
promptMessage,
}: {
promptMessage: string;
}): Promise<number> {
const { name: rolloutPercent } = await promptAsync({
type: 'text',
name: 'name',
format: value => {
return parseInt(value, 10);
},
message: promptMessage,
initial: 0,
validate: (rolloutPercent: string): true | string => {
const floatValue = parseFloat(rolloutPercent);
return Number.isInteger(floatValue) && floatValue >= 0 && floatValue <= 100
? true
: 'The rollout percentage must be an integer between 0 and 100 inclusive.';
},
});
return rolloutPercent;
enum ActionRawFlagValue {
CREATE = 'create',
EDIT = 'edit',
END = 'end',
}
type ChannelRolloutRawArgsAndFlags = {
channel?: string;
action?: ActionRawFlagValue;
percent?: number;
outcome?: EndOutcome;
'non-interactive': boolean;
branch?: string;
'runtime-version'?: string;
'private-key-path'?: string;
json?: boolean;
};
function getRolloutInfo(channel: UpdateChannelObject): {
newBranch: Pick<UpdateBranch, 'name' | 'id'>;
oldBranch: Pick<UpdateBranch, 'name' | 'id'>;
currentPercent: number;
} {
const { branchMapping } = getBranchMapping(channel.branchMapping);
const [newBranchId, oldBranchId] = branchMapping.data.map(d => d.branchId);
const newBranch = channel.updateBranches.filter(branch => branch.id === newBranchId)[0];
const oldBranch = channel.updateBranches.filter(branch => branch.id === oldBranchId)[0];
if (!newBranch || !oldBranch) {
throw new Error(`Branch mapping rollout is missing a branch for channel "${channel.name}".`);
}
const branchMappingNode = branchMapping.data[0]?.branchMappingLogic;
assertNodeObject(branchMappingNode);
assertNumber(branchMappingNode.operand);
const currentPercent = 100 * branchMappingNode.operand;
return { newBranch, oldBranch, currentPercent };
}
async function startRolloutAsync(
graphqlClient: ExpoGraphqlClient,
{
channelName,
branchName,
percent,
projectId,
displayName,
currentBranchMapping,
channel,
nonInteractive,
}: {
channelName?: string;
branchName: string;
percent?: number;
projectId: string;
displayName: string;
currentBranchMapping: BranchMapping;
channel: UpdateChannelObject;
nonInteractive: boolean;
}
): Promise<{
newChannelInfo: {
id: string;
name: string;
branchMapping: string;
};
logMessage: string;
}> {
const branch = await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId: projectId,
name: branchName,
});
const oldBranchId = currentBranchMapping.data[0].branchId;
if (branch.id === oldBranchId) {
throw new Error(
`channel "${channelName}" is already pointing at branch "${branchName}". Rollouts must be done with distinct branches.`
);
}
if (percent == null) {
if (nonInteractive) {
throw new Error(
'You must specify a percent with the --percent flag when initiating a rollout with the --non-interactive flag.'
);
}
const promptMessage = `What percent of users should be directed to the branch "${branchName}"?`;
percent = await promptForRolloutPercentAsync({ promptMessage });
}
const newBranchMapping = {
version: 0,
data: [
{
branchId: branch.id,
branchMappingLogic: {
operand: percent / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_lt',
},
},
currentBranchMapping.data[0],
],
};
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: channel.id,
branchMapping: JSON.stringify(newBranchMapping),
});
const oldBranch = channel.updateBranches.filter(branch => branch.id === oldBranchId)[0];
if (!oldBranch) {
throw new Error(
`Branch mapping is missing its only branch for channel "${channelName}" on app "${displayName}"`
);
}
const logMessage = `Started a rollout of branch ${chalk.bold(branchName)} on channel ${chalk.bold(
channelName!
)}! ${chalk.bold(percent)}% of users will be directed to branch ${chalk.bold(
branchName
)}, ${chalk.bold(100 - percent)}% to branch ${chalk.bold(oldBranch.name)}.`;
return { newChannelInfo, logMessage };
}
async function editRolloutAsync(
graphqlClient: ExpoGraphqlClient,
{
channelName,
percent,
nonInteractive,
currentBranchMapping,
channel,
}: {
channelName?: string;
percent?: number;
nonInteractive: boolean;
currentBranchMapping: BranchMapping;
channel: UpdateChannelObject;
}
): Promise<{
newChannelInfo: {
id: string;
name: string;
branchMapping: string;
};
logMessage: string;
}> {
const { newBranch, oldBranch, currentPercent } = getRolloutInfo(channel);
if (percent == null) {
if (nonInteractive) {
throw new Error(
'A rollout is already in progress. If you wish to modify it you must use specify the new rollout percentage with the --percent flag.'
);
}
const promptMessage = `Currently ${currentPercent}% of all users are routed to branch ${
newBranch.name
} and ${100 - currentPercent}% of all users are routed to branch ${
oldBranch.name
}. What percent of users should be directed to the branch ${newBranch.name}?`;
percent = await promptForRolloutPercentAsync({ promptMessage });
}
const newBranchMapping = { ...currentBranchMapping };
(newBranchMapping.data[0].branchMappingLogic as BranchMappingObject).operand = percent / 100;
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: channel.id,
branchMapping: JSON.stringify(newBranchMapping),
});
const logMessage = `Rollout of branch ${chalk.bold(newBranch.name)} on channel ${chalk.bold(
channelName!
)} updated from ${chalk.bold(currentPercent)}% to ${chalk.bold(percent)}%. ${chalk.bold(
percent
)}% of users will be directed to branch ${chalk.bold(newBranch.name)}, ${chalk.bold(
100 - percent
)}% to branch ${chalk.bold(oldBranch.name)}.`;
return { newChannelInfo, logMessage };
}
async function endRolloutAsync(
graphqlClient: ExpoGraphqlClient,
{
channelName,
branchName,
nonInteractive,
projectId,
channel,
}: {
channelName?: string;
branchName?: string;
nonInteractive: boolean;
projectId: string;
channel: UpdateChannelObject;
}
): Promise<{
newChannelInfo: {
id: string;
name: string;
branchMapping: string;
};
logMessage: string;
}> {
// end rollout
const { newBranch, oldBranch, currentPercent } = getRolloutInfo(channel);
let endOnNewBranch;
if (branchName) {
const branch = await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId: projectId,
name: branchName,
});
switch (branch.id) {
case newBranch.id:
endOnNewBranch = true;
break;
case oldBranch.id:
endOnNewBranch = false;
break;
default:
throw new Error(
`The branch "${branchName}" specified by --branch must be one of the branches involved in the rollout: "${newBranch.name}" or "${oldBranch.name}".`
);
}
} else {
if (nonInteractive) {
throw new Error(
'Branch name must be specified with the --branch flag when both the --end and --non-interactive flag are true.'
);
}
endOnNewBranch = await selectAsync<boolean>(
'Ending the rollout will send all traffic to a single branch. Which one should that be?',
[
{
title: `${newBranch.name} ${chalk.grey(`- current percent: ${currentPercent}%`)}`,
value: true,
},
{
title: `${oldBranch.name} ${chalk.grey(`- current percent: ${100 - currentPercent}%`)}`,
value: false,
},
]
);
}
if (endOnNewBranch == null) {
throw new Error('Branch to end on is undefined.');
}
const newBranchMapping = {
version: 0,
data: [
{
branchId: endOnNewBranch ? newBranch.id : oldBranch.id,
branchMappingLogic: 'true',
},
],
};
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: channel.id,
branchMapping: JSON.stringify(newBranchMapping),
});
const logMessage = `Rollout on channel ${chalk.bold(
channelName
)} ended. All traffic is now sent to branch ${chalk.bold(
endOnNewBranch ? newBranch.name : oldBranch.name
)}`;
return { newChannelInfo, logMessage };
}
type ChannelRolloutArgsAndFlags = {
channelName?: string;
action?: RolloutActions;
nonInteractive: boolean;
json?: boolean;
} & Partial<EditRolloutNonInteractiveOptions> &
Partial<EndRolloutNonInteractiveOptions> &
EndRolloutGeneralOptions &
Partial<CreateRolloutNonInteractiveOptions>;
export default class ChannelRollout extends EasCommand {
static override description = 'Roll a new branch out on a channel incrementally.';
@@ -313,17 +56,68 @@ export default class ChannelRollout extends EasCommand {
];
static override flags = {
branch: Flags.string({
description: 'branch to rollout',
action: Flags.enum({
description: 'Rollout action to perform',
options: Object.values(ActionRawFlagValue),
required: false,
relationships: [
{
type: 'all',
flags: [
{
name: 'percent',
// eslint-disable-next-line async-protect/async-suffix
when: async flags => {
return (
!!flags['non-interactive'] &&
(flags['action'] === ActionRawFlagValue.CREATE ||
flags['action'] === ActionRawFlagValue.EDIT)
);
},
},
{
name: 'outcome',
// eslint-disable-next-line async-protect/async-suffix
when: async flags =>
!!flags['non-interactive'] && flags['action'] === ActionRawFlagValue.END,
},
{
name: 'branch',
// eslint-disable-next-line async-protect/async-suffix
when: async flags =>
!!flags['non-interactive'] && flags['action'] === ActionRawFlagValue.CREATE,
},
{
name: 'runtime-version',
// eslint-disable-next-line async-protect/async-suffix
when: async flags =>
!!flags['non-interactive'] && flags['action'] === ActionRawFlagValue.CREATE,
},
],
},
],
}),
percent: Flags.integer({
description: 'percent of users to send to the new branch',
description:
'Percent of users to send to the new branch. Use with --action=edit or --action=create',
required: false,
}),
end: Flags.boolean({
description: 'end the rollout',
default: false,
outcome: Flags.enum({
description: 'End outcome of rollout. Use with --action=end',
options: Object.values(EndOutcome),
required: false,
}),
branch: Flags.string({
description: 'Branch to roll out. Use with --action=create',
required: false,
}),
'runtime-version': Flags.string({
description: 'Runtime version to target. Use with --action=create',
required: false,
}),
'private-key-path': Flags.string({
description: `File containing the PEM-encoded private key corresponding to the certificate in expo-updates' configuration. Defaults to a file named "private-key.pem" in the certificate's directory.`,
required: false,
}),
...EasNonInteractiveAndJsonFlags,
};
@@ -334,164 +128,63 @@ export default class ChannelRollout extends EasCommand {
};
async runAsync(): Promise<void> {
const { args, flags } = await this.parse(ChannelRollout);
const argsAndFlags = this.sanitizeArgsAndFlags({ ...flags, ...args });
const {
args: { channel: channelNameArg },
flags: {
json: jsonFlag,
end: endFlag,
branch: branchName,
percent,
'non-interactive': nonInteractive,
},
} = await this.parse(ChannelRollout);
const {
privateProjectConfig: { projectId },
privateProjectConfig: { exp, projectId },
loggedIn: { graphqlClient },
} = await this.getContextAsync(ChannelRollout, {
nonInteractive,
nonInteractive: argsAndFlags.nonInteractive,
});
if (jsonFlag) {
enableJsonOutput();
if (argsAndFlags.json) {
// TODO(quin): implement json output
throw new Error('Developer Preview doesnt support JSON output yet');
}
const projectDisplayName = await getDisplayNameForProjectIdAsync(graphqlClient, projectId);
let channelName: string = channelNameArg;
if (!channelName) {
const { name } = await selectChannelOnAppAsync(graphqlClient, {
projectId,
selectionPromptTitle: 'Select a channel on which to perform a rollout',
paginatedQueryOptions: {
json: jsonFlag,
nonInteractive,
offset: 0,
},
});
channelName = name;
}
const channel = await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName,
});
if (!channel) {
throw new Error(
`Could not find a channel named "${channelName}". Check which channels exist on this project with ${chalk.bold(
'eas channel:list'
)}.`
);
}
const { branchMapping: currentBranchMapping, isRollout } = getBranchMapping(
channel.branchMapping
);
if (currentBranchMapping.data.length === 0) {
throw new Error('The channel is not pointing at any branches.');
}
if (currentBranchMapping.data.length > 2) {
throw new Error('"channel:rollout" cannot handle branch mappings with more than 2 branches.');
}
// This combination doesn't make sense. Throw an error explaining the options.
if (isRollout && branchName && !endFlag) {
throw new Error(
`There is a rollout in progress. You can only either edit the rollout percent or 'end' it.`
);
}
/**
* This if/else block has three branches:
* 1. The branch mapping is not a rollout, i.e. it is pointing to a single branch.
* 2. The branch mapping is a rollout.
* a. increase/decrease the rollout percentage.
* b. end the rollout.
*/
let rolloutMutationResult: {
newChannelInfo: {
id: string;
name: string;
branchMapping: string;
};
logMessage: string;
const app = { projectId, exp };
const ctx = {
projectId,
nonInteractive: argsAndFlags.nonInteractive,
graphqlClient,
app,
};
if (!isRollout) {
rolloutMutationResult = await startRolloutAsync(graphqlClient, {
channelName,
branchName:
branchName ??
(await promptForBranchNameAsync({
graphqlClient,
projectId,
channelName,
nonInteractive,
json: jsonFlag,
})),
percent,
nonInteractive,
projectId,
displayName: projectDisplayName,
currentBranchMapping,
channel,
});
} else if (endFlag) {
rolloutMutationResult = await endRolloutAsync(graphqlClient, {
channelName,
branchName,
nonInteractive,
projectId,
channel,
});
if (argsAndFlags.nonInteractive) {
await new NonInteractiveRollout(argsAndFlags).runAsync(ctx);
} else {
rolloutMutationResult = await editRolloutAsync(graphqlClient, {
channelName,
percent,
nonInteractive,
currentBranchMapping,
channel,
});
}
if (!rolloutMutationResult) {
throw new Error('rollout result is empty');
}
const { newChannelInfo, logMessage } = rolloutMutationResult;
if (jsonFlag) {
printJsonOnlyOutput(newChannelInfo);
} else {
Log.withTick(logMessage);
Log.addNewLineIfNone();
Log.warn(
`✨ This command is in Developer Preview and has not been released to production yet. Website support is coming soon.`
);
Log.addNewLineIfNone();
await new RolloutMainMenu(argsAndFlags).runAsync(ctx);
}
}
}
async function promptForBranchNameAsync({
graphqlClient,
projectId,
channelName,
nonInteractive,
json,
}: {
graphqlClient: ExpoGraphqlClient;
projectId: string;
channelName: string;
nonInteractive: boolean;
json: boolean;
}): Promise<string> {
if (nonInteractive) {
throw new Error('Must supply branch flag in non-interactive mode');
private getAction(action: ActionRawFlagValue): RolloutActions {
switch (action) {
case ActionRawFlagValue.CREATE:
return MainMenuActions.CREATE_NEW;
case ActionRawFlagValue.EDIT:
return ManageRolloutActions.EDIT;
case ActionRawFlagValue.END:
return ManageRolloutActions.END;
}
}
const { name: branchName } = await selectBranchOnAppAsync(graphqlClient, {
projectId,
promptTitle: `Which branch would you like roll out on ${channelName}?`,
displayTextForListItem: updateBranch => ({
title: updateBranch.name,
}),
// discard limit and offset because this query is not their intended target
paginatedQueryOptions: {
json,
nonInteractive,
offset: 0,
},
});
return branchName;
private sanitizeArgsAndFlags(
rawFlags: ChannelRolloutRawArgsAndFlags
): ChannelRolloutArgsAndFlags {
const action = rawFlags.action;
return {
channelName: rawFlags.channel,
percent: rawFlags.percent,
outcome: rawFlags.outcome,
branchNameToRollout: rawFlags.branch,
runtimeVersion: rawFlags['runtime-version'],
privateKeyPath: rawFlags['private-key-path'] ?? null,
action: action ? this.getAction(action) : undefined,
nonInteractive: rawFlags['non-interactive'],
json: rawFlags.json,
};
}
}
@@ -47,6 +47,7 @@ export default class MetadataLint extends EasCommand {
easJsonAccessor: EasJsonAccessor.fromProjectPath(projectDir),
platforms: [Platform.IOS],
profileName: flags.profile,
projectDir,
});
if (submitProfiles.length !== 1) {
@@ -49,6 +49,7 @@ export default class MetadataPull extends EasCommand {
easJsonAccessor: EasJsonAccessor.fromProjectPath(projectDir),
platforms: [Platform.IOS],
profileName: flags.profile,
projectDir,
});
if (submitProfiles.length !== 1) {
@@ -47,6 +47,7 @@ export default class MetadataPush extends EasCommand {
easJsonAccessor: EasJsonAccessor.fromProjectPath(projectDir),
platforms: [Platform.IOS],
profileName: flags.profile,
projectDir,
});
if (submitProfiles.length !== 1) {
+1
View File
@@ -118,6 +118,7 @@ export default class Submit extends EasCommand {
easJsonAccessor: EasJsonAccessor.fromProjectPath(projectDir),
platforms,
profileName: flagsWithPlatform.profile,
projectDir,
});
const submissions: SubmissionFragment[] = [];
@@ -1,5 +1,5 @@
import { AppJSONConfig, PackageJSONConfig, getConfig } from '@expo/config';
import { vol } from 'memfs';
import { AppJSONConfig, ExpoConfig, PackageJSONConfig, getConfig } from '@expo/config';
import { DirectoryJSON, vol } from 'memfs';
import { instance, mock } from 'ts-mockito';
import LoggedInContextField from '../../../commandUtils/context/LoggedInContextField';
@@ -8,12 +8,17 @@ import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/cr
import FeatureGateEnvOverrides from '../../../commandUtils/gating/FeatureGateEnvOverrides';
import FeatureGating from '../../../commandUtils/gating/FeatureGating';
import { jester } from '../../../credentials/__tests__/fixtures-constants';
import { CodeSigningInfo, UpdateFragment } from '../../../graphql/generated';
import { UpdateFragment } from '../../../graphql/generated';
import { PublishMutation } from '../../../graphql/mutations/PublishMutation';
import { AppQuery } from '../../../graphql/queries/AppQuery';
import { UpdateQuery } from '../../../graphql/queries/UpdateQuery';
import { getBranchNameFromChannelNameAsync } from '../../../update/getBranchNameFromChannelNameAsync';
import { selectUpdateGroupOnBranchAsync } from '../../../update/queries';
import {
getCodeSigningInfoAsync,
getManifestBodyAsync,
signBody,
} from '../../../utils/code-signing';
import UpdateRepublish from '../republish';
const projectRoot = '/test-project';
@@ -33,12 +38,6 @@ const updateStub: UpdateFragment = {
createdAt: '2022-01-01T12:00:00Z',
};
const codeSigningStub: CodeSigningInfo = {
keyid: 'keyid',
alg: 'alg',
sig: 'sig',
};
jest.mock('fs');
jest.mock('@expo/config');
jest.mock('../../../commandUtils/context/contextUtils/getProjectIdAsync');
@@ -52,16 +51,12 @@ jest.mock('../../../ora', () => ({
start: () => ({ succeed: () => {}, fail: () => {} }),
}),
}));
jest.mock('../../../utils/code-signing');
jest.mock('../../../fetch');
describe(UpdateRepublish.name, () => {
afterEach(() => vol.reset());
it('errors without --channel, --branch, or --group', async () => {
await expect(new UpdateRepublish([], commandOptions).run()).rejects.toThrow(
'--channel, --branch, or --group must be specified'
);
});
it('errors when providing both --group and --branch', async () => {
const flags = ['--group=1234', '--branch=main'];
@@ -156,18 +151,45 @@ describe(UpdateRepublish.name, () => {
});
it('re-creates update using codesigning with --group and --message', async () => {
const flags = ['--group=1234', '--message=test-republish'];
const flags = [
'--group=1234',
'--message=test-republish',
`--private-key-path=./keys/test-private-key.pem`,
];
const codeSigning = {
alg: 'alg',
alg: 'rsa-v1_5-sha256',
keyid: 'keyid',
sig: 'sig',
};
mockTestProject();
mockTestProject({
extraManifest: {
updates: {
codeSigningCertificate: './keys/test-certificate.pem',
codeSigningMetadata: {
alg: 'rsa-v1_5-sha256',
keyid: 'keyid',
},
},
},
extraVol: {
'./keys/test-private-key.pem': 'testpemprivate',
'./keys/test-certificate.pem': 'testpemcertificate',
},
});
jest.mocked(getCodeSigningInfoAsync).mockResolvedValue({
privateKey: '' as any,
certificate: '' as any,
codeSigningMetadata: { alg: 'rsa-v1_5-sha256', keyid: 'keyid' },
});
jest.mocked(getManifestBodyAsync).mockResolvedValue('test');
jest.mocked(signBody).mockReturnValue('sig');
// Mock queries to retrieve the update and code signing info
jest
.mocked(UpdateQuery.viewUpdateGroupAsync)
.mockResolvedValue([{ ...updateStub, codeSigningInfo: codeSigningStub }]);
.mockResolvedValue([{ ...updateStub, codeSigningInfo: codeSigning }]);
// Mock mutations to store the new update
jest.mocked(PublishMutation.publishUpdateGroupAsync).mockResolvedValue([
{
@@ -287,8 +309,12 @@ describe(UpdateRepublish.name, () => {
/** Create a new in-memory project, based on src/commands/project/__tests__/init.test.ts */
function mockTestProject({
configuredProjectId = '1234',
extraManifest,
extraVol,
}: {
configuredProjectId?: string;
extraManifest?: Partial<ExpoConfig>;
extraVol?: DirectoryJSON;
} = {}): void {
const packageJSON: PackageJSONConfig = {
name: 'testing123',
@@ -309,6 +335,7 @@ function mockTestProject({
projectId: configuredProjectId,
},
},
...extraManifest,
},
};
@@ -316,6 +343,7 @@ function mockTestProject({
{
'package.json': JSON.stringify(packageJSON),
'app.json': JSON.stringify(appJSON),
...extraVol,
},
projectRoot
);
@@ -35,6 +35,7 @@ import {
getRuntimeVersionObjectAsync,
getUpdateMessageForCommandAsync,
isUploadedAssetCountAboveWarningThreshold,
platformDisplayNames,
resolveInputDirectoryAsync,
uploadAssetsAsync,
} from '../../project/publish';
@@ -325,6 +326,21 @@ export default class UpdatePublish extends EasCommand {
for (const uploadedAssetPath of uploadResults.uniqueUploadedAssetPaths) {
Log.debug(chalk.dim(`- ${uploadedAssetPath}`));
}
const platformString = (Object.keys(assets) as PublishPlatform[])
.map(platform => {
const collectedAssetForPlatform = nullthrows(assets[platform]);
const totalAssetsForPlatform = collectedAssetForPlatform.assets.length + 1; // launch asset
const assetString = totalAssetsForPlatform === 1 ? 'asset' : 'assets';
return `${totalAssetsForPlatform} ${platformDisplayNames[platform]} ${assetString}`;
})
.join(', ');
Log.withInfo(
`${platformString} (maximum: ${assetLimitPerUpdateGroup} total per update). ${learnMore(
'https://expo.fyi/eas-update-asset-limits',
{ learnMoreMessage: 'Learn more about asset limits.' }
)}`
);
} catch (e) {
assetSpinner.fail('Failed to upload');
throw e;
+98 -135
View File
@@ -1,23 +1,21 @@
import { Platform } from '@expo/config';
import { Flags } from '@oclif/core';
import { getUpdateGroupUrl } from '../../build/utils/url';
import { selectBranchOnAppAsync } from '../../branch/queries';
import { selectChannelOnAppAsync } from '../../channel/queries';
import EasCommand from '../../commandUtils/EasCommand';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { EasNonInteractiveAndJsonFlags } from '../../commandUtils/flags';
import { getPaginatedQueryOptions } from '../../commandUtils/pagination';
import { Update } from '../../graphql/generated';
import { PublishMutation } from '../../graphql/mutations/PublishMutation';
import { UpdateQuery } from '../../graphql/queries/UpdateQuery';
import Log, { link } from '../../log';
import { ora } from '../../ora';
import { getOwnerAccountForProjectIdAsync } from '../../project/projectUtils';
import Log from '../../log';
import { promptAsync } from '../../prompts';
import { getBranchNameFromChannelNameAsync } from '../../update/getBranchNameFromChannelNameAsync';
import { selectUpdateGroupOnBranchAsync } from '../../update/queries';
import { UpdateToRepublish, republishAsync } from '../../update/republish';
import { truncateString as truncateUpdateMessage } from '../../update/utils';
import formatFields from '../../utils/formatFields';
import { enableJsonOutput, printJsonOnlyOutput } from '../../utils/json';
import { getCodeSigningInfoAsync } from '../../utils/code-signing';
import { enableJsonOutput } from '../../utils/json';
const defaultRepublishPlatforms: Platform[] = ['android', 'ios'];
@@ -27,6 +25,7 @@ type UpdateRepublishRawFlags = {
group?: string;
message?: string;
platform: string;
'private-key-path'?: string;
'non-interactive': boolean;
json?: boolean;
};
@@ -37,34 +36,21 @@ type UpdateRepublishFlags = {
groupId?: string;
updateMessage?: string;
platform: Platform[];
privateKeyPath?: string;
nonInteractive: boolean;
json: boolean;
};
type UpdateToRepublish = {
groupId: string;
branchId: string;
branchName: string;
} & Pick<
Update,
| 'message'
| 'runtimeVersion'
| 'manifestFragment'
| 'platform'
| 'gitCommitHash'
| 'codeSigningInfo'
>;
export default class UpdateRepublish extends EasCommand {
static override description = 'roll back to an existing update';
static override flags = {
channel: Flags.string({
description: 'Channel name to select an update to republish from',
description: 'Channel name to select an update group to republish from',
exclusive: ['branch', 'group'],
}),
branch: Flags.string({
description: 'Branch name to select an update to republish from',
description: 'Branch name to select an update group to republish from',
exclusive: ['channel', 'group'],
}),
group: Flags.string({
@@ -73,7 +59,7 @@ export default class UpdateRepublish extends EasCommand {
}),
message: Flags.string({
char: 'm',
description: 'Short message describing the republished update',
description: 'Short message describing the republished update group',
required: false,
}),
platform: Flags.enum({
@@ -82,6 +68,10 @@ export default class UpdateRepublish extends EasCommand {
default: 'all',
required: false,
}),
'private-key-path': Flags.string({
description: `File containing the PEM-encoded private key corresponding to the certificate in expo-updates' configuration. Defaults to a file named "private-key.pem" in the certificate's directory.`,
required: false,
}),
...EasNonInteractiveAndJsonFlags,
};
@@ -105,6 +95,8 @@ export default class UpdateRepublish extends EasCommand {
enableJsonOutput();
}
const codeSigningInfo = await getCodeSigningInfoAsync(exp, flags.privateKeyPath);
const existingUpdates = await getOrAskUpdatesAsync(graphqlClient, projectId, flags);
const updatesToPublish = existingUpdates.filter(update =>
flags.platform.includes(update.platform as Platform)
@@ -124,117 +116,43 @@ export default class UpdateRepublish extends EasCommand {
}
if (rawFlags.platform === 'all') {
Log.withTick(`The republished update will appear only on: ${rawFlags.platform}`);
Log.withTick(`The republished update group will appear only on: ${rawFlags.platform}`);
} else {
const platformsFromUpdates = updatesToPublish.map(update => update.platform);
if (platformsFromUpdates.length < defaultRepublishPlatforms.length) {
Log.warn(`You are republishing an update that wasn't published for all platforms.`);
Log.warn(`You are republishing an update group that wasn't published for all platforms.`);
}
Log.withTick(
`The republished update will appear on the same platforms it was originally published on: ${platformsFromUpdates.join(
`The republished update group will appear on the same platforms it was originally published on: ${platformsFromUpdates.join(
', '
)}`
);
}
// This command only republishes a single update group
// The update group properties are the same for all updates
const { branchId, branchName, runtimeVersion } = updatesToPublish[0];
const updateMessage = await getOrAskUpdateMessageAsync(updatesToPublish, flags);
// If codesigning was created for the original update, we need to add it to the republish
const shouldRepublishWithCodesigning = updatesToPublish.some(update => update.codeSigningInfo);
if (shouldRepublishWithCodesigning) {
Log.withTick(
`The republished update will be signed with the same codesigning as the original update.`
);
}
const publishIndicator = ora('Republishing...').start();
let updatesRepublished: Awaited<ReturnType<typeof PublishMutation.publishUpdateGroupAsync>>;
try {
updatesRepublished = await PublishMutation.publishUpdateGroupAsync(graphqlClient, [
{
branchId,
runtimeVersion,
message: updateMessage,
updateInfoGroup: Object.fromEntries(
updatesToPublish.map(update => [update.platform, JSON.parse(update.manifestFragment)])
),
gitCommitHash: updatesToPublish[0].gitCommitHash,
awaitingCodeSigningInfo: shouldRepublishWithCodesigning,
},
]);
if (shouldRepublishWithCodesigning) {
const codeSigningByPlatform = Object.fromEntries(
updatesToPublish.map(update => [update.platform, update.codeSigningInfo])
);
await Promise.all(
updatesRepublished.map(async update => {
const codeSigning = codeSigningByPlatform[update.platform];
if (codeSigning) {
await PublishMutation.setCodeSigningInfoAsync(graphqlClient, update.id, codeSigning);
}
})
);
}
publishIndicator.succeed('Republished update');
} catch (error: any) {
publishIndicator.fail('Failed to republish update');
throw error;
}
if (flags.json) {
return printJsonOnlyOutput(updatesRepublished);
}
const updatesRepublishedByPlatform = Object.fromEntries(
updatesRepublished.map(update => [update.platform, update])
);
const updateGroupUrl = getUpdateGroupUrl(
(await getOwnerAccountForProjectIdAsync(graphqlClient, projectId)).name,
exp.slug,
updatesRepublished[0].group
);
Log.addNewLineIfNone();
Log.log(
formatFields([
{ label: 'Branch', value: branchName },
{ label: 'Runtime version', value: updatesRepublished[0].runtimeVersion },
{ label: 'Platform', value: updatesRepublished.map(update => update.platform).join(', ') },
{ label: 'Update Group ID', value: updatesRepublished[0].id },
...(updatesRepublishedByPlatform.android
? [{ label: 'Android update ID', value: updatesRepublishedByPlatform.android.id }]
: []),
...(updatesRepublishedByPlatform.ios
? [{ label: 'iOS update ID', value: updatesRepublishedByPlatform.ios.id }]
: []),
{ label: 'Message', value: updateMessage },
{ label: 'Website link', value: link(updateGroupUrl, { dim: false }) },
])
);
const arbitraryUpdate = updatesToPublish[0];
await republishAsync({
graphqlClient,
app: { exp, projectId },
updatesToPublish,
targetBranch: { branchId: arbitraryUpdate.branchId, branchName: arbitraryUpdate.branchName },
updateMessage,
codeSigningInfo,
json: flags.json,
});
}
sanitizeFlags(rawFlags: UpdateRepublishRawFlags): UpdateRepublishFlags {
private sanitizeFlags(rawFlags: UpdateRepublishRawFlags): UpdateRepublishFlags {
const branchName = rawFlags.branch;
const channelName = rawFlags.channel;
const groupId = rawFlags.group;
const nonInteractive = rawFlags['non-interactive'];
const privateKeyPath = rawFlags['private-key-path'];
if (nonInteractive && !groupId) {
throw new Error('Only --group can be used in non-interactive mode');
}
if (!groupId && !(branchName || channelName)) {
throw new Error(`--channel, --branch, or --group must be specified`);
}
const platform =
rawFlags.platform === 'all' ? defaultRepublishPlatforms : ([rawFlags.platform] as Platform[]);
@@ -245,6 +163,7 @@ export default class UpdateRepublish extends EasCommand {
groupId,
platform,
updateMessage: rawFlags.message,
privateKeyPath,
json: rawFlags.json ?? false,
nonInteractive,
};
@@ -258,18 +177,22 @@ async function getOrAskUpdatesAsync(
flags: UpdateRepublishFlags
): Promise<UpdateToRepublish[]> {
if (flags.groupId) {
const updateGroups = await UpdateQuery.viewUpdateGroupAsync(graphqlClient, {
const updateGroup = await UpdateQuery.viewUpdateGroupAsync(graphqlClient, {
groupId: flags.groupId,
});
return updateGroups.map(group => ({
...group,
groupId: group.group,
branchId: group.branch.id,
branchName: group.branch.name,
return updateGroup.map(update => ({
...update,
groupId: update.group,
branchId: update.branch.id,
branchName: update.branch.name,
}));
}
if (flags.nonInteractive) {
throw new Error('Must supply --group when in non-interactive mode');
}
if (flags.branchName) {
return await askUpdatesFromBranchNameAsync(graphqlClient, {
...flags,
@@ -286,7 +209,55 @@ async function getOrAskUpdatesAsync(
});
}
throw new Error('--channel, --branch, or --group is required');
const { choice } = await promptAsync({
type: 'select',
message: 'Find update by branch or channel?',
name: 'choice',
choices: [
{ title: 'Branch', value: 'branch' },
{ title: 'Channel', value: 'channel' },
],
});
if (choice === 'channel') {
const { name } = await selectChannelOnAppAsync(graphqlClient, {
projectId,
selectionPromptTitle: 'Select a channel to view',
paginatedQueryOptions: {
json: flags.json,
nonInteractive: flags.nonInteractive,
offset: 0,
},
});
return await askUpdatesFromChannelNameAsync(graphqlClient, {
...flags,
channelName: name,
projectId,
});
} else if (choice === 'branch') {
const { name } = await selectBranchOnAppAsync(graphqlClient, {
projectId,
promptTitle: 'Select branch from which to choose update',
displayTextForListItem: updateBranch => ({
title: updateBranch.name,
}),
// discard limit and offset because this query is not their intended target
paginatedQueryOptions: {
json: flags.json,
nonInteractive: flags.nonInteractive,
offset: 0,
},
});
return await askUpdatesFromBranchNameAsync(graphqlClient, {
...flags,
branchName: name,
projectId,
});
} else {
throw new Error('Must choose update via channel or branch');
}
}
/** Ask the user which update needs to be republished by branch name, this requires interactive mode */
@@ -299,21 +270,17 @@ async function askUpdatesFromBranchNameAsync(
nonInteractive,
}: { projectId: string; branchName: string; json: boolean; nonInteractive: boolean }
): Promise<UpdateToRepublish[]> {
if (nonInteractive) {
throw new Error('Must supply --group when in non-interactive mode');
}
const updateGroups = await selectUpdateGroupOnBranchAsync(graphqlClient, {
const updateGroup = await selectUpdateGroupOnBranchAsync(graphqlClient, {
projectId,
branchName,
paginatedQueryOptions: getPaginatedQueryOptions({ json, 'non-interactive': nonInteractive }),
});
return updateGroups.map(group => ({
...group,
groupId: group.id,
branchId: group.branch.id,
branchName: group.branch.name,
return updateGroup.map(update => ({
...update,
groupId: update.group,
branchId: update.branch.id,
branchName: update.branch.name,
}));
}
/** Ask the user which update needs to be republished by channel name, this requires interactive mode */
@@ -326,10 +293,6 @@ async function askUpdatesFromChannelNameAsync(
nonInteractive,
}: { projectId: string; channelName: string; json: boolean; nonInteractive: boolean }
): Promise<UpdateToRepublish[]> {
if (nonInteractive) {
throw new Error('Must supply --group when in non-interactive mode');
}
const branchName = await getBranchNameFromChannelNameAsync(graphqlClient, projectId, channelName);
return await askUpdatesFromBranchNameAsync(graphqlClient, {
@@ -86,7 +86,11 @@ export default class UpdateRollBackToEmbedded extends EasCommand {
}),
platform: Flags.enum({
char: 'p',
options: [...defaultPublishPlatforms, 'all'],
options: [
// TODO: Add web when it's fully supported
...defaultPublishPlatforms,
'all',
],
default: 'all',
required: false,
}),
@@ -0,0 +1,42 @@
import { Flags } from '@oclif/core';
import EasCommand from '../../commandUtils/EasCommand';
import { promptAsync } from '../../prompts';
import UpdateRepublish from './republish';
import UpdateRollBackToEmbedded from './roll-back-to-embedded';
export default class UpdateRollback extends EasCommand {
static override description = 'roll back to an embedded update or an existing update';
static override hidden = true;
static override flags = {
'private-key-path': Flags.string({
description: `File containing the PEM-encoded private key corresponding to the certificate in expo-updates' configuration. Defaults to a file named "private-key.pem" in the certificate's directory.`,
required: false,
}),
};
async runAsync(): Promise<void> {
const { flags } = await this.parse(UpdateRollback);
const { choice } = await promptAsync({
type: 'select',
message: 'Which type of update would you like to roll back to?',
name: 'choice',
choices: [
{ title: 'Published Update', value: 'published' },
{ title: 'Embedded Update', value: 'embedded' },
],
});
const privateKeyPathArg = flags['private-key-path']
? ['--private-key-path', flags['private-key-path']]
: [];
if (choice === 'published') {
await UpdateRepublish.run(privateKeyPathArg);
} else {
await UpdateRollBackToEmbedded.run(privateKeyPathArg);
}
}
}
@@ -177,7 +177,23 @@ export class SetUpAdhocProvisioningProfile {
);
}
// 6. Create (or update) app build credentials
// 6. Compare selected devices with the ones actually provisioned
const diffList = differenceBy(
chosenDevices,
appleProvisioningProfile.appleDevices,
'identifier'
);
if (diffList && diffList.length > 0) {
Log.warn(`Failed to provision ${diffList.length} of the selected devices:`);
for (const missingDevice of diffList) {
Log.warn(`- ${formatDeviceLabel(missingDevice)}`);
}
Log.log(
'Most commonly devices fail to to be provisioned while they are still being processed by Apple, which can take up to 24-72 hours. Check your Apple Developer Portal page at https://developer.apple.com/account/resources/devices/list, the devices in "Processing" status cannot be provisioned yet'
);
}
// 7. Create (or update) app build credentials
assert(appleProvisioningProfile);
return await assignBuildCredentialsAsync(
ctx,
@@ -1,4 +1,38 @@
import { doUDIDsMatch } from '../SetUpAdhocProvisioningProfile';
import { Env } from '@expo/eas-build-job';
import { EasJson } from '@expo/eas-json';
import { Analytics } from '../../../../analytics/AnalyticsManager';
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
import {
Account,
AppleAppIdentifierFragment,
AppleDevice,
AppleDeviceClass,
AppleDeviceFragment,
AppleDistributionCertificateFragment,
IosAppBuildCredentialsFragment,
} from '../../../../graphql/generated';
import Log from '../../../../log';
import { getApplePlatformFromTarget } from '../../../../project/ios/target';
import { Actor } from '../../../../user/User';
import { CredentialsContext, CredentialsContextProjectInfo } from '../../../context';
import { ProvisioningProfile } from '../../appstore/Credentials.types';
import { ApplePlatform } from '../../appstore/constants';
import { assignBuildCredentialsAsync, getBuildCredentialsAsync } from '../BuildCredentialsUtils';
import { chooseDevicesAsync } from '../DeviceUtils';
import { SetUpAdhocProvisioningProfile, doUDIDsMatch } from '../SetUpAdhocProvisioningProfile';
jest.mock('../BuildCredentialsUtils');
jest.mock('../../../context');
jest.mock('../../../ios/api/GraphqlClient');
jest.mock('../DeviceUtils', () => {
return {
__esModule: true,
chooseDevicesAsync: jest.fn(),
formatDeviceLabel: jest.requireActual('../DeviceUtils').formatDeviceLabel,
};
});
jest.mock('../../../../project/ios/target');
describe(doUDIDsMatch, () => {
it('return false if UDIDs do not match', () => {
@@ -12,3 +46,104 @@ describe(doUDIDsMatch, () => {
expect(doUDIDsMatch(udidsA, udidsB)).toBe(true);
});
});
describe('runWithDistributionCertificateAsync', () => {
beforeEach(() => {
jest.resetAllMocks();
});
const setUpAdhocProvisioningProfile = new SetUpAdhocProvisioningProfile({
app: { account: {} as Account, projectName: 'projName', bundleIdentifier: 'bundleId' },
target: { targetName: 'targetName', bundleIdentifier: 'bundleId', entitlements: {} },
});
describe('compare chosen and provisioned devices', () => {
describe('not all devices provisioned', () => {
it('displays warning to the user and lists the missing devices', async () => {
const { ctx, distCert } = setUpTest();
jest.mocked(getBuildCredentialsAsync).mockResolvedValue({
provisioningProfile: {
appleTeam: {},
appleDevices: [{ identifier: 'id1' }],
developerPortalIdentifier: 'provisioningProfileId',
},
} as IosAppBuildCredentialsFragment);
const LogWarnSpy = jest.spyOn(Log, 'warn');
const LogLogSpy = jest.spyOn(Log, 'log');
const result = await setUpAdhocProvisioningProfile.runWithDistributionCertificateAsync(
ctx,
distCert
);
expect(result).toEqual({} as IosAppBuildCredentialsFragment);
expect(LogWarnSpy).toHaveBeenCalledTimes(3);
expect(LogWarnSpy).toHaveBeenCalledWith('Failed to provision 2 of the selected devices:');
expect(LogWarnSpy).toHaveBeenCalledWith('- id2 (iPhone) (Device 2)');
expect(LogWarnSpy).toHaveBeenCalledWith('- id3 (Mac) (Device 3)');
expect(LogLogSpy).toHaveBeenCalledTimes(1);
expect(LogLogSpy).toHaveBeenCalledWith(
'Most commonly devices fail to to be provisioned while they are still being processed by Apple, which can take up to 24-72 hours. Check your Apple Developer Portal page at https://developer.apple.com/account/resources/devices/list, the devices in "Processing" status cannot be provisioned yet'
);
});
});
describe('all devices provisioned', () => {
it('does not display warning', async () => {
const { ctx, distCert } = setUpTest();
jest.mocked(getBuildCredentialsAsync).mockResolvedValue({
provisioningProfile: {
appleTeam: {},
appleDevices: [{ identifier: 'id1' }, { identifier: 'id2' }, { identifier: 'id3' }],
developerPortalIdentifier: 'provisioningProfileId',
},
} as IosAppBuildCredentialsFragment);
const LogWarnSpy = jest.spyOn(Log, 'warn');
const LogLogSpy = jest.spyOn(Log, 'log');
const result = await setUpAdhocProvisioningProfile.runWithDistributionCertificateAsync(
ctx,
distCert
);
expect(result).toEqual({} as IosAppBuildCredentialsFragment);
expect(LogWarnSpy).not.toHaveBeenCalled();
expect(LogLogSpy).not.toHaveBeenCalled();
});
});
});
});
function setUpTest(): { ctx: CredentialsContext; distCert: AppleDistributionCertificateFragment } {
const ctx = jest.mocked(
new CredentialsContext(
{} as {
projectInfo: CredentialsContextProjectInfo | null;
easJsonCliConfig?: EasJson['cli'];
nonInteractive: boolean;
projectDir: string;
user: Actor;
graphqlClient: ExpoGraphqlClient;
analytics: Analytics;
env?: Env;
}
)
);
Object.defineProperty(ctx, 'ios', { value: jest.mock('../../../ios/api/GraphqlClient') });
ctx.ios.getDevicesForAppleTeamAsync = jest
.fn()
.mockResolvedValue([
{ identifier: 'id1' },
{ identifier: 'id2' },
{ identifier: 'id3' },
] as AppleDeviceFragment[]);
jest.mocked(chooseDevicesAsync).mockResolvedValue([
{ identifier: 'id1', name: 'Device 1', deviceClass: AppleDeviceClass.Ipad },
{ identifier: 'id2', name: 'Device 2', deviceClass: AppleDeviceClass.Iphone },
{ identifier: 'id3', name: 'Device 3', deviceClass: AppleDeviceClass.Mac },
] as AppleDevice[]);
// @ts-ignore
jest.mocked(getApplePlatformFromTarget).mockResolvedValue(ApplePlatform.IOS);
Object.defineProperty(ctx, 'appStore', { value: jest.mock('../../appstore/AppStoreApi') });
ctx.appStore.createOrReuseAdhocProvisioningProfileAsync = jest.fn().mockResolvedValue({
provisioningProfileId: 'provisioningProfileId',
} as ProvisioningProfile);
ctx.ios.createOrGetExistingAppleAppIdentifierAsync = jest
.fn()
.mockResolvedValue({} as AppleAppIdentifierFragment);
jest.mocked(assignBuildCredentialsAsync).mockResolvedValue({} as IosAppBuildCredentialsFragment);
const distCert = {} as AppleDistributionCertificateFragment;
return { ctx, distCert };
}
@@ -0,0 +1 @@
export const runCurrentMachineMethodAsync = jest.fn();
@@ -5,6 +5,7 @@ import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils
import AppStoreApi from '../../../../credentials/ios/appstore/AppStoreApi';
import { AccountFragment, Role } from '../../../../graphql/generated';
import DeviceCreateAction, { RegistrationMethod } from '../action';
import { runCurrentMachineMethodAsync } from '../currentMachineMethod';
import { runDeveloperPortalMethodAsync } from '../developerPortalMethod';
import { runInputMethodAsync } from '../inputMethod';
import { runRegistrationUrlMethodAsync } from '../registrationUrlMethod';
@@ -13,6 +14,7 @@ jest.mock('prompts');
jest.mock('../developerPortalMethod');
jest.mock('../inputMethod');
jest.mock('../registrationUrlMethod');
jest.mock('../currentMachineMethod');
beforeEach(() => {
const promptsMock = jest.mocked(prompts);
@@ -22,6 +24,7 @@ beforeEach(() => {
});
jest.mocked(runRegistrationUrlMethodAsync).mockClear();
jest.mocked(runInputMethodAsync).mockClear();
jest.mocked(runCurrentMachineMethodAsync).mockClear();
});
describe(DeviceCreateAction, () => {
@@ -118,5 +121,36 @@ describe(DeviceCreateAction, () => {
expect(runDeveloperPortalMethodAsync).toBeCalled();
});
it('calls runCurrentMachineMethodAsync if user chooses the current machine method', async () => {
jest.mocked(prompts).mockImplementationOnce(async () => ({
method: RegistrationMethod.CURRENT_MACHINE,
}));
const appStoreApiMock = mock<AppStoreApi>();
const appStoreApi = instance(appStoreApiMock);
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const account: AccountFragment = {
id: 'account_id',
name: 'foobar',
users: [
{
role: Role.Owner,
actor: {
id: 'user_id',
},
},
],
};
const appleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123Y',
appleTeamName: 'John Doe (Individual)',
};
const action = new DeviceCreateAction(graphqlClient, appStoreApi, account, appleTeam);
await action.runAsync();
expect(runCurrentMachineMethodAsync).toBeCalled();
});
});
});
@@ -0,0 +1,183 @@
import os from 'os';
import prompts from 'prompts';
import { instance, mock } from 'ts-mockito';
import { ExpoGraphqlClient } from '../../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppleDeviceMutation } from '../../../../credentials/ios/api/graphql/mutations/AppleDeviceMutation';
import { AppleTeam } from '../../../../graphql/generated';
import { DeviceCreateError } from '../../../utils/errors';
import { runCurrentMachineMethodAsync } from '../currentMachineMethod';
jest.mock('../../../../credentials/ios/api/graphql/mutations/AppleDeviceMutation');
jest.mock('../../../../ora');
jest.mock('os', () => {
return {
...jest.requireActual('os'),
cpus: jest.fn(),
};
});
jest.mock('@expo/spawn-async', () => {
return {
__esModule: true,
...jest.requireActual('@expo/spawn-async'),
default: jest.fn(async () => {
return {
stdout: JSON.stringify({
SPHardwareDataType: [
{
provisioning_UDID: 'fake_udid',
machine_name: 'fake_machine_name',
},
],
}),
};
}),
};
});
let actualPlatform: string;
beforeAll(() => {
actualPlatform = process.platform;
});
beforeEach(() => {
jest.mocked(prompts).mockReset();
jest.mocked(prompts).mockImplementation(() => {
throw new Error(`unhandled prompts call - this shouldn't happen - fix tests!`);
});
jest.mocked(AppleDeviceMutation.createAppleDeviceAsync).mockClear();
});
afterAll(() => {
Object.defineProperty(process, 'platform', { value: actualPlatform });
});
describe(runCurrentMachineMethodAsync, () => {
it('allows registering the default Mac device class', async () => {
jest.mocked(os.cpus).mockImplementation(() => [{ model: 'Apple M1' } as os.CpuInfo]);
Object.defineProperty(process, 'platform', { value: 'darwin' });
mockDeviceData('my Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const accountId = 'account-id';
// @ts-expect-error appleTeam is missing properties of AppleTeam GraphQL type
const appleTeam: AppleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123XY',
appleTeamName: 'John Doe (Individual)',
};
await runCurrentMachineMethodAsync(graphqlClient, accountId, appleTeam);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(1);
});
it('proceeds with registration if user approves, only once', async () => {
jest.mocked(os.cpus).mockImplementation(() => [{ model: 'Apple M1' } as os.CpuInfo]);
Object.defineProperty(process, 'platform', { value: 'darwin' });
mockDeviceData('my Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
mockDeviceData('my other Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: false }));
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const accountId = 'account-id';
// @ts-expect-error appleTeam is missing properties of AppleTeam GraphQL type
const appleTeam: AppleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123XY',
appleTeamName: 'John Doe (Individual)',
};
await runCurrentMachineMethodAsync(graphqlClient, accountId, appleTeam);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(1);
});
it('exits registration if user cancels', async () => {
jest.mocked(os.cpus).mockImplementation(() => [{ model: 'Apple M1' } as os.CpuInfo]);
Object.defineProperty(process, 'platform', { value: 'darwin' });
mockDeviceData('my Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: false }));
mockDeviceData('my other Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const accountId = 'account-id';
// @ts-expect-error appleTeam is missing properties of AppleTeam GraphQL type
const appleTeam: AppleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123XY',
appleTeamName: 'John Doe (Individual)',
};
await runCurrentMachineMethodAsync(graphqlClient, accountId, appleTeam);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(0);
});
it('exits registration if current Mac machine is not of Apple Silicon type', async () => {
jest
.mocked(os.cpus)
.mockImplementation(() => [{ model: 'Intel(R) Core(TM) i5' } as os.CpuInfo]);
Object.defineProperty(process, 'platform', { value: 'darwin' });
mockDeviceData('my old Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
mockDeviceData('my other Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: false }));
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const accountId = 'account-id';
// @ts-expect-error appleTeam is missing properties of AppleTeam GraphQL type
const appleTeam: AppleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123XY',
appleTeamName: 'John Doe (Individual)',
};
await expect(
runCurrentMachineMethodAsync(graphqlClient, accountId, appleTeam)
).rejects.toThrowError(
new DeviceCreateError(
"Current machine is not of Apple Silicon type - provisioning UDID can't be added automatically."
)
);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(0);
});
it('exits registration if current machine is not Mac', async () => {
jest
.mocked(os.cpus)
.mockImplementation(() => [{ model: 'Intel(R) Core(TM) i5' } as os.CpuInfo]);
Object.defineProperty(process, 'platform', { value: 'win32' });
mockDeviceData('my Windows PC');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
mockDeviceData('my other Mac');
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: false }));
const graphqlClient = instance(mock<ExpoGraphqlClient>());
const accountId = 'account-id';
// @ts-expect-error appleTeam is missing properties of AppleTeam GraphQL type
const appleTeam: AppleTeam = {
id: 'apple-team-id',
appleTeamIdentifier: 'ABC123XY',
appleTeamName: 'John Doe (Individual)',
};
await expect(
runCurrentMachineMethodAsync(graphqlClient, accountId, appleTeam)
).rejects.toThrowError(
new DeviceCreateError(
"Current machine is not of Apple Silicon type - provisioning UDID can't be added automatically."
)
);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(0);
});
});
function mockDeviceData(name: string): void {
jest.mocked(prompts).mockImplementationOnce(async () => ({ name }));
}
@@ -21,6 +21,8 @@ describe(runInputMethodAsync, () => {
it('should allow for multiple device registration', async () => {
mockDeviceData('00001111-001122334455662E', 'my iPhone', AppleDeviceClass.Iphone);
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
mockDeviceData('00001111-001122334455662F', 'my Mac', AppleDeviceClass.Mac);
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: true }));
mockDeviceData('b12cba9856d89c932ab7a4b813c4d932534e1679', 'my iPad', AppleDeviceClass.Ipad);
jest.mocked(prompts).mockImplementationOnce(async () => ({ value: false }));
@@ -35,7 +37,7 @@ describe(runInputMethodAsync, () => {
await runInputMethodAsync(graphqlClient, accountId, appleTeam);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(2);
expect(AppleDeviceMutation.createAppleDeviceAsync).toHaveBeenCalledTimes(3);
});
});
@@ -5,6 +5,7 @@ import AppStoreApi from '../../../credentials/ios/appstore/AppStoreApi';
import { AccountFragment, AppleTeam } from '../../../graphql/generated';
import Log from '../../../log';
import { promptAsync } from '../../../prompts';
import { runCurrentMachineMethodAsync } from './currentMachineMethod';
import { runDeveloperPortalMethodAsync } from './developerPortalMethod';
import { runInputMethodAsync } from './inputMethod';
import { runRegistrationUrlMethodAsync } from './registrationUrlMethod';
@@ -13,6 +14,7 @@ export enum RegistrationMethod {
WEBSITE,
INPUT,
DEVELOPER_PORTAL,
CURRENT_MACHINE,
EXIT,
}
@@ -37,6 +39,8 @@ export default class DeviceCreateAction {
);
} else if (method === RegistrationMethod.INPUT) {
await runInputMethodAsync(this.graphqlClient, this.account.id, this.appleTeam);
} else if (method === RegistrationMethod.CURRENT_MACHINE) {
await runCurrentMachineMethodAsync(this.graphqlClient, this.account.id, this.appleTeam);
} else if (method === RegistrationMethod.EXIT) {
Log.log('Bye!');
process.exit(0);
@@ -66,6 +70,12 @@ export default class DeviceCreateAction {
title: `${chalk.bold('Input')} - allows you to type in UDIDs (advanced option)`,
value: RegistrationMethod.INPUT,
},
{
title: `${chalk.bold(
'Current Machine'
)} - automatically sets the provisioning UDID of the current Apple Silicon machine`,
value: RegistrationMethod.CURRENT_MACHINE,
},
{ title: chalk.bold('Exit'), value: RegistrationMethod.EXIT },
],
validate: (val: RegistrationMethod) => Object.values(RegistrationMethod).includes(val),
@@ -0,0 +1,127 @@
import spawnAsync from '@expo/spawn-async';
import chalk from 'chalk';
import os from 'os';
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppleDeviceMutation } from '../../../credentials/ios/api/graphql/mutations/AppleDeviceMutation';
import { AppleDeviceClass, AppleTeam } from '../../../graphql/generated';
import Log from '../../../log';
import { ora } from '../../../ora';
import { confirmAsync } from '../../../prompts';
import { DeviceCreateError } from '../../utils/errors';
import { DeviceData, printDeviceData, promptForNameAsync } from './utils';
export async function runCurrentMachineMethodAsync(
graphqlClient: ExpoGraphqlClient,
accountId: string,
appleTeam: Pick<AppleTeam, 'appleTeamIdentifier' | 'appleTeamName' | 'id'>
): Promise<void> {
Log.newLine();
Log.log(chalk.white('Checking if current machine is an Apple Silicon one.'));
if (!isMachineAppleSilicon()) {
throw new DeviceCreateError(
"Current machine is not of Apple Silicon type - provisioning UDID can't be added automatically."
);
}
Log.log(chalk.green('Check successful.'));
await collectDataAndRegisterDeviceAsync(graphqlClient, { accountId, appleTeam });
}
function isMachineAppleSilicon(): boolean {
return os.cpus()[0].model.includes('Apple M') && process.platform === 'darwin';
}
async function collectDataAndRegisterDeviceAsync(
graphqlClient: ExpoGraphqlClient,
{
accountId,
appleTeam,
}: {
accountId: string;
appleTeam: Pick<AppleTeam, 'appleTeamIdentifier' | 'appleTeamName' | 'id'>;
}
): Promise<void> {
const deviceData = await collectDeviceDataAsync(appleTeam);
if (!deviceData) {
return;
}
const { udid, deviceClass, name } = deviceData;
const spinner = ora(`Registering Apple device on Expo`).start();
try {
await AppleDeviceMutation.createAppleDeviceAsync(
graphqlClient,
{
appleTeamId: appleTeam.id,
identifier: udid,
name,
deviceClass: deviceClass ?? undefined,
},
accountId
);
} catch (err) {
spinner.fail();
throw err;
}
spinner.succeed();
}
async function collectDeviceDataAsync(
appleTeam: Pick<AppleTeam, 'appleTeamIdentifier' | 'appleTeamName'>,
initialValues: Partial<DeviceData> = {}
): Promise<DeviceData | null> {
Log.log(chalk.white('Fetching the provisioning UDID.'));
const [udid, defaultMachineName] = await fetchCurrentMachineUDIDAsync();
Log.log(chalk.green(`Fetched the provisioning UDID - ${udid}`));
const name = await promptForNameAsync(defaultMachineName ?? initialValues.name);
const deviceClass = AppleDeviceClass.Mac;
const deviceData: DeviceData = {
udid,
name,
deviceClass,
};
printDeviceData(deviceData, appleTeam);
const registrationConfirmed = await confirmAsync({
message: 'Is this what you want to register?',
});
if (!registrationConfirmed) {
Log.log('No worries, just try again.');
Log.newLine();
return null;
} else {
return deviceData;
}
}
async function fetchCurrentMachineUDIDAsync(): Promise<[string, string?]> {
try {
const profilerData = (
await spawnAsync('system_profiler', ['-json', 'SPHardwareDataType'])
).stdout.trim();
if (!profilerData) {
const message = 'Failed to fetch the provisioning UDID from system profiler';
Log.error(message);
throw new DeviceCreateError(message);
}
const profilerDataJSON = JSON.parse(profilerData);
const provisioningUDID = profilerDataJSON?.SPHardwareDataType[0]?.provisioning_UDID;
if (!provisioningUDID) {
const message = 'System profiler data did not contain the provisioning UDID';
Log.error(message);
throw new DeviceCreateError(message);
}
const defaultMachineName = profilerDataJSON?.SPHardwareDataType[0]?.machine_name;
return [provisioningUDID, defaultMachineName];
} catch (err: any) {
if (!(err instanceof DeviceCreateError)) {
const message = `Failed to fetch the provisioning UDID of the current machine - ${err.message}`;
Log.error(message);
throw new DeviceCreateError(message);
}
throw err;
}
}
@@ -19,6 +19,7 @@ const DEVICE_IMPORT_CHUNK_SIZE = 10;
const DEVICE_CLASS_TO_GRAPHQL_TYPE: Partial<Record<DeviceClass, AppleDeviceClass>> = {
[DeviceClass.IPAD]: AppleDeviceClass.Ipad,
[DeviceClass.IPHONE]: AppleDeviceClass.Iphone,
[DeviceClass.MAC]: AppleDeviceClass.Mac,
};
export async function runDeveloperPortalMethodAsync(
@@ -105,7 +106,7 @@ async function findUnregisteredPortalDevicesAsync(
return portalDevices.filter(
portalDevice =>
!(portalDevice.attributes.udid in expoRegisteredDevicesByUdid) &&
[DeviceClass.IPAD, DeviceClass.IPHONE, DeviceClass.APPLE_TV].includes(
[DeviceClass.IPAD, DeviceClass.IPHONE, DeviceClass.APPLE_TV, DeviceClass.MAC].includes(
portalDevice.attributes.deviceClass
)
);
@@ -2,18 +2,17 @@ import chalk from 'chalk';
import { ExpoGraphqlClient } from '../../../commandUtils/context/contextUtils/createGraphqlClient';
import { AppleDeviceMutation } from '../../../credentials/ios/api/graphql/mutations/AppleDeviceMutation';
import { AppleDeviceClass, AppleTeam } from '../../../graphql/generated';
import { AppleTeam } from '../../../graphql/generated';
import Log from '../../../log';
import { ora } from '../../../ora';
import { confirmAsync, promptAsync } from '../../../prompts';
import { isValidUDID, normalizeUDID } from '../../udids';
import { formatNewDevice } from '../../utils/formatDevice';
interface DeviceData {
udid: string;
name?: string;
deviceClass: AppleDeviceClass | null;
}
import { confirmAsync } from '../../../prompts';
import {
DeviceData,
printDeviceData,
promptForDeviceClassAsync,
promptForNameAsync,
promptForUDIDAsync,
} from './utils';
export async function runInputMethodAsync(
graphqlClient: ExpoGraphqlClient,
@@ -78,16 +77,7 @@ async function collectDeviceDataAsync(
deviceClass,
};
Log.newLine();
Log.log(
`We are going to register the following device in our database.
This device will ${chalk.bold(
'not'
)} be registered on the Apple Developer Portal until it is chosen for an internal distribution build.`
);
Log.newLine();
Log.log(formatNewDevice({ ...deviceData, identifier: deviceData.udid }, appleTeam));
Log.newLine();
printDeviceData(deviceData, appleTeam);
const registrationConfirmed = await confirmAsync({
message: 'Is this what you want to register?',
@@ -100,56 +90,3 @@ This device will ${chalk.bold(
return deviceData;
}
}
export async function promptForUDIDAsync(initial?: string): Promise<string> {
const { udid } = await promptAsync({
type: 'text',
name: 'udid',
message: 'UDID:',
initial,
validate: (rawVal: string) => {
const val = normalizeUDID(rawVal);
if (!val || val === '') {
return 'UDID cannot be empty';
} else if (val.length !== 25 && val.length !== 40) {
return 'UDID should be a 25 or 40-character string';
} else if (!isValidUDID(val)) {
return 'UDID is invalid';
} else {
return true;
}
},
format: (val: string) => normalizeUDID(val),
});
return udid;
}
async function promptForNameAsync(initial?: string): Promise<string | undefined> {
const { name } = await promptAsync({
type: 'text',
name: 'name',
message: 'Device name (optional):',
initial,
});
return name;
}
async function promptForDeviceClassAsync(
initial?: AppleDeviceClass | null
): Promise<AppleDeviceClass | null> {
const choices = [
{ title: 'iPhone', value: AppleDeviceClass.Iphone },
{ title: 'iPad', value: AppleDeviceClass.Ipad },
{ title: 'Not sure (leave empty)', value: null },
];
const values = choices.map(({ value }) => value);
const { deviceClass } = await promptAsync({
type: 'select',
name: 'deviceClass',
message: 'Device class (optional):',
choices,
initial: initial !== undefined && values.indexOf(initial),
});
return deviceClass;
}
@@ -0,0 +1,83 @@
import chalk from 'chalk';
import { AppleDeviceClass, AppleTeam } from '../../../graphql/generated';
import Log from '../../../log';
import { promptAsync } from '../../../prompts';
import { isValidUDID, normalizeUDID } from '../../udids';
import { formatNewDevice } from '../../utils/formatDevice';
export interface DeviceData {
udid: string;
name?: string;
deviceClass: AppleDeviceClass | null;
}
export async function promptForDeviceClassAsync(
initial?: AppleDeviceClass | null
): Promise<AppleDeviceClass | null> {
const choices = [
{ title: 'iPhone', value: AppleDeviceClass.Iphone },
{ title: 'iPad', value: AppleDeviceClass.Ipad },
{ title: 'Mac', value: AppleDeviceClass.Mac },
{ title: 'Not sure (leave empty)', value: null },
];
const values = choices.map(({ value }) => value);
const { deviceClass } = await promptAsync({
type: 'select',
name: 'deviceClass',
message: 'Device class (optional):',
choices,
initial: initial !== undefined && values.indexOf(initial),
});
return deviceClass;
}
export async function promptForNameAsync(initial?: string): Promise<string | undefined> {
const { name } = await promptAsync({
type: 'text',
name: 'name',
message: 'Device name (optional):',
initial,
});
return name;
}
export async function promptForUDIDAsync(initial?: string): Promise<string> {
const { udid } = await promptAsync({
type: 'text',
name: 'udid',
message: 'UDID:',
initial,
validate: (rawVal: string) => {
const val = normalizeUDID(rawVal);
if (!val || val === '') {
return 'UDID cannot be empty';
} else if (val.length !== 25 && val.length !== 40) {
return 'UDID should be a 25 or 40-character string';
} else if (!isValidUDID(val)) {
return 'UDID is invalid';
} else {
return true;
}
},
format: (val: string) => normalizeUDID(val),
});
return udid;
}
export function printDeviceData(
deviceData: DeviceData,
appleTeam: Pick<AppleTeam, 'appleTeamIdentifier' | 'appleTeamName'>
): void {
Log.newLine();
Log.log(
`We are going to register the following device in our database.
This device will ${chalk.bold(
'not'
)} be registered on the Apple Developer Portal until it is chosen for an internal distribution build.`
);
Log.newLine();
Log.log(formatNewDevice({ ...deviceData, identifier: deviceData.udid }, appleTeam));
Log.newLine();
}
+3 -3
View File
@@ -12,10 +12,10 @@ import { Actor } from '../user/User';
import DeviceCreateAction from './actions/create/action';
import { DeviceManagerContext } from './context';
const CREATE_COMMAND_DESCRIPTION = `This command lets you register your Apple devices (iPhones and iPads) for internal distribution of your app.
const CREATE_COMMAND_DESCRIPTION = `This command lets you register your Apple devices (iPhones, iPads and Macs) for internal distribution of your app.
Internal distribution means that you won't need to upload your app archive to App Store / Testflight.
Your app archive (.ipa) will be installable on your equipment as long as you sign your application with an adhoc provisiong profile.
The provisioning profile needs to contain the UDIDs (unique identifiers) of your iPhones and iPads.
Your app archive (.ipa) will be installable on your equipment as long as you sign your application with an adhoc provisioning profile.
The provisioning profile needs to contain the UDIDs (unique identifiers) of your iPhones, iPads and Macs.
First of all, choose the Expo account under which you want to register your devices.
Later, authenticate with Apple and choose your desired Apple Team (if your Apple ID has access to multiple teams).`;
@@ -3,3 +3,9 @@ export class DeviceNotFoundError extends Error {
super(message ?? 'Device not found.');
}
}
export class DeviceCreateError extends Error {
constructor(message?: string) {
super(message ?? 'Failed to create a device.');
}
}
@@ -9,6 +9,7 @@ export type AppleTeamIdAndName = Pick<AppleTeam, 'appleTeamIdentifier' | 'appleT
const DEVICE_CLASS_DISPLAY_NAMES: Record<AppleDeviceClass, string> = {
[AppleDeviceClass.Iphone]: 'iPhone',
[AppleDeviceClass.Ipad]: 'iPad',
[AppleDeviceClass.Mac]: 'Mac',
};
function formatDeviceClass(device: Device | NewDevice): string {
@@ -0,0 +1,10 @@
import { testAppJson } from '../../credentials/__tests__/fixtures-constants';
import { EASUpdateContext } from '../utils';
export function createCtxMock(options: { nonInteractive?: boolean } = {}): EASUpdateContext {
return {
graphqlClient: jest.fn() as any,
nonInteractive: options.nonInteractive ?? false,
app: { exp: testAppJson, projectId: 'test-project-id' },
};
}
+15
View File
@@ -0,0 +1,15 @@
import { ExpoConfig } from '@expo/config-types';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
export type EASUpdateContext = {
graphqlClient: ExpoGraphqlClient;
nonInteractive: boolean;
app: { exp: ExpoConfig; projectId: string };
};
export interface EASUpdateAction<T = any> {
runAsync(ctx: EASUpdateContext): Promise<T>;
}
export class NonInteractiveError extends Error {}
+203 -28
View File
@@ -1009,6 +1009,7 @@ export type App = Project & {
/** Environment secrets for an app */
environmentSecrets: Array<EnvironmentSecret>;
fullName: Scalars['String'];
githubBuildTriggers: Array<GitHubBuildTrigger>;
githubRepository?: Maybe<GitHubRepository>;
githubRepositorySettings?: Maybe<GitHubRepositorySettings>;
/** githubUrl field from most recent classic update manifest */
@@ -1365,16 +1366,19 @@ export type AppInsights = {
export type AppInsightsTotalUniqueUsersArgs = {
timespan: InsightsTimespan;
useDeprecatedBackend?: InputMaybe<Scalars['Boolean']>;
};
export type AppInsightsUniqueUsersByAppVersionOverTimeArgs = {
timespan: InsightsTimespan;
useDeprecatedBackend?: InputMaybe<Scalars['Boolean']>;
};
export type AppInsightsUniqueUsersByPlatformOverTimeArgs = {
timespan: InsightsTimespan;
useDeprecatedBackend?: InputMaybe<Scalars['Boolean']>;
};
export type AppMutation = {
@@ -1653,7 +1657,8 @@ export type AppleDevice = {
export enum AppleDeviceClass {
Ipad = 'IPAD',
Iphone = 'IPHONE'
Iphone = 'IPHONE',
Mac = 'MAC'
}
export type AppleDeviceInput = {
@@ -2236,6 +2241,17 @@ export enum BuildJobStatus {
Started = 'STARTED'
}
export type BuildLimitThresholdExceededMetadata = {
__typename?: 'BuildLimitThresholdExceededMetadata';
account: Account;
thresholdsExceeded: Array<NotificationThresholdExceeded>;
};
export enum BuildLimitThresholdExceededMetadataType {
Ios = 'IOS',
Total = 'TOTAL'
}
export type BuildLogs = {
__typename?: 'BuildLogs';
format?: Maybe<BuildJobLogsFormat>;
@@ -2381,6 +2397,14 @@ export type BuildParamsInput = {
sdkVersion?: InputMaybe<Scalars['String']>;
};
export type BuildPlanCreditThresholdExceededMetadata = {
__typename?: 'BuildPlanCreditThresholdExceededMetadata';
account: Account;
buildCreditUsage: Scalars['Int'];
planLimit: Scalars['Int'];
threshold: Scalars['Int'];
};
export enum BuildPriority {
High = 'HIGH',
Normal = 'NORMAL',
@@ -2586,6 +2610,19 @@ export type CreateGitHubAppInstallationInput = {
installationIdentifier: Scalars['Int'];
};
export type CreateGitHubBuildTriggerInput = {
appId: Scalars['ID'];
autoSubmit: Scalars['Boolean'];
buildProfile: Scalars['String'];
isActive: Scalars['Boolean'];
platform: AppPlatform;
/** A branch or tag name, or a wildcard pattern where the code change originates from. For example, `main` or `release/*`. */
sourcePattern: Scalars['String'];
/** A branch name or a wildcard pattern that the pull request targets. For example, `main` or `release/*`. */
targetPattern?: InputMaybe<Scalars['String']>;
type: GitHubBuildTriggerType;
};
export type CreateGitHubRepositoryInput = {
appId: Scalars['ID'];
githubAppInstallationId: Scalars['ID'];
@@ -3091,6 +3128,54 @@ export type GitHubBuildInput = {
platform: AppPlatform;
};
export type GitHubBuildTrigger = {
__typename?: 'GitHubBuildTrigger';
app: App;
autoSubmit: Scalars['Boolean'];
buildProfile: Scalars['String'];
createdAt: Scalars['DateTime'];
id: Scalars['ID'];
isActive: Scalars['Boolean'];
lastRunAt?: Maybe<Scalars['DateTime']>;
platform: AppPlatform;
sourcePattern: Scalars['String'];
targetPattern?: Maybe<Scalars['String']>;
type: GitHubBuildTriggerType;
updatedAt: Scalars['DateTime'];
};
export type GitHubBuildTriggerMutation = {
__typename?: 'GitHubBuildTriggerMutation';
/** Create GitHub build trigger for an App */
createGitHubBuildTrigger: GitHubBuildTrigger;
/** Delete GitHub build trigger by ID */
deleteGitHubBuildTrigger: GitHubBuildTrigger;
/** Update a GitHub build trigger by ID */
updateGitHubBuildTrigger: GitHubBuildTrigger;
};
export type GitHubBuildTriggerMutationCreateGitHubBuildTriggerArgs = {
githubBuildTriggerData: CreateGitHubBuildTriggerInput;
};
export type GitHubBuildTriggerMutationDeleteGitHubBuildTriggerArgs = {
githubBuildTriggerId: Scalars['ID'];
};
export type GitHubBuildTriggerMutationUpdateGitHubBuildTriggerArgs = {
githubBuildTriggerData: UpdateGitHubBuildTriggerInput;
githubBuildTriggerId: Scalars['ID'];
};
export enum GitHubBuildTriggerType {
PullRequestUpdated = 'PULL_REQUEST_UPDATED',
PushToBranch = 'PUSH_TO_BRANCH',
TagUpdated = 'TAG_UPDATED'
}
export type GitHubRepository = {
__typename?: 'GitHubRepository';
app: App;
@@ -3758,13 +3843,27 @@ export type MeteredBillingStatus = {
EAS_UPDATE: Scalars['Boolean'];
};
export type Notification = {
__typename?: 'Notification';
createdAt: Scalars['DateTime'];
event: NotificationEvent;
id: Scalars['ID'];
isRead: Scalars['Boolean'];
metadata?: Maybe<NotificationMetadata>;
type: NotificationType;
updatedAt: Scalars['DateTime'];
};
export enum NotificationEvent {
BuildComplete = 'BUILD_COMPLETE',
BuildLimitThresholdExceeded = 'BUILD_LIMIT_THRESHOLD_EXCEEDED',
BuildPlanCreditThresholdExceeded = 'BUILD_PLAN_CREDIT_THRESHOLD_EXCEEDED',
SubmissionComplete = 'SUBMISSION_COMPLETE'
SubmissionComplete = 'SUBMISSION_COMPLETE',
Test = 'TEST'
}
export type NotificationMetadata = BuildLimitThresholdExceededMetadata | BuildPlanCreditThresholdExceededMetadata | TestNotificationMetadata;
export type NotificationSubscription = {
__typename?: 'NotificationSubscription';
account?: Maybe<Account>;
@@ -3805,8 +3904,17 @@ export type NotificationSubscriptionMutationUnsubscribeArgs = {
id: Scalars['ID'];
};
export type NotificationThresholdExceeded = {
__typename?: 'NotificationThresholdExceeded';
count: Scalars['Int'];
limit: Scalars['Int'];
threshold: Scalars['Int'];
type: BuildLimitThresholdExceededMetadataType;
};
export enum NotificationType {
Email = 'EMAIL'
Email = 'EMAIL',
Web = 'WEB'
}
export type Offer = {
@@ -4090,6 +4198,8 @@ export type RootMutation = {
githubApp: GitHubAppMutation;
/** Mutations for GitHub App installations */
githubAppInstallation: GitHubAppInstallationMutation;
/** Mutations for GitHub build triggers */
githubBuildTrigger: GitHubBuildTriggerMutation;
/** Mutations for GitHub repositories */
githubRepository: GitHubRepositoryMutation;
/** Mutations for GitHub repository settings */
@@ -4200,14 +4310,15 @@ export type RootQuery = {
meUserActor?: Maybe<UserActor>;
project: ProjectQuery;
snack: SnackQuery;
/** Top-level query object for querying SSO Users. */
ssoUser: SsoUserQuery;
/** Top-level query object for querying Expo status page services. */
statuspageService: StatuspageServiceQuery;
submissions: SubmissionQuery;
/** fetch all updates in a group */
updatesByGroup: Array<Update>;
/** Top-level query object for querying Users. */
/**
* Top-level query object for querying Users.
* @deprecated Public user queries are no longer supported
*/
user: UserQuery;
/** Top-level query object for querying UserActors. */
userActor: UserActorQuery;
@@ -4264,6 +4375,23 @@ export type Runtime = {
version: Scalars['String'];
};
export type RuntimeEdge = {
__typename?: 'RuntimeEdge';
cursor: Scalars['String'];
node: Runtime;
};
export type RuntimeFilterInput = {
/** Only return runtimes shared with this branch */
branchId?: InputMaybe<Scalars['String']>;
};
export type RuntimesConnection = {
__typename?: 'RuntimesConnection';
edges: Array<RuntimeEdge>;
pageInfo: PageInfo;
};
/** Represents a human SSO (not robot) actor. */
export type SsoUser = Actor & UserActor & {
__typename?: 'SSOUser';
@@ -4309,6 +4437,8 @@ export type SsoUser = Actor & UserActor & {
/** @deprecated No longer supported */
twitterUsername?: Maybe<Scalars['String']>;
username: Scalars['String'];
/** Web notifications linked to a user */
websiteNotifications: Array<Notification>;
};
@@ -4351,24 +4481,6 @@ export type SsoUserDataInput = {
lastName?: InputMaybe<Scalars['String']>;
};
export type SsoUserQuery = {
__typename?: 'SSOUserQuery';
/** Query an SSOUser by ID */
byId: SsoUser;
/** Query an SSOUser by username */
byUsername: SsoUser;
};
export type SsoUserQueryByIdArgs = {
userId: Scalars['ID'];
};
export type SsoUserQueryByUsernameArgs = {
username: Scalars['String'];
};
export type SecondFactorBooleanResult = {
__typename?: 'SecondFactorBooleanResult';
success: Scalars['Boolean'];
@@ -4745,6 +4857,11 @@ export type SubscriptionDetailsPlanEnablementArgs = {
serviceMetric: EasServiceMetric;
};
export type TestNotificationMetadata = {
__typename?: 'TestNotificationMetadata';
message: Scalars['String'];
};
export type TimelineActivityConnection = {
__typename?: 'TimelineActivityConnection';
edges: Array<TimelineActivityEdge>;
@@ -4806,12 +4923,22 @@ export type UpdateBranch = {
createdAt: Scalars['DateTime'];
id: Scalars['ID'];
name: Scalars['String'];
runtimes: RuntimesConnection;
updateGroups: Array<Array<Update>>;
updatedAt: Scalars['DateTime'];
updates: Array<Update>;
};
export type UpdateBranchRuntimesArgs = {
after?: InputMaybe<Scalars['String']>;
before?: InputMaybe<Scalars['String']>;
filter?: InputMaybe<RuntimeFilterInput>;
first?: InputMaybe<Scalars['Int']>;
last?: InputMaybe<Scalars['Int']>;
};
export type UpdateBranchUpdateGroupsArgs = {
filter?: InputMaybe<UpdatesFilter>;
limit: Scalars['Int'];
@@ -4917,6 +5044,16 @@ export type UpdateChannelMutationEditUpdateChannelArgs = {
channelId: Scalars['ID'];
};
export type UpdateGitHubBuildTriggerInput = {
autoSubmit: Scalars['Boolean'];
buildProfile: Scalars['String'];
isActive: Scalars['Boolean'];
platform: AppPlatform;
sourcePattern: Scalars['String'];
targetPattern?: InputMaybe<Scalars['String']>;
type: GitHubBuildTriggerType;
};
export type UpdateGitHubRepositorySettingsInput = {
baseDirectory: Scalars['String'];
};
@@ -5062,6 +5199,7 @@ export type User = Actor & UserActor & {
/** @deprecated No longer supported */
twitterUsername?: Maybe<Scalars['String']>;
username: Scalars['String'];
websiteNotifications: Array<Notification>;
};
@@ -5150,6 +5288,8 @@ export type UserActor = {
/** @deprecated No longer supported */
twitterUsername?: Maybe<Scalars['String']>;
username: Scalars['String'];
/** Web notifications linked to a user */
websiteNotifications: Array<Notification>;
};
@@ -5368,9 +5508,15 @@ export type UserPermission = {
export type UserQuery = {
__typename?: 'UserQuery';
/** Query a User by ID */
/**
* Query a User by ID
* @deprecated Public user queries are no longer supported
*/
byId: User;
/** Query a User by username */
/**
* Query a User by username
* @deprecated Public user queries are no longer supported
*/
byUsername: User;
};
@@ -6136,6 +6282,17 @@ export type BranchesByAppQueryVariables = Exact<{
export type BranchesByAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, updateBranches: Array<{ __typename?: 'UpdateBranch', id: string, name: string, updates: Array<{ __typename?: 'Update', id: string, group: string, message?: string | null, createdAt: any, runtimeVersion: string, platform: string, manifestFragment: string, isRollBackToEmbedded: boolean, manifestPermalink: string, gitCommitHash?: string | null, actor?: { __typename: 'Robot', firstName?: string | null, id: string } | { __typename: 'SSOUser', username: string, id: string } | { __typename: 'User', username: string, id: string } | null, branch: { __typename?: 'UpdateBranch', id: string, name: string }, codeSigningInfo?: { __typename?: 'CodeSigningInfo', keyid: string, sig: string, alg: string } | null }> }> } } };
export type BranchesBasicPaginatedOnAppQueryVariables = Exact<{
appId: Scalars['String'];
first?: InputMaybe<Scalars['Int']>;
after?: InputMaybe<Scalars['String']>;
last?: InputMaybe<Scalars['Int']>;
before?: InputMaybe<Scalars['String']>;
}>;
export type BranchesBasicPaginatedOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, branchesPaginated: { __typename?: 'AppBranchesConnection', edges: Array<{ __typename?: 'AppBranchEdge', cursor: string, node: { __typename?: 'UpdateBranch', id: string, name: string } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | null, endCursor?: string | null } } } } };
export type ViewBranchesOnUpdateChannelQueryVariables = Exact<{
appId: Scalars['String'];
channelName: Scalars['String'];
@@ -6173,6 +6330,7 @@ export type ViewBuildsOnAppQuery = { __typename?: 'RootQuery', app: { __typename
export type ViewUpdateChannelOnAppQueryVariables = Exact<{
appId: Scalars['String'];
channelName: Scalars['String'];
filter?: InputMaybe<UpdatesFilter>;
}>;
@@ -6191,10 +6349,12 @@ export type ViewUpdateChannelsPaginatedOnAppQueryVariables = Exact<{
appId: Scalars['String'];
first?: InputMaybe<Scalars['Int']>;
after?: InputMaybe<Scalars['String']>;
last?: InputMaybe<Scalars['Int']>;
before?: InputMaybe<Scalars['String']>;
}>;
export type ViewUpdateChannelsPaginatedOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, channelsPaginated: { __typename?: 'AppChannelsConnection', edges: Array<{ __typename?: 'AppChannelEdge', node: { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | null, endCursor?: string | null } } } } };
export type ViewUpdateChannelsPaginatedOnAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, channelsPaginated: { __typename?: 'AppChannelsConnection', edges: Array<{ __typename?: 'AppChannelEdge', cursor: string, node: { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | null, endCursor?: string | null } } } } };
export type EnvironmentSecretsByAppIdQueryVariables = Exact<{
appId: Scalars['String'];
@@ -6217,6 +6377,19 @@ export type GetAssetLimitPerUpdateGroupForAppQueryVariables = Exact<{
export type GetAssetLimitPerUpdateGroupForAppQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, assetLimitPerUpdateGroup: number } } };
export type ViewRuntimesOnBranchQueryVariables = Exact<{
appId: Scalars['String'];
name: Scalars['String'];
first?: InputMaybe<Scalars['Int']>;
after?: InputMaybe<Scalars['String']>;
last?: InputMaybe<Scalars['Int']>;
before?: InputMaybe<Scalars['String']>;
filter?: InputMaybe<RuntimeFilterInput>;
}>;
export type ViewRuntimesOnBranchQuery = { __typename?: 'RootQuery', app: { __typename?: 'AppQuery', byId: { __typename?: 'App', id: string, updateBranchByName?: { __typename?: 'UpdateBranch', id: string, runtimes: { __typename?: 'RuntimesConnection', edges: Array<{ __typename?: 'RuntimeEdge', cursor: string, node: { __typename?: 'Runtime', id: string, version: string } }>, pageInfo: { __typename?: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | null, endCursor?: string | null } } } | null } } };
export type StatuspageServiceByServiceNamesQueryVariables = Exact<{
serviceNames: Array<StatuspageServiceName> | StatuspageServiceName;
}>;
@@ -6300,6 +6473,8 @@ export type BuildWithSubmissionsFragment = { __typename?: 'Build', id: string, s
export type EnvironmentSecretFragment = { __typename?: 'EnvironmentSecret', id: string, name: string, type: EnvironmentSecretType, createdAt: any };
export type RuntimeFragment = { __typename?: 'Runtime', id: string, version: string };
export type StatuspageServiceFragment = { __typename?: 'StatuspageService', id: string, name: StatuspageServiceName, status: StatuspageServiceStatus, incidents: Array<{ __typename?: 'StatuspageIncident', id: string, status: StatuspageIncidentStatus, name: string, impact: StatuspageIncidentImpact, shortlink: string }> };
export type SubmissionFragment = { __typename?: 'Submission', id: string, status: SubmissionStatus, platform: AppPlatform, logsUrl?: string | null, app: { __typename?: 'App', id: string, name: string, slug: string, ownerAccount: { __typename?: 'Account', id: string, name: string } }, androidConfig?: { __typename?: 'AndroidSubmissionConfig', applicationIdentifier?: string | null, track: SubmissionAndroidTrack, releaseStatus?: SubmissionAndroidReleaseStatus | null, rollout?: number | null } | null, iosConfig?: { __typename?: 'IosSubmissionConfig', ascAppIdentifier: string, appleIdUsername?: string | null } | null, error?: { __typename?: 'SubmissionError', errorCode?: string | null, message?: string | null } | null };
@@ -6308,7 +6483,7 @@ export type UpdateFragment = { __typename?: 'Update', id: string, group: string,
export type UpdateBranchFragment = { __typename?: 'UpdateBranch', id: string, name: string, updates: Array<{ __typename?: 'Update', id: string, group: string, message?: string | null, createdAt: any, runtimeVersion: string, platform: string, manifestFragment: string, isRollBackToEmbedded: boolean, manifestPermalink: string, gitCommitHash?: string | null, actor?: { __typename: 'Robot', firstName?: string | null, id: string } | { __typename: 'SSOUser', username: string, id: string } | { __typename: 'User', username: string, id: string } | null, branch: { __typename?: 'UpdateBranch', id: string, name: string }, codeSigningInfo?: { __typename?: 'CodeSigningInfo', keyid: string, sig: string, alg: string } | null }> };
export type UpdateBranchWithCurrentGroupFragment = { __typename?: 'UpdateBranch', id: string, name: string, updateGroups: Array<Array<{ __typename?: 'Update', id: string, group: string, message?: string | null, createdAt: any, runtimeVersion: string, platform: string, manifestFragment: string, isRollBackToEmbedded: boolean, manifestPermalink: string, gitCommitHash?: string | null, actor?: { __typename: 'Robot', firstName?: string | null, id: string } | { __typename: 'SSOUser', username: string, id: string } | { __typename: 'User', username: string, id: string } | null, branch: { __typename?: 'UpdateBranch', id: string, name: string }, codeSigningInfo?: { __typename?: 'CodeSigningInfo', keyid: string, sig: string, alg: string } | null }>> };
export type UpdateBranchBasicInfoFragment = { __typename?: 'UpdateBranch', id: string, name: string };
export type UpdateChannelBasicInfoFragment = { __typename?: 'UpdateChannel', id: string, name: string, branchMapping: string };
@@ -5,8 +5,11 @@ import { BranchNotFoundError } from '../../branch/utils';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { withErrorHandlingAsync } from '../client';
import {
BranchesBasicPaginatedOnAppQuery,
BranchesBasicPaginatedOnAppQueryVariables,
BranchesByAppQuery,
BranchesByAppQueryVariables,
UpdateBranchBasicInfoFragment,
UpdateBranchFragment,
ViewBranchQuery,
ViewBranchQueryVariables,
@@ -15,6 +18,7 @@ import {
} from '../generated';
import { UpdateFragmentNode } from '../types/Update';
import { UpdateBranchFragmentNode } from '../types/UpdateBranch';
import { UpdateBranchBasicInfoFragmentNode } from '../types/UpdateBranchBasicInfo';
export type UpdateBranchOnChannelObject = NonNullable<
ViewBranchesOnUpdateChannelQuery['app']['byId']['updateChannelByName']
@@ -24,7 +28,7 @@ export const BranchQuery = {
async getBranchByNameAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, name }: ViewBranchQueryVariables
): Promise<NonNullable<ViewBranchQuery['app']['byId']['updateBranchByName']>> {
): Promise<UpdateBranchBasicInfoFragment> {
const response = await withErrorHandlingAsync<ViewBranchQuery>(
graphqlClient
.query<ViewBranchQuery, ViewBranchQueryVariables>(
@@ -35,11 +39,12 @@ export const BranchQuery = {
id
updateBranchByName(name: $name) {
id
name
...UpdateBranchBasicInfoFragment
}
}
}
}
${print(UpdateBranchBasicInfoFragmentNode)}
`,
{
appId,
@@ -88,6 +93,56 @@ export const BranchQuery = {
return data?.app?.byId.updateBranches ?? [];
},
async listBranchesBasicInfoPaginatedOnAppAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, first, after, last, before }: BranchesBasicPaginatedOnAppQueryVariables
): Promise<BranchesBasicPaginatedOnAppQuery['app']['byId']['branchesPaginated']> {
const response = await withErrorHandlingAsync(
graphqlClient
.query<BranchesBasicPaginatedOnAppQuery, BranchesBasicPaginatedOnAppQueryVariables>(
gql`
query BranchesBasicPaginatedOnApp(
$appId: String!
$first: Int
$after: String
$last: Int
$before: String
) {
app {
byId(appId: $appId) {
id
branchesPaginated(first: $first, after: $after, before: $before, last: $last) {
edges {
node {
id
...UpdateBranchBasicInfoFragment
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
}
}
${print(UpdateBranchBasicInfoFragmentNode)}
`,
{ appId, first, after, last, before },
{ additionalTypenames: ['UpdateBranch'] }
)
.toPromise()
);
const { branchesPaginated } = response.app.byId;
if (!branchesPaginated) {
throw new Error(`Could not find channels on project with id ${appId}`);
}
return branchesPaginated;
},
async listBranchesOnChannelAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, channelName, offset, limit }: ViewBranchesOnUpdateChannelQueryVariables
@@ -5,8 +5,8 @@ import { ChannelNotFoundError } from '../../channel/errors';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { withErrorHandlingAsync } from '../client';
import {
PageInfo,
UpdateChannelBasicInfoFragment,
UpdateBranchBasicInfoFragment,
UpdateFragment,
ViewUpdateChannelOnAppQuery,
ViewUpdateChannelOnAppQueryVariables,
ViewUpdateChannelsOnAppQuery,
@@ -14,7 +14,7 @@ import {
ViewUpdateChannelsPaginatedOnAppQuery,
ViewUpdateChannelsPaginatedOnAppQueryVariables,
} from '../generated';
import { UpdateBranchWithCurrentGroupFragmentNode } from '../types/UpdateBranchWithCurrentUpdate';
import { UpdateFragmentNode } from '../types/Update';
import { UpdateChannelBasicInfoFragmentNode } from '../types/UpdateChannelBasicInfo';
type ViewUpdateChannelsOnAppObject = NonNullable<
@@ -28,16 +28,32 @@ type UpdateChannelByNameObject = NonNullable<
// these types should have the same fields
export type UpdateChannelObject = ViewUpdateChannelsOnAppObject & UpdateChannelByNameObject;
export type UpdateBranchObject = UpdateChannelObject['updateBranches'][number];
export function composeUpdateBranchObject(
branchInfo: UpdateBranchBasicInfoFragment,
updateGroups: UpdateFragment[][]
): UpdateBranchObject {
return {
...branchInfo,
updateGroups,
};
}
export const ChannelQuery = {
async viewUpdateChannelAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, channelName }: ViewUpdateChannelOnAppQueryVariables
{ appId, channelName, filter }: ViewUpdateChannelOnAppQueryVariables
): Promise<UpdateChannelByNameObject> {
const response = await withErrorHandlingAsync(
graphqlClient
.query<ViewUpdateChannelOnAppQuery, ViewUpdateChannelOnAppQueryVariables>(
gql`
query ViewUpdateChannelOnApp($appId: String!, $channelName: String!) {
query ViewUpdateChannelOnApp(
$appId: String!
$channelName: String!
$filter: UpdatesFilter
) {
app {
byId(appId: $appId) {
id
@@ -48,15 +64,19 @@ export const ChannelQuery = {
branchMapping
updateBranches(offset: 0, limit: 5) {
id
...UpdateBranchWithCurrentGroupFragment
name
updateGroups(offset: 0, limit: 1, filter: $filter) {
id
...UpdateFragment
}
}
}
}
}
}
${print(UpdateBranchWithCurrentGroupFragmentNode)}
${print(UpdateFragmentNode)}
`,
{ appId, channelName },
{ appId, channelName, filter },
{ additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] }
)
.toPromise()
@@ -88,13 +108,17 @@ export const ChannelQuery = {
branchMapping
updateBranches(offset: 0, limit: 5) {
id
...UpdateBranchWithCurrentGroupFragment
name
updateGroups(offset: 0, limit: 1) {
id
...UpdateFragment
}
}
}
}
}
}
${print(UpdateBranchWithCurrentGroupFragmentNode)}
${print(UpdateFragmentNode)}
`,
{ appId, offset, limit },
{ additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] }
@@ -111,8 +135,8 @@ export const ChannelQuery = {
},
async viewUpdateChannelsBasicInfoPaginatedOnAppAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, first, after }: ViewUpdateChannelsPaginatedOnAppQueryVariables
): Promise<[UpdateChannelBasicInfoFragment[], PageInfo]> {
{ appId, first, after, last, before }: ViewUpdateChannelsPaginatedOnAppQueryVariables
): Promise<ViewUpdateChannelsPaginatedOnAppQuery['app']['byId']['channelsPaginated']> {
const response = await withErrorHandlingAsync(
graphqlClient
.query<
@@ -120,16 +144,23 @@ export const ChannelQuery = {
ViewUpdateChannelsPaginatedOnAppQueryVariables
>(
gql`
query ViewUpdateChannelsPaginatedOnApp($appId: String!, $first: Int, $after: String) {
query ViewUpdateChannelsPaginatedOnApp(
$appId: String!
$first: Int
$after: String
$last: Int
$before: String
) {
app {
byId(appId: $appId) {
id
channelsPaginated(first: $first, after: $after) {
channelsPaginated(first: $first, after: $after, before: $before, last: $last) {
edges {
node {
id
...UpdateChannelBasicInfoFragment
}
cursor
}
pageInfo {
hasNextPage
@@ -143,7 +174,7 @@ export const ChannelQuery = {
}
${print(UpdateChannelBasicInfoFragmentNode)}
`,
{ appId, first, after },
{ appId, first, after, last, before },
{ additionalTypenames: ['UpdateChannel', 'UpdateBranch', 'Update'] }
)
.toPromise()
@@ -153,7 +184,6 @@ export const ChannelQuery = {
if (!channelsPaginated) {
throw new Error(`Could not find channels on project with id ${appId}`);
}
return [channelsPaginated.edges.map(edge => edge.node) ?? [], channelsPaginated.pageInfo];
return channelsPaginated;
},
};
@@ -0,0 +1,85 @@
import { print } from 'graphql';
import gql from 'graphql-tag';
import { BranchNotFoundError } from '../../branch/utils';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { Connection } from '../../utils/relay';
import { withErrorHandlingAsync } from '../client';
import {
RuntimeFragment,
ViewRuntimesOnBranchQuery,
ViewRuntimesOnBranchQueryVariables,
} from '../generated';
import { RuntimeFragmentNode } from '../types/Runtime';
export const RuntimeQuery = {
async getRuntimesOnBranchAsync(
graphqlClient: ExpoGraphqlClient,
{ appId, name, first, after, last, before, filter }: ViewRuntimesOnBranchQueryVariables
): Promise<Connection<RuntimeFragment>> {
const response = await withErrorHandlingAsync<ViewRuntimesOnBranchQuery>(
graphqlClient
.query<ViewRuntimesOnBranchQuery, ViewRuntimesOnBranchQueryVariables>(
gql`
query ViewRuntimesOnBranch(
$appId: String!
$name: String!
$first: Int
$after: String
$last: Int
$before: String
$filter: RuntimeFilterInput
) {
app {
byId(appId: $appId) {
id
updateBranchByName(name: $name) {
id
runtimes(
first: $first
after: $after
before: $before
last: $last
filter: $filter
) {
edges {
node {
id
...RuntimeFragment
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
}
}
}
${print(RuntimeFragmentNode)}
`,
{
appId,
name,
first,
after,
last,
before,
filter,
},
{ additionalTypenames: ['UpdateBranch', 'Runtime'] }
)
.toPromise()
);
const { updateBranchByName } = response.app.byId;
if (!updateBranchByName) {
throw new BranchNotFoundError(`Could not find a branch named "${name}".`);
}
return updateBranchByName.runtimes;
},
};
@@ -0,0 +1,8 @@
import gql from 'graphql-tag';
export const RuntimeFragmentNode = gql`
fragment RuntimeFragment on Runtime {
id
version
}
`;
@@ -2,15 +2,17 @@ import { print } from 'graphql';
import gql from 'graphql-tag';
import { UpdateFragmentNode } from './Update';
import { UpdateBranchBasicInfoFragmentNode } from './UpdateBranchBasicInfo';
export const UpdateBranchFragmentNode = gql`
fragment UpdateBranchFragment on UpdateBranch {
id
name
...UpdateBranchBasicInfoFragment
updates(offset: 0, limit: 10) {
id
...UpdateFragment
}
}
${print(UpdateFragmentNode)}
${print(UpdateBranchBasicInfoFragmentNode)}
`;
@@ -0,0 +1,8 @@
import gql from 'graphql-tag';
export const UpdateBranchBasicInfoFragmentNode = gql`
fragment UpdateBranchBasicInfoFragment on UpdateBranch {
id
name
}
`;
@@ -1,16 +0,0 @@
import { print } from 'graphql';
import gql from 'graphql-tag';
import { UpdateFragmentNode } from './Update';
export const UpdateBranchWithCurrentGroupFragmentNode = gql`
fragment UpdateBranchWithCurrentGroupFragment on UpdateBranch {
id
name
updateGroups(offset: 0, limit: 1) {
id
...UpdateFragment
}
}
${print(UpdateFragmentNode)}
`;
@@ -5,6 +5,7 @@ import { AppleDeviceClass } from '../../generated';
export const APPLE_DEVICE_CLASS_LABELS: Record<AppleDeviceClass, string> = {
[AppleDeviceClass.Ipad]: 'iPad',
[AppleDeviceClass.Iphone]: 'iPhone',
[AppleDeviceClass.Mac]: 'Mac',
};
export const AppleDeviceFragmentNode = gql`
+4
View File
@@ -57,6 +57,10 @@ export default class Log {
Log.consoleLog(chalk.green(figures.tick), ...args);
}
public static withInfo(...args: any[]): void {
Log.consoleLog(chalk.green(figures.info), ...args);
}
private static consoleLog(...args: any[]): void {
Log.updateIsLastLineNewLine(args);
// eslint-disable-next-line no-console
@@ -180,7 +180,7 @@ export class AppleConfigReader {
return {
locale,
description: info.description,
keywords: info.keywords?.join(', '),
keywords: info.keywords?.join(','),
// TODO: maybe move this to task logic, it's more an exception than data handling
whatsNew: context.versionIsFirst ? undefined : info.releaseNotes || DEFAULT_WHATSNEW,
marketingUrl: info.marketingUrl,
+2 -2
View File
@@ -38,7 +38,7 @@ const AppExtensionsConfigSchema = Joi.array().items(
})
);
export async function resolveMangedProjectTargetsAsync({
export async function resolveManagedProjectTargetsAsync({
exp,
projectDir,
xcodeBuildContext,
@@ -138,7 +138,7 @@ export async function resolveTargetsAsync(opts: ResolveTargetOptions): Promise<T
if (workflow === Workflow.GENERIC) {
return await resolveBareProjectTargetsAsync(opts);
} else if (workflow === Workflow.MANAGED) {
return await resolveMangedProjectTargetsAsync(opts);
return await resolveManagedProjectTargetsAsync(opts);
} else {
throw new Error(`Unknown workflow: ${workflow}`);
}
+11 -4
View File
@@ -193,6 +193,9 @@ export async function buildBundlesAsync({
throw new Error('Could not locate package.json');
}
const platformArgs =
platformFlag === 'all' ? ['--platform', 'ios', '--platform', 'android'] : [platformFlag];
if (shouldUseVersionedExpoCLI(projectDir, exp)) {
await expoCommandAsync(projectDir, [
'export',
@@ -200,8 +203,7 @@ export async function buildBundlesAsync({
inputDir,
'--dump-sourcemap',
'--dump-assetmap',
'--platform',
platformFlag,
...platformArgs,
...(clearCache ? ['--clear'] : []),
]);
} else {
@@ -214,8 +216,7 @@ export async function buildBundlesAsync({
'--non-interactive',
'--dump-sourcemap',
'--dump-assetmap',
'--platform',
platformFlag,
...platformArgs,
...(clearCache ? ['--clear'] : []),
]);
}
@@ -682,3 +683,9 @@ export function getRuntimeToPlatformMappingFromRuntimeVersions(
}
return runtimeToPlatformMapping;
}
export const platformDisplayNames: Record<Platform, string> = {
android: 'Android',
ios: 'iOS',
web: 'Web',
};
@@ -0,0 +1,352 @@
import { v4 as uuidv4 } from 'uuid';
import {
channelInfoWithBranches,
testBasicBranchInfo1,
testBasicBranchInfo2,
testChannelBasicInfo,
} from '../../channel/__tests__/branch-mapping-fixtures';
import {
BranchMappingOperator,
BranchMappingValidationError,
alwaysTrue,
andStatement,
equalsOperator,
hashLtOperator,
} from '../../channel/branch-mapping';
import {
assertRolloutBranchMapping,
composeRollout,
createRolloutBranchMapping,
doesTargetRollout,
editRolloutBranchMapping,
getRollout,
getRolloutInfo,
getRolloutInfoFromBranchMapping,
isConstrainedRollout,
isConstrainedRolloutInfo,
isLegacyRolloutInfo,
isRolloutBranchMapping,
} from '../branch-mapping';
import {
rolloutBranchMapping,
rolloutBranchMappingLegacy,
standardBranchMapping,
} from './fixtures';
describe(doesTargetRollout, () => {
it('detects whether a runtime targets a constrained rollout', () => {
expect(doesTargetRollout(rolloutBranchMapping, '1.0.0')).toBe(true);
expect(doesTargetRollout(rolloutBranchMapping, '2.0.0')).toBe(false);
});
it('should always return true if the rollout is unconstrained', () => {
expect(doesTargetRollout(rolloutBranchMappingLegacy, '1.0.0')).toBe(true);
expect(doesTargetRollout(rolloutBranchMappingLegacy, '2.0.0')).toBe(true);
});
});
describe(composeRollout, () => {
it('composes a rollout', () => {
const rollout = getRollout(channelInfoWithBranches);
const rolloutInfo = getRolloutInfo(testChannelBasicInfo);
const composedRollout = composeRollout(rolloutInfo, testBasicBranchInfo2, testBasicBranchInfo1);
expect(composedRollout).toEqual(rollout);
});
it('throws if the branches to not match the rollout info', () => {
const rolloutInfo = getRolloutInfo(testChannelBasicInfo);
expect(() =>
composeRollout(rolloutInfo, testBasicBranchInfo1, testBasicBranchInfo2)
).toThrowError(BranchMappingValidationError);
});
});
describe(createRolloutBranchMapping, () => {
it('creates a rollout branch mapping', () => {
const branchMapping = createRolloutBranchMapping({
defaultBranchId: 'default-branch-id',
rolloutBranchId: 'rollout-branch-id',
percent: 10,
runtimeVersion: '1.0.0',
});
expect(isRolloutBranchMapping(branchMapping)).toBe(true);
});
it('throws if an invalid number is passed in', () => {
expect(() =>
createRolloutBranchMapping({
defaultBranchId: 'default-branch-id',
rolloutBranchId: 'rollout-branch-id',
percent: 0.1,
runtimeVersion: '1.0.0',
})
).toThrowError(BranchMappingValidationError);
expect(() =>
createRolloutBranchMapping({
defaultBranchId: 'default-branch-id',
rolloutBranchId: 'rollout-branch-id',
percent: -1,
runtimeVersion: '1.0.0',
})
).toThrowError(BranchMappingValidationError);
expect(() =>
createRolloutBranchMapping({
defaultBranchId: 'default-branch-id',
rolloutBranchId: 'rollout-branch-id',
percent: 1000,
runtimeVersion: '1.0.0',
})
).toThrowError(BranchMappingValidationError);
});
});
describe(assertRolloutBranchMapping, () => {
it('asserts a rollout branch mapping', () => {
expect(() => assertRolloutBranchMapping(standardBranchMapping)).toThrowError(
BranchMappingValidationError
);
expect(() => assertRolloutBranchMapping(rolloutBranchMapping)).not.toThrowError(
BranchMappingValidationError
);
expect(() => assertRolloutBranchMapping(rolloutBranchMappingLegacy)).not.toThrowError(
BranchMappingValidationError
);
});
});
describe(isLegacyRolloutInfo, () => {
it('classifies rollouts properly', () => {
const constrainedRollout = getRolloutInfoFromBranchMapping(rolloutBranchMapping);
expect(isLegacyRolloutInfo(constrainedRollout)).toBe(false);
const legacyRollout = getRolloutInfoFromBranchMapping(rolloutBranchMappingLegacy);
expect(isLegacyRolloutInfo(legacyRollout)).toBe(true);
});
});
describe(isConstrainedRollout, () => {
it('classifies rollouts properly', () => {
const constrainedRollout = getRolloutInfoFromBranchMapping(rolloutBranchMapping);
expect(isConstrainedRolloutInfo(constrainedRollout)).toBe(true);
const legacyRollout = getRolloutInfoFromBranchMapping(rolloutBranchMappingLegacy);
expect(isConstrainedRolloutInfo(legacyRollout)).toBe(false);
});
});
describe(getRollout, () => {
it('doesnt get the mapping if it isnt a rollout', () => {
const notRollout = { ...channelInfoWithBranches };
notRollout.branchMapping = JSON.stringify(standardBranchMapping);
expect(() => getRollout(notRollout)).toThrowError();
});
it('gets a constrained rollout', () => {
const constrainedRollout = { ...channelInfoWithBranches };
const rolloutBranchMappingWithCorrectBranch = { ...rolloutBranchMapping };
rolloutBranchMappingWithCorrectBranch.data[0].branchId = testBasicBranchInfo1.id;
rolloutBranchMappingWithCorrectBranch.data[1].branchId = testBasicBranchInfo2.id;
constrainedRollout.branchMapping = JSON.stringify(rolloutBranchMapping);
const rollout = getRollout(constrainedRollout);
expect(rollout.percentRolledOut).toEqual(10);
expect(isConstrainedRolloutInfo(rollout)).toBe(true);
expect(rollout.defaultBranch).toEqual(testBasicBranchInfo2);
expect(rollout.rolledOutBranch).toEqual(testBasicBranchInfo1);
expect(rollout.defaultBranchId).toEqual(testBasicBranchInfo2.id);
expect(rollout.rolledOutBranchId).toEqual(testBasicBranchInfo1.id);
});
it('gets a legacy rollout', () => {
const rollout = getRollout(channelInfoWithBranches);
expect(rollout.percentRolledOut).toEqual(15);
expect(isLegacyRolloutInfo(rollout)).toBe(true);
expect(rollout.defaultBranch).toEqual(testBasicBranchInfo2);
expect(rollout.rolledOutBranch).toEqual(testBasicBranchInfo1);
expect(rollout.defaultBranchId).toEqual(testBasicBranchInfo2.id);
expect(rollout.rolledOutBranchId).toEqual(testBasicBranchInfo1.id);
});
});
describe(getRolloutInfoFromBranchMapping, () => {
it('gets a constrained rollout', () => {
const rollout = getRolloutInfoFromBranchMapping(rolloutBranchMapping);
expect(rollout.percentRolledOut).toEqual(10);
expect(isConstrainedRolloutInfo(rollout)).toBe(true);
expect(rollout.defaultBranchId).toEqual(rolloutBranchMapping.data[1].branchId);
expect(rollout.rolledOutBranchId).toEqual(rolloutBranchMapping.data[0].branchId);
});
it('gets a legacy rollout', () => {
const rollout = getRolloutInfoFromBranchMapping(rolloutBranchMappingLegacy);
expect(rollout.percentRolledOut).toEqual(10);
expect(isLegacyRolloutInfo(rollout)).toBe(true);
expect(rollout.defaultBranchId).toEqual(rolloutBranchMappingLegacy.data[1].branchId);
expect(rollout.rolledOutBranchId).toEqual(rolloutBranchMappingLegacy.data[0].branchId);
});
});
describe(editRolloutBranchMapping, () => {
it('doesnt edit the branch mapping if the input is out of range', () => {
expect(() => editRolloutBranchMapping(rolloutBranchMapping, -1)).toThrowError();
expect(() => editRolloutBranchMapping(rolloutBranchMapping, 101)).toThrowError();
expect(() => editRolloutBranchMapping(rolloutBranchMapping, 0.1)).toThrowError();
});
it('returns a new instance of a branch mapping', () => {
const editedBranchMapping = editRolloutBranchMapping(rolloutBranchMapping, 50);
expect(rolloutBranchMapping).not.toBe(editedBranchMapping);
});
it('edits the branch mapping for a constrained rollout', () => {
const editedBranchMapping = editRolloutBranchMapping(rolloutBranchMapping, 50);
const rollout = getRolloutInfoFromBranchMapping(editedBranchMapping);
expect(rollout.percentRolledOut).toEqual(50);
expect(isConstrainedRolloutInfo(rollout)).toBe(true);
});
it('edits the branch mapping for a legacy rollout', () => {
const editedBranchMapping = editRolloutBranchMapping(rolloutBranchMappingLegacy, 50);
const rollout = getRolloutInfoFromBranchMapping(editedBranchMapping);
expect(rollout.percentRolledOut).toEqual(50);
expect(isLegacyRolloutInfo(rollout)).toBe(true);
});
});
describe(isRolloutBranchMapping, () => {
it('detects a rollout made by the cli', () => {
expect(isRolloutBranchMapping(rolloutBranchMappingLegacy)).toBe(true);
expect(isRolloutBranchMapping(rolloutBranchMapping)).toBe(true);
});
it('detects custom mappings equivalent to rollouts made by the cli', () => {
const customMapping1 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRolloutBranchMapping(customMapping1)).toBe(true);
});
it('correctly classifies branchMappings that arent rollouts', () => {
expect(isRolloutBranchMapping(standardBranchMapping)).toBe(false);
const customMapping1 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_gt' as BranchMappingOperator,
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRolloutBranchMapping(customMapping1)).toBe(false);
const customMapping2 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRolloutBranchMapping(customMapping2)).toBe(false);
const customMapping3 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRolloutBranchMapping(customMapping3)).toBe(false);
const customMapping4 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
},
],
};
expect(isRolloutBranchMapping(customMapping4)).toBe(false);
const customMapping5 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
{
operand: '2.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRolloutBranchMapping(customMapping5)).toBe(false);
const customMapping6 = {
version: 0,
data: [
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
},
],
};
expect(isRolloutBranchMapping(customMapping6)).toBe(false);
});
});
@@ -0,0 +1,75 @@
import { v4 as uuidv4 } from 'uuid';
import { BranchMapping, alwaysTrue } from '../../channel/branch-mapping';
import { ConstrainedRolloutBranchMapping, LegacyRolloutBranchMapping } from '../branch-mapping';
export const rolloutBranchMapping: ConstrainedRolloutBranchMapping = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: [
'and',
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: '==',
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_lt',
},
],
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
export const rolloutBranchMapping2: ConstrainedRolloutBranchMapping = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: [
'and',
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_lt',
},
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: '==',
},
],
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
export const rolloutBranchMappingLegacy: LegacyRolloutBranchMapping = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_lt',
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
export const standardBranchMapping: BranchMapping = {
version: 0,
data: [{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() }],
};
export const emptyBranchMapping: BranchMapping = {
version: 0,
data: [],
};
@@ -1,200 +0,0 @@
import { v4 as uuidv4 } from 'uuid';
import {
BranchMappingOperator,
alwaysTrue,
andStatement,
equalsOperator,
hashLtOperator,
} from '../../channel/branch-mapping';
import { isRollout } from '../utils';
const rolloutBranchMapping = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
const rolloutBranchMappingLegacy = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
const standardBranchMapping = {
version: 0,
data: [{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() }],
};
describe(isRollout, () => {
it('detects a rollout made by the cli', () => {
expect(isRollout(rolloutBranchMappingLegacy)).toBe(true);
expect(isRollout(rolloutBranchMapping)).toBe(true);
});
it('detects custom mappings equivalent to rollouts made by the cli', () => {
const customMapping1 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRollout(customMapping1)).toBe(true);
});
it('correctly classifies branchMappings that arent rollouts', () => {
expect(isRollout(standardBranchMapping)).toBe(false);
const customMapping1 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_gt' as BranchMappingOperator,
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRollout(customMapping1)).toBe(false);
const customMapping2 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRollout(customMapping2)).toBe(false);
const customMapping3 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRollout(customMapping3)).toBe(false);
const customMapping4 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'FOOBAR',
branchMappingOperator: hashLtOperator(),
},
},
],
};
expect(isRollout(customMapping4)).toBe(false);
const customMapping5 = {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
{
operand: '2.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
};
expect(isRollout(customMapping5)).toBe(false);
const customMapping6 = {
version: 0,
data: [
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
},
],
};
expect(isRollout(customMapping6)).toBe(false);
});
});
@@ -0,0 +1,332 @@
import { Updates } from '@expo/config-plugins';
import assert from 'assert';
import { SelectBranch } from '../../branch/actions/SelectBranch';
import {
getStandardBranchId,
hasEmptyBranchMap,
hasStandardBranchMap,
} from '../../channel/branch-mapping';
import { getUpdateBranch } from '../../channel/utils';
import { updateChannelBranchMappingAsync } from '../../commands/channel/edit';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import {
UpdateBranchBasicInfoFragment,
UpdateChannelBasicInfoFragment,
UpdateFragment,
} from '../../graphql/generated';
import { BranchQuery } from '../../graphql/queries/BranchQuery';
import {
ChannelQuery,
UpdateChannelObject,
composeUpdateBranchObject,
} from '../../graphql/queries/ChannelQuery';
import { UpdateQuery } from '../../graphql/queries/UpdateQuery';
import Log from '../../log';
import { confirmAsync, promptAsync } from '../../prompts';
import { truthy } from '../../utils/expodash/filter';
import {
composeRollout,
createRolloutBranchMapping,
getRolloutInfoFromBranchMapping,
isRollout,
} from '../branch-mapping';
import {
displayRolloutDetails,
formatBranchWithUpdateGroup,
promptForRolloutPercentAsync,
} from '../utils';
import { SelectRuntime } from './SelectRuntime';
export type NonInteractiveOptions = {
branchNameToRollout: string;
percent: number;
runtimeVersion: string;
};
function isNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): options is NonInteractiveOptions {
return !!options.branchNameToRollout && !!options.percent && !!options.runtimeVersion;
}
function assertNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): asserts options is NonInteractiveOptions {
assert(
isNonInteractiveOptions(options),
'--branch, --percent and --runtime-version are required for creating a rollout in non-interactive mode.'
);
}
/**
* Create a rollout for the project.
*/
export class CreateRollout implements EASUpdateAction<UpdateChannelBasicInfoFragment> {
constructor(
private channelInfo: UpdateChannelBasicInfoFragment,
private options: Partial<NonInteractiveOptions> = {}
) {}
public async runAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment> {
const { branchNameToRollout } = this.options;
const { nonInteractive, graphqlClient } = ctx;
if (nonInteractive) {
assertNonInteractiveOptions(this.options);
}
if (isRollout(this.channelInfo)) {
throw new Error(`A rollout is already in progress for channel ${this.channelInfo.name}`);
}
if (hasEmptyBranchMap(this.channelInfo)) {
throw new Error(
`Your channel needs to be linked to a branch before a rollout can be created. Do this by running 'eas channel:edit'`
);
}
if (!hasStandardBranchMap(this.channelInfo)) {
throw new Error(
`You have a custom branch mapping. Map your channel to a single branch before creating a rollout. Received: ${this.channelInfo.branchMapping}`
);
}
const defaultBranchId = getStandardBranchId(this.channelInfo);
const branchInfoToRollout = branchNameToRollout
? await this.resolveBranchNameAsync(ctx, branchNameToRollout)
: await this.selectBranchAsync(ctx, defaultBranchId);
if (branchInfoToRollout.id === defaultBranchId) {
throw new Error(
`Channel ${this.channelInfo.name} is already mapped to branch ${branchInfoToRollout.name}.`
);
}
const runtimeVersion =
this.options.runtimeVersion ??
(await this.selectRuntimeVersionAsync(ctx, branchInfoToRollout, defaultBranchId));
Log.newLine();
const promptMessage = `What percent of users should be rolled out to branch ${branchInfoToRollout.name}?`;
const percent = this.options.percent ?? (await promptForRolloutPercentAsync({ promptMessage }));
const rolloutBranchMapping = createRolloutBranchMapping({
defaultBranchId,
rolloutBranchId: branchInfoToRollout.id,
percent,
runtimeVersion,
});
const channelObject = await this.getChannelObjectAsync(ctx, runtimeVersion);
const defaultBranch = getUpdateBranch(channelObject, defaultBranchId);
const defaultUpdateGroup = defaultBranch.updateGroups[0];
const rolloutInfo = getRolloutInfoFromBranchMapping(rolloutBranchMapping);
const rolledOutBranchUpdateGroup = await this.getLatestUpdateGroupOnBranchAsync(
ctx,
branchInfoToRollout,
runtimeVersion
);
const rolledOutBranch = composeUpdateBranchObject(
branchInfoToRollout,
rolledOutBranchUpdateGroup ? [rolledOutBranchUpdateGroup] : []
);
const rollout = composeRollout(rolloutInfo, defaultBranch, rolledOutBranch);
displayRolloutDetails(this.channelInfo.name, rollout);
Log.log(
formatBranchWithUpdateGroup(defaultUpdateGroup, defaultBranch, 100 - rollout.percentRolledOut)
);
Log.addNewLineIfNone();
Log.log(
formatBranchWithUpdateGroup(
rolledOutBranchUpdateGroup,
rolledOutBranch,
rollout.percentRolledOut
)
);
Log.addNewLineIfNone();
const didConfirm = await this.confirmCreationAsync(ctx);
if (!didConfirm) {
throw new Error('Aborting...');
}
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: this.channelInfo.id,
branchMapping: JSON.stringify(rolloutBranchMapping),
});
Log.succeed('✅ Successfully created rollout');
return newChannelInfo;
}
async confirmCreationAsync(ctx: EASUpdateContext): Promise<boolean> {
const { nonInteractive } = ctx;
if (nonInteractive) {
return true;
}
return await confirmAsync({
message: `Create rollout?`,
});
}
async getChannelObjectAsync(
ctx: EASUpdateContext,
runtimeVersion: string
): Promise<UpdateChannelObject> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
return await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: this.channelInfo.name,
filter: { runtimeVersions: [runtimeVersion] },
});
}
async getLatestUpdateGroupOnBranchAsync(
ctx: EASUpdateContext,
branchInfo: UpdateBranchBasicInfoFragment,
runtimeVersion: string
): Promise<UpdateFragment[] | null> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
const updateGroups = await UpdateQuery.viewUpdateGroupsOnBranchAsync(graphqlClient, {
appId: projectId,
branchName: branchInfo.name,
limit: 1,
offset: 0,
filter: {
runtimeVersions: [runtimeVersion],
},
});
assert(
updateGroups.length < 2,
`Expected at most one update group. Received: ${JSON.stringify(updateGroups)}`
);
return updateGroups[0] ?? null;
}
async selectRuntimeVersionAsync(
ctx: EASUpdateContext,
branchToRollout: UpdateBranchBasicInfoFragment,
defaultBranchId: string
): Promise<string> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
// we just want the branch name, not the update group
const channelObjectRtvAgnostic = await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: this.channelInfo.name,
});
const defaultBranchRtvAgnostic = getUpdateBranch(channelObjectRtvAgnostic, defaultBranchId);
const selectSharedRuntimeAction = new SelectRuntime(branchToRollout, {
anotherBranchToIntersectRuntimesBy: defaultBranchRtvAgnostic,
});
const sharedRuntime = await selectSharedRuntimeAction.runAsync(ctx);
if (sharedRuntime) {
return sharedRuntime;
}
return await this.selectRuntimeVersionFromAlternativeSourceAsync(
ctx,
branchToRollout,
defaultBranchRtvAgnostic
);
}
async selectRuntimeVersionFromAlternativeSourceAsync(
ctx: EASUpdateContext,
branchToRollout: UpdateBranchBasicInfoFragment,
defaultBranch: UpdateBranchBasicInfoFragment
): Promise<string> {
const { runtimeSource: selectedRuntimeSource } = await promptAsync({
type: 'select',
name: 'runtimeSource',
message: `What would you like to do?`,
choices: [
{
value: 'DEFAULT_BRANCH_RUNTIME',
title: `Find a runtime supported on the ${defaultBranch.name} branch`,
},
{
value: 'ROLLED_OUT_BRANCH_RUNTIME',
title: `Find a runtime supported on the ${branchToRollout.name} branch`,
},
{
value: 'PROJECT_RUNTIME',
title: 'Use the runtime specified in your project config',
},
],
});
if (selectedRuntimeSource === 'DEFAULT_BRANCH_RUNTIME') {
const selectDefaultBranchRuntimeAction = new SelectRuntime(defaultBranch);
const defaultBranchRuntime = await selectDefaultBranchRuntimeAction.runAsync(ctx);
if (defaultBranchRuntime) {
return defaultBranchRuntime;
}
} else if (selectedRuntimeSource === 'ROLLED_OUT_BRANCH_RUNTIME') {
const selectBranchToRolloutRuntimeAction = new SelectRuntime(branchToRollout);
const branchToRolloutRuntime = await selectBranchToRolloutRuntimeAction.runAsync(ctx);
if (branchToRolloutRuntime) {
return branchToRolloutRuntime;
}
} else if (selectedRuntimeSource === 'PROJECT_RUNTIME') {
return await this.selectRuntimeVersionFromProjectConfigAsync(ctx);
} else {
throw new Error(`Unexpected runtime source: ${selectedRuntimeSource}`);
}
return await this.selectRuntimeVersionFromAlternativeSourceAsync(
ctx,
branchToRollout,
defaultBranch
);
}
async selectRuntimeVersionFromProjectConfigAsync(ctx: EASUpdateContext): Promise<string> {
const platforms: ('ios' | 'android')[] = ['ios', 'android'];
const runtimes = platforms
.map(platform => Updates.getRuntimeVersion(ctx.app.exp, platform))
.filter(truthy);
const dedupedRuntimes = [...new Set(runtimes)];
if (dedupedRuntimes.length === 0) {
throw new Error(
`Your project config doesn't specify a runtime. Ensure your project is configured correctly for EAS Update by running \`eas update:configure\``
);
} else if (dedupedRuntimes.length === 1) {
const runtime = dedupedRuntimes[0];
Log.log(`🔧 Your project config currently supports runtime ${runtime}`);
return runtime;
}
const { runtime: selectedRuntime } = await promptAsync({
type: 'select',
name: 'runtime',
message: `Select a runtime supported by your project config`,
choices: runtimes.map((runtime, index) => ({
title: `${runtime} ${index === 0 ? '[iOS runtime]' : '[Android runtime]'}`,
value: runtime,
})),
});
return selectedRuntime;
}
async selectBranchAsync(
ctx: EASUpdateContext,
defaultBranchId: string
): Promise<UpdateBranchBasicInfoFragment> {
const selectBranchAction = new SelectBranch({
printedType: 'branch to roll out',
// we don't want to show the default branch as an option
filterPredicate: (branchInfo: UpdateBranchBasicInfoFragment) =>
branchInfo.id !== defaultBranchId,
});
const branchInfo = await selectBranchAction.runAsync(ctx);
if (!branchInfo) {
// We know the user has at least one branch, since we have `defaultBranchId`
throw new Error(
`You don't have a second branch to roll out. Create it with 'eas branch:create'`
);
}
return branchInfo;
}
async resolveBranchNameAsync(
ctx: EASUpdateContext,
branchName: string
): Promise<UpdateBranchBasicInfoFragment> {
const { graphqlClient, app } = ctx;
return await BranchQuery.getBranchByNameAsync(graphqlClient, {
appId: app.projectId,
name: branchName,
});
}
}
@@ -0,0 +1,118 @@
import assert from 'assert';
import chalk from 'chalk';
import { updateChannelBranchMappingAsync } from '../../commands/channel/edit';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { ChannelQuery, UpdateChannelObject } from '../../graphql/queries/ChannelQuery';
import Log from '../../log';
import { confirmAsync } from '../../prompts';
import {
editRolloutBranchMapping,
getRollout,
getRolloutBranchMapping,
getRolloutInfo,
isConstrainedRolloutInfo,
isRollout,
} from '../branch-mapping';
import { promptForRolloutPercentAsync } from '../utils';
export type NonInteractiveOptions = {
percent: number;
};
function isNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): options is NonInteractiveOptions {
return !!options.percent;
}
function assertNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): asserts options is NonInteractiveOptions {
assert(
isNonInteractiveOptions(options),
'--percent is required for editing a rollout in non-interactive mode.'
);
}
/**
* Edit an existing rollout for the project.
*/
export class EditRollout implements EASUpdateAction<UpdateChannelBasicInfoFragment> {
constructor(
private channelInfo: UpdateChannelBasicInfoFragment,
private options: Partial<NonInteractiveOptions> = {}
) {}
public async runAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment> {
const { nonInteractive, graphqlClient } = ctx;
if (nonInteractive) {
assertNonInteractiveOptions(this.options);
}
const channelObject = await this.getChannelObjectAsync(ctx);
const rollout = getRollout(channelObject);
const { rolledOutBranch, defaultBranch } = rollout;
const promptMessage = `What percent of users should be rolled out to the ${rolledOutBranch.name} branch ?`;
const percent = this.options.percent ?? (await promptForRolloutPercentAsync({ promptMessage }));
if (percent === 0 || percent === 100) {
Log.warn(
`Editing the percent to ${percent} will not end the rollout. You'll need to end the rollout from the main menu.`
);
}
const oldBranchMapping = getRolloutBranchMapping(channelObject.branchMapping);
const newBranchMapping = editRolloutBranchMapping(oldBranchMapping, percent);
Log.newLine();
Log.log(
`📝 ${chalk.bold(percent)}% of users will be rolled out to the ${chalk.bold(
rolledOutBranch.name
)} branch and ${chalk.bold(100 - percent)}% will remain on the ${chalk.bold(
defaultBranch.name
)} branch.`
);
const confirmEdit = await this.confirmEditAsync(ctx);
if (!confirmEdit) {
throw new Error('Aborting...');
}
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: channelObject.id,
branchMapping: JSON.stringify(newBranchMapping),
});
Log.addNewLineIfNone();
Log.log(`✅ Successfuly updated rollout`);
return newChannelInfo;
}
async confirmEditAsync(ctx: EASUpdateContext): Promise<boolean> {
const { nonInteractive } = ctx;
if (nonInteractive) {
return true;
}
return await confirmAsync({
message: `Confirm changes?`,
});
}
async getChannelObjectAsync(ctx: EASUpdateContext): Promise<UpdateChannelObject> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
if (!isRollout(this.channelInfo)) {
throw new Error(
`The channel ${chalk.bold(
this.channelInfo.name
)} is not a rollout. To end a rollout, you must specify a channel with an ongoing rollout.`
);
}
const rolloutInfo = getRolloutInfo(this.channelInfo);
return await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: this.channelInfo.name,
...(isConstrainedRolloutInfo(rolloutInfo)
? { filter: { runtimeVersions: [rolloutInfo.runtimeVersion] } }
: {}),
});
}
}
@@ -0,0 +1,220 @@
import assert from 'assert';
import chalk from 'chalk';
import { getAlwaysTrueBranchMapping } from '../../channel/branch-mapping';
import { updateChannelBranchMappingAsync } from '../../commands/channel/edit';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import {
ChannelQuery,
UpdateBranchObject,
UpdateChannelObject,
} from '../../graphql/queries/ChannelQuery';
import Log from '../../log';
import { confirmAsync, promptAsync } from '../../prompts';
import { republishAsync } from '../../update/republish';
import { getCodeSigningInfoAsync } from '../../utils/code-signing';
import formatFields from '../../utils/formatFields';
import {
Rollout,
getRollout,
getRolloutInfo,
isConstrainedRolloutInfo,
isRollout,
} from '../branch-mapping';
import { formatBranchWithUpdateGroup } from '../utils';
export enum EndOutcome {
REPUBLISH_AND_REVERT = 'republish-and-revert',
REVERT = 'revert',
}
export type GeneralOptions = {
privateKeyPath: string | null;
};
export type NonInteractiveOptions = {
outcome: EndOutcome;
};
function isNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): options is NonInteractiveOptions {
return !!options.outcome;
}
function assertNonInteractiveOptions(
options: Partial<NonInteractiveOptions>
): asserts options is NonInteractiveOptions {
assert(
isNonInteractiveOptions(options),
'--outcome is required for ending a rollout in non-interactive mode.'
);
}
/**
* End an existing rollout for the project.
*/
export class EndRollout implements EASUpdateAction<UpdateChannelBasicInfoFragment> {
constructor(
private channelInfo: UpdateChannelBasicInfoFragment,
private options: Partial<NonInteractiveOptions> & GeneralOptions
) {}
public async runAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment> {
const { nonInteractive } = ctx;
if (nonInteractive) {
assertNonInteractiveOptions(this.options);
}
const channelObject = await this.getChannelObjectAsync(ctx);
const rollout = getRollout(channelObject);
const { rolledOutBranch } = rollout;
const rolledOutUpdateGroup = rolledOutBranch.updateGroups[0];
let outcome: EndOutcome;
if (!rolledOutUpdateGroup) {
Log.log(`⚠️ There is no update group being served on the ${rolledOutBranch.name} branch.`);
assert(
this.options.outcome !== EndOutcome.REPUBLISH_AND_REVERT,
`The only valid outcome for this rollout is to revert users back to the ${rollout.defaultBranch.name} branch. `
);
outcome = EndOutcome.REVERT;
} else {
outcome = this.options.outcome ?? (await this.selectOutcomeAsync(rollout));
}
const didConfirm = await this.confirmOutcomeAsync(ctx, outcome, rollout);
if (!didConfirm) {
throw new Error('Aborting...');
}
return await this.performOutcomeAsync(ctx, rollout, outcome);
}
async getChannelObjectAsync(ctx: EASUpdateContext): Promise<UpdateChannelObject> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
if (!isRollout(this.channelInfo)) {
throw new Error(
`The channel ${chalk.bold(
this.channelInfo.name
)} is not a rollout. To end a rollout, you must specify a channel with an ongoing rollout.`
);
}
const rolloutInfo = getRolloutInfo(this.channelInfo);
return await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: this.channelInfo.name,
...(isConstrainedRolloutInfo(rolloutInfo)
? { filter: { runtimeVersions: [rolloutInfo.runtimeVersion] } }
: {}),
});
}
async selectOutcomeAsync(rollout: Rollout<UpdateBranchObject>): Promise<EndOutcome> {
const { rolledOutBranch, percentRolledOut, defaultBranch } = rollout;
const rolledOutUpdateGroup = rolledOutBranch.updateGroups[0];
const defaultUpdateGroup = defaultBranch.updateGroups[0];
const outcomes = [
{
value: EndOutcome.REPUBLISH_AND_REVERT,
title: formatBranchWithUpdateGroup(rolledOutUpdateGroup, rolledOutBranch, percentRolledOut),
},
{
value: EndOutcome.REVERT,
title: formatBranchWithUpdateGroup(
defaultUpdateGroup,
defaultBranch,
100 - percentRolledOut
),
},
];
const { outcome: selectedOutcome } = await promptAsync({
type: 'select',
name: 'outcome',
message: `Which update group would you like to serve?`,
choices: outcomes,
});
Log.newLine();
if (selectedOutcome === EndOutcome.REPUBLISH_AND_REVERT) {
Log.log(
`➡️ 📱 The update group you chose is served by branch ${chalk.bold(rolledOutBranch.name)}`
);
} else {
Log.log(
`➡️ 📱 The update group you chose is served by branch ${chalk.bold(defaultBranch.name)}`
);
}
return selectedOutcome;
}
async performOutcomeAsync(
ctx: EASUpdateContext,
rollout: Rollout<UpdateBranchObject>,
outcome: EndOutcome
): Promise<UpdateChannelBasicInfoFragment> {
const { graphqlClient, app } = ctx;
const { rolledOutBranch, defaultBranch } = rollout;
const rolledOutUpdateGroup = rolledOutBranch.updateGroups[0];
if (outcome === EndOutcome.REPUBLISH_AND_REVERT) {
const codeSigningInfo = await getCodeSigningInfoAsync(
ctx.app.exp,
this.options.privateKeyPath ?? undefined
);
const arbitraryUpdate = rolledOutUpdateGroup[0];
const { message: oldUpdateMessage, group: oldGroupId } = arbitraryUpdate;
const newUpdateMessage = `Republish "${oldUpdateMessage!}" - group: ${oldGroupId}`;
await republishAsync({
graphqlClient,
app,
updatesToPublish: rolledOutUpdateGroup.map(update => ({
...update,
groupId: update.group,
branchId: update.branch.id,
branchName: update.branch.name,
})),
codeSigningInfo,
targetBranch: { branchId: defaultBranch.id, branchName: defaultBranch.name },
updateMessage: newUpdateMessage,
});
}
const alwaysTrueDefaultBranchMapping = getAlwaysTrueBranchMapping(defaultBranch.id);
const newChannelInfo = await updateChannelBranchMappingAsync(graphqlClient, {
channelId: this.channelInfo.id,
branchMapping: JSON.stringify(alwaysTrueDefaultBranchMapping),
});
Log.addNewLineIfNone();
Log.log(`⬅️ Reverted all users back to branch ${chalk.bold(defaultBranch.name)}`);
Log.log(`✅ Successfully ended rollout`);
return newChannelInfo;
}
async confirmOutcomeAsync(
ctx: EASUpdateContext,
selectedOutcome: EndOutcome,
rollout: Rollout<UpdateBranchObject>
): Promise<boolean> {
const { nonInteractive } = ctx;
if (nonInteractive) {
return true;
}
const { rolledOutBranch, defaultBranch } = rollout;
Log.newLine();
if (selectedOutcome === EndOutcome.REPUBLISH_AND_REVERT) {
Log.log(`Ending the rollout will do the following:`);
const actions = formatFields([
{
label: '1.',
value: `🔁 Republish the update group from ${chalk.bold(
rolledOutBranch.name
)} onto ${chalk.bold(defaultBranch.name)}`,
},
{ label: '2.', value: `⬅️ Revert all users back to ${chalk.bold(defaultBranch.name)}` },
]);
Log.log(actions);
} else {
Log.log(
`⬅️ Ending the rollout will revert all users back to ${chalk.bold(defaultBranch.name)}`
);
}
return await confirmAsync({
message: `Continue?`,
});
}
}
@@ -0,0 +1,96 @@
import assert from 'assert';
import chalk from 'chalk';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { ChannelQuery, UpdateChannelObject } from '../../graphql/queries/ChannelQuery';
import { promptAsync } from '../../prompts';
import { getRolloutInfo, isConstrainedRolloutInfo, isRollout } from '../branch-mapping';
import { printRollout } from '../utils';
import {
EditRollout,
NonInteractiveOptions as EditRolloutNonInteractiveOptions,
} from './EditRollout';
import {
EndRollout,
GeneralOptions as EndRolloutGeneralOptions,
NonInteractiveOptions as EndRolloutNonInteractiveOptions,
} from './EndRollout';
export enum ManageRolloutActions {
EDIT = 'Edit',
END = 'End',
GO_BACK = 'Go back',
}
/**
* Manage a rollout for the project.
*/
export class ManageRollout implements EASUpdateAction<EASUpdateAction> {
constructor(
private channelInfo: UpdateChannelBasicInfoFragment,
private options: {
callingAction?: EASUpdateAction;
action?: ManageRolloutActions.EDIT | ManageRolloutActions.END;
} & Partial<EditRolloutNonInteractiveOptions> &
Partial<EndRolloutNonInteractiveOptions> &
EndRolloutGeneralOptions
) {}
public async runAsync(ctx: EASUpdateContext): Promise<EASUpdateAction> {
const { nonInteractive } = ctx;
if (nonInteractive) {
throw new Error(`rollout selection cannot be run in non-interactive mode.`);
}
const channelObject = await this.getChannelObjectAsync(ctx);
printRollout(channelObject);
const action = this.options.action ?? (await this.selectActionAsync());
switch (action as ManageRolloutActions) {
case ManageRolloutActions.EDIT:
return new EditRollout(this.channelInfo, this.options);
case ManageRolloutActions.END:
return new EndRollout(this.channelInfo, this.options);
case ManageRolloutActions.GO_BACK:
assert(this.options.callingAction, 'calling action must be defined');
return this.options.callingAction;
}
}
async selectActionAsync(): Promise<ManageRolloutActions> {
const manageOptions = [ManageRolloutActions.EDIT, ManageRolloutActions.END];
if (this.options.callingAction) {
manageOptions.push(ManageRolloutActions.GO_BACK);
}
const { manageOption: selectedManageOption } = await promptAsync({
type: 'select',
name: 'manageOption',
message: `What would you like to do?`,
choices: manageOptions.map(manageOption => ({
value: manageOption,
title: manageOption,
})),
});
return selectedManageOption;
}
async getChannelObjectAsync(ctx: EASUpdateContext): Promise<UpdateChannelObject> {
const { graphqlClient, app } = ctx;
const { projectId } = app;
if (!isRollout(this.channelInfo)) {
throw new Error(
`The channel ${chalk.bold(
this.channelInfo.name
)} is not a rollout. To manage a rollout, you must specify a channel with an ongoing rollout.`
);
}
const rolloutInfo = getRolloutInfo(this.channelInfo);
return await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName: this.channelInfo.name,
...(isConstrainedRolloutInfo(rolloutInfo)
? { filter: { runtimeVersions: [rolloutInfo.runtimeVersion] } }
: {}),
});
}
}
@@ -0,0 +1,77 @@
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { ChannelQuery } from '../../graphql/queries/ChannelQuery';
import { CodeSigningInfo } from '../../utils/code-signing';
import {
CreateRollout,
NonInteractiveOptions as CreateRolloutNonInteractiveOptions,
} from './CreateRollout';
import {
EditRollout,
NonInteractiveOptions as EditRolloutNonInteractiveOptions,
} from './EditRollout';
import {
EndRollout,
GeneralOptions as EndRolloutGeneralOptions,
NonInteractiveOptions as EndRolloutNonInteractiveOptions,
} from './EndRollout';
import { ManageRolloutActions } from './ManageRollout';
import { MainMenuActions, RolloutActions } from './RolloutMainMenu';
/**
* Control a rollout in non interactive mode.
*/
export class NonInteractiveRollout implements EASUpdateAction<void> {
constructor(
private options: {
channelName?: string;
codeSigningInfo?: CodeSigningInfo;
action?: RolloutActions;
} & Partial<EditRolloutNonInteractiveOptions> &
Partial<EndRolloutNonInteractiveOptions> &
EndRolloutGeneralOptions &
Partial<CreateRolloutNonInteractiveOptions>
) {}
public async runAsync(ctx: EASUpdateContext): Promise<void> {
const { channelName, action } = this.options;
const { nonInteractive, app, graphqlClient } = ctx;
if (!nonInteractive) {
throw new Error(`This action is meant for non-interactive mode.`);
}
if (!channelName) {
throw new Error(
`The channel argument is required in non-interactive mode. Run eas channel:rollout [channel-name]`
);
}
const channelInfo = await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: app.projectId,
channelName,
});
if (!action) {
throw new Error(`--action is required in non-interactive mode.`);
}
await this.runActionAsync(ctx, action, channelInfo, this.options);
}
async runActionAsync(
ctx: EASUpdateContext,
action: RolloutActions,
channelInfo: UpdateChannelBasicInfoFragment,
options: Partial<EditRolloutNonInteractiveOptions> &
Partial<EndRolloutNonInteractiveOptions> &
EndRolloutGeneralOptions &
Partial<CreateRolloutNonInteractiveOptions>
): Promise<UpdateChannelBasicInfoFragment> {
switch (action) {
case MainMenuActions.CREATE_NEW:
return await new CreateRollout(channelInfo, options).runAsync(ctx);
case ManageRolloutActions.EDIT:
return await new EditRollout(channelInfo, options).runAsync(ctx);
case ManageRolloutActions.END:
return await new EndRollout(channelInfo, options).runAsync(ctx);
}
}
}
@@ -0,0 +1,149 @@
import assert from 'assert';
import { SelectChannel } from '../../channel/actions/SelectChannel';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { ChannelQuery } from '../../graphql/queries/ChannelQuery';
import Log from '../../log';
import { promptAsync } from '../../prompts';
import { isRollout } from '../branch-mapping';
import {
CreateRollout,
NonInteractiveOptions as CreateRolloutNonInteractiveOptions,
} from './CreateRollout';
import { NonInteractiveOptions as EditRolloutNonInteractiveOptions } from './EditRollout';
import {
GeneralOptions as EndRolloutGeneralOptions,
NonInteractiveOptions as EndRolloutNonInteractiveOptions,
} from './EndRollout';
import { ManageRollout, ManageRolloutActions } from './ManageRollout';
import { SelectRollout } from './SelectRollout';
export enum MainMenuActions {
CREATE_NEW = 'Create a new rollout',
MANAGE_EXISTING = 'Manage an existing rollout',
}
export type RolloutActions =
| MainMenuActions.CREATE_NEW
| ManageRolloutActions.EDIT
| ManageRolloutActions.END;
/**
* Manage a rollout for the project.
*/
export class RolloutMainMenu implements EASUpdateAction<void> {
constructor(
private options: {
channelName?: string;
action?: RolloutActions;
} & Partial<EditRolloutNonInteractiveOptions> &
Partial<EndRolloutNonInteractiveOptions> &
EndRolloutGeneralOptions &
Partial<CreateRolloutNonInteractiveOptions>
) {}
public async runAsync(ctx: EASUpdateContext): Promise<void> {
const { action } = this.options;
const { nonInteractive } = ctx;
if (nonInteractive) {
throw new Error(`rollout main menu cannot be run in non-interactive mode.`);
}
const menuOption = action ? this.toMainMenuAction(action) : await this.promptMenuActionAsync();
await this.runActionAsync(ctx, menuOption);
}
async runActionAsync(ctx: EASUpdateContext, menuAction: MainMenuActions): Promise<null> {
const { channelName } = this.options;
switch (menuAction) {
case MainMenuActions.CREATE_NEW: {
const channelInfo = channelName
? await this.resolveChannelNameAsync(ctx, channelName)
: await this.selectChannelToRolloutAsync(ctx);
await new CreateRollout(channelInfo, this.options).runAsync(ctx);
return null;
}
case MainMenuActions.MANAGE_EXISTING: {
const channelInfo = channelName
? await this.resolveChannelNameAsync(ctx, channelName)
: await this.selectRolloutAsync(ctx);
if (!channelInfo) {
Log.log('You dont have any rollouts.');
} else {
assert(
this.options.action !== MainMenuActions.CREATE_NEW,
'Invalid route for create action'
);
const manageAction = await new ManageRollout(channelInfo, {
...this.options,
action: this.options.action,
callingAction: this,
}).runAsync(ctx);
await manageAction.runAsync(ctx);
}
return null;
}
}
}
async selectRolloutAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment | null> {
const selectRollout = new SelectRollout();
const channelInfo = await selectRollout.runAsync(ctx);
return channelInfo;
}
async selectChannelToRolloutAsync(
ctx: EASUpdateContext
): Promise<UpdateChannelBasicInfoFragment> {
let hasSomeChannel = false;
const selectChannelAction = new SelectChannel({
filterPredicate: (channelInfo: UpdateChannelBasicInfoFragment) => {
hasSomeChannel = true;
return !isRollout(channelInfo);
},
});
const channelInfo = await selectChannelAction.runAsync(ctx);
if (!channelInfo) {
const error = hasSomeChannel
? new Error('All your channels are already part of a rollout.')
: new Error(`You dont have any channels. Create one with \`eas channel:create\``);
throw error;
}
return channelInfo;
}
async resolveChannelNameAsync(
ctx: EASUpdateContext,
channelName: string
): Promise<UpdateChannelBasicInfoFragment> {
const { graphqlClient, app } = ctx;
return await ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: app.projectId,
channelName,
});
}
toMainMenuAction(action: RolloutActions): MainMenuActions {
if (action === MainMenuActions.CREATE_NEW) {
return MainMenuActions.CREATE_NEW;
} else if (action === ManageRolloutActions.EDIT || action === ManageRolloutActions.END) {
return MainMenuActions.MANAGE_EXISTING;
} else {
throw new Error(`Action not supported yet: ` + action);
}
}
async promptMenuActionAsync(): Promise<MainMenuActions> {
const menuOptions = [MainMenuActions.CREATE_NEW, MainMenuActions.MANAGE_EXISTING];
const { menuOption: selectedMenuOption } = await promptAsync({
type: 'select',
name: 'menuOption',
message: `What would you like to do?`,
choices: menuOptions.map(menuOption => ({
value: menuOption,
title: menuOption,
})),
});
return selectedMenuOption;
}
}
@@ -0,0 +1,38 @@
import { SelectChannel } from '../../channel/actions/SelectChannel';
import { EASUpdateAction, EASUpdateContext } from '../../eas-update/utils';
import { UpdateChannelBasicInfoFragment } from '../../graphql/generated';
import { Ora, ora } from '../../ora';
import { Edge, QueryParams } from '../../utils/relay';
import { isRollout } from '../branch-mapping';
/**
* Select an existing rollout for the project.
*/
export class SelectRollout implements EASUpdateAction<UpdateChannelBasicInfoFragment | null> {
public async runAsync(ctx: EASUpdateContext): Promise<UpdateChannelBasicInfoFragment | null> {
let assetSpinner: Ora | null = null;
const afterEachFilterQuery = (
_externalQueryParams: QueryParams,
totalNodesFetched: number,
_dataset: Edge<UpdateChannelBasicInfoFragment>[],
willFetchAgain: boolean
): void => {
if (willFetchAgain && !assetSpinner) {
assetSpinner = ora().start('Fetching channels...');
}
if (assetSpinner) {
assetSpinner.text = `Fetched ${totalNodesFetched} channels`;
}
};
const selectChannelAction = new SelectChannel({
printedType: 'rollout',
filterPredicate: isRollout,
afterEachFilterQuery,
});
const channelInfo = await selectChannelAction.runAsync(ctx);
if (assetSpinner) {
(assetSpinner as Ora).succeed(`Fetched all channels`);
}
return channelInfo;
}
}
@@ -0,0 +1,201 @@
import assert from 'assert';
import chalk from 'chalk';
import { ExpoGraphqlClient } from '../../commandUtils/context/contextUtils/createGraphqlClient';
import { EASUpdateAction, EASUpdateContext, NonInteractiveError } from '../../eas-update/utils';
import { RuntimeFragment, UpdateBranchBasicInfoFragment } from '../../graphql/generated';
import { RuntimeQuery } from '../../graphql/queries/RuntimeQuery';
import { UpdateQuery } from '../../graphql/queries/UpdateQuery';
import Log, { learnMore } from '../../log';
import { confirmAsync } from '../../prompts';
import { Connection, QueryParams, selectPaginatedAsync } from '../../utils/relay';
import { formatRuntimeWithUpdateGroup } from '../utils';
/**
* Select a runtime from a branch
*/
export class SelectRuntime implements EASUpdateAction<string | null> {
private printedType;
constructor(
private branchInfo: UpdateBranchBasicInfoFragment,
private options: {
anotherBranchToIntersectRuntimesBy?: UpdateBranchBasicInfoFragment;
} = {}
) {
this.printedType = options.anotherBranchToIntersectRuntimesBy
? `compatible runtime`
: `runtime`;
}
warnNoRuntime(): void {
if (this.options.anotherBranchToIntersectRuntimesBy) {
const intersectBranchName = this.options.anotherBranchToIntersectRuntimesBy.name;
Log.warn(
`⚠️ Branches ${this.branchInfo.name} and ${intersectBranchName} dont have any updates with the same runtime.`
);
Log.warn(
`Your updates could be misconfigured. ${learnMore('https://expo.fyi/eas-update-rollouts')}`
);
} else {
// no runtime on branch means no updates published on branch
Log.warn(`⚠️ There are no updates published on branch ${this.branchInfo.name}.`);
}
}
formatCantFindRuntime(): string {
return `🕵️ Not finding the update you were looking for? ${learnMore(
'https://expo.fyi/eas-update-rollouts'
)}`;
}
public async runAsync(ctx: EASUpdateContext): Promise<string | null> {
const { nonInteractive, graphqlClient, app } = ctx;
const { projectId } = app;
if (nonInteractive) {
throw new NonInteractiveError(`runtime selection cannot be run in non-interactive mode.`);
}
const newestRuntimeConnection = await this.getNewestRuntimeAsync(graphqlClient, {
appId: projectId,
branchName: this.branchInfo.name,
anotherBranchIdToIntersectRuntimesBy: this.options.anotherBranchToIntersectRuntimesBy?.id,
});
if (newestRuntimeConnection.edges.length === 0) {
Log.addNewLineIfNone();
this.warnNoRuntime();
return null;
}
const onlyOneRuntime =
newestRuntimeConnection.edges.length === 1 && !newestRuntimeConnection.pageInfo.hasNextPage;
Log.log(`✅ ${beginSentence(this.printedType)}${onlyOneRuntime ? '' : 's'} detected`);
if (onlyOneRuntime) {
const runtime = newestRuntimeConnection.edges[0].node;
const formattedRuntimeWithGroup = await this.displayLatestUpdateGroupAsync({
graphqlClient,
appId: projectId,
branchName: this.branchInfo.name,
runtime,
});
Log.addNewLineIfNone();
Log.log(formattedRuntimeWithGroup);
Log.addNewLineIfNone();
const useRuntime = await confirmAsync({
message: `Target ${this.printedType} ${chalk.bold(runtime.version)}?`,
});
if (useRuntime) {
return runtime.version;
} else {
Log.newLine();
Log.warn(this.formatCantFindRuntime());
return null;
}
}
Log.log(this.formatCantFindRuntime());
const selectedRuntime = await this.selectRuntimesAsync(graphqlClient, {
appId: projectId,
});
if (!selectedRuntime) {
throw new Error(`No ${this.printedType} selected`);
}
return selectedRuntime.version;
}
async getNewestRuntimeAsync(
graphqlClient: ExpoGraphqlClient,
{
appId,
branchName,
anotherBranchIdToIntersectRuntimesBy,
}: {
appId: string;
branchName: string;
anotherBranchIdToIntersectRuntimesBy?: string;
}
): Promise<Connection<RuntimeFragment>> {
return await RuntimeQuery.getRuntimesOnBranchAsync(graphqlClient, {
appId,
name: branchName,
first: 1,
filter: {
branchId: anotherBranchIdToIntersectRuntimesBy,
},
});
}
async displayLatestUpdateGroupAsync({
graphqlClient,
appId,
branchName,
runtime,
}: {
graphqlClient: ExpoGraphqlClient;
appId: string;
branchName: string;
runtime: RuntimeFragment;
}): Promise<string> {
const updateGroups = await UpdateQuery.viewUpdateGroupsOnBranchAsync(graphqlClient, {
appId,
branchName,
limit: 1,
offset: 0,
filter: {
runtimeVersions: [runtime.version],
},
});
assert(
updateGroups.length < 2,
`Expected at most one update group. Received: ${JSON.stringify(updateGroups)}`
);
return formatRuntimeWithUpdateGroup(updateGroups[0], runtime, branchName);
}
async selectRuntimesAsync(
graphqlClient: ExpoGraphqlClient,
{
appId,
batchSize = 5,
}: {
appId: string;
batchSize?: number;
}
): Promise<RuntimeFragment | null> {
const queryAsync = async (queryParams: QueryParams): Promise<Connection<RuntimeFragment>> => {
return await RuntimeQuery.getRuntimesOnBranchAsync(graphqlClient, {
appId,
name: this.branchInfo.name,
first: queryParams.first,
after: queryParams.after,
last: queryParams.last,
before: queryParams.before,
filter: {
branchId: this.options.anotherBranchToIntersectRuntimesBy?.id,
},
});
};
const getTitleAsync = async (runtime: RuntimeFragment): Promise<string> => {
return await this.displayLatestUpdateGroupAsync({
graphqlClient,
appId,
branchName: this.branchInfo.name,
runtime,
});
};
return await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType: 'target runtime',
pageSize: batchSize,
});
}
}
function beginSentence(phrase: string): string {
if (typeof phrase !== 'string' || phrase.length === 0) {
return phrase; // Return the input without any modification if it's not a string or empty
}
return phrase.charAt(0).toUpperCase() + phrase.slice(1);
}
@@ -0,0 +1,88 @@
import { testBasicChannelInfo, testBasicChannelInfo2 } from '../../../channel/__tests__/fixtures';
import { createCtxMock } from '../../../eas-update/__tests__/fixtures';
import { NonInteractiveError } from '../../../eas-update/utils';
import { ChannelQuery } from '../../../graphql/queries/ChannelQuery';
import { promptAsync } from '../../../prompts';
import { standardBranchMapping } from '../../__tests__/fixtures';
import { SelectRollout } from '../SelectRollout';
jest.mock('../../../prompts');
jest.mock('../../../graphql/queries/ChannelQuery');
describe(SelectRollout, () => {
afterEach(() => {
jest.clearAllMocks();
});
it('returns null if project has no rollouts', async () => {
const ctx = createCtxMock();
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const selectRollout = new SelectRollout();
const rollout = await selectRollout.runAsync(ctx);
expect(rollout).toBeNull();
});
it('still prompts if project has only one rollout', async () => {
const ctx = createCtxMock();
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [{ node: testBasicChannelInfo, cursor: 'cursor' }],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicChannelInfo,
}));
const selectRollout = new SelectRollout();
const rollout = await selectRollout.runAsync(ctx);
expect(rollout).toBe(testBasicChannelInfo);
expect(promptAsync).toHaveBeenCalledTimes(1);
});
it('returns the selected rollout', async () => {
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [
{ node: testBasicChannelInfo, cursor: 'cursor' },
{ node: testBasicChannelInfo2, cursor: 'cursor' },
],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: testBasicChannelInfo,
}));
const ctx = createCtxMock();
const selectRollout = new SelectRollout();
const rollout = await selectRollout.runAsync(ctx);
expect(rollout).toBe(testBasicChannelInfo);
});
it('filters the channels for rollouts', async () => {
const standardBranchMappingChannel = { ...testBasicChannelInfo };
standardBranchMappingChannel.branchMapping = JSON.stringify(standardBranchMapping);
const ctx = createCtxMock();
jest.mocked(ChannelQuery.viewUpdateChannelsBasicInfoPaginatedOnAppAsync).mockResolvedValue({
edges: [{ node: standardBranchMappingChannel, cursor: 'cursor' }],
pageInfo: {
hasPreviousPage: false,
hasNextPage: false,
},
});
const selectRollout = new SelectRollout();
const rollout = await selectRollout.runAsync(ctx);
expect(rollout).toBeNull();
});
it('throws an error in Non-Interactive Mode', async () => {
const ctx = createCtxMock({
nonInteractive: true,
});
const selectRollout = new SelectRollout();
// dont fail if users are running in non-interactive mode
await expect(selectRollout.runAsync(ctx)).rejects.toThrowError(NonInteractiveError);
});
});
@@ -0,0 +1,418 @@
import {
BranchMapping,
BranchMappingAlwaysTrue,
BranchMappingNode,
BranchMappingValidationError,
alwaysTrue,
assertNodeObject,
assertNumber,
assertStatement,
assertString,
getBranchMapping,
getNodesFromStatement,
isAlwaysTrue,
isAndStatement,
isStatement,
} from '../channel/branch-mapping';
import {
BranchBasicInfo,
ChannelBasicInfo,
UpdateChannelInfoWithBranches,
getUpdateBranch,
} from '../channel/utils';
export type Rollout<Branch extends BranchBasicInfo> =
| LegacyRollout<Branch>
| ConstrainedRollout<Branch>;
export type RolloutInfo = LegacyRolloutInfo | ConstrainedRolloutInfo;
type ConstrainedRollout<Branch extends BranchBasicInfo> = LegacyRollout<Branch> & {
runtimeVersion: string;
};
type LegacyRollout<Branch extends BranchBasicInfo> = {
rolledOutBranch: Branch;
defaultBranch: Branch;
} & LegacyRolloutInfo;
type ConstrainedRolloutInfo = LegacyRolloutInfo & {
runtimeVersion: string;
};
type LegacyRolloutInfo = {
rolledOutBranchId: string;
percentRolledOut: number;
defaultBranchId: string;
};
export type RolloutBranchMapping = LegacyRolloutBranchMapping | ConstrainedRolloutBranchMapping;
type RolloutNode = {
clientKey: 'rolloutToken';
branchMappingOperator: 'hash_lt';
operand: number;
};
type RuntimeVersionNode = {
clientKey: 'runtimeVersion';
branchMappingOperator: '==';
operand: string;
};
type RtvConstrainedRolloutNode =
| ['and', RolloutNode, RuntimeVersionNode]
| ['and', RuntimeVersionNode, RolloutNode];
export type LegacyRolloutBranchMapping = {
version: number;
data: [
{
branchId: string;
branchMappingLogic: RolloutNode;
},
{
branchId: string;
branchMappingLogic: BranchMappingAlwaysTrue;
}
];
};
export type ConstrainedRolloutBranchMapping = {
version: number;
data: [
{
branchId: string;
branchMappingLogic: RtvConstrainedRolloutNode;
},
{
branchId: string;
branchMappingLogic: BranchMappingAlwaysTrue;
}
];
};
export function isLegacyRolloutInfo(rollout: RolloutInfo): rollout is LegacyRolloutInfo {
return !isConstrainedRolloutInfo(rollout);
}
export function isConstrainedRolloutInfo(rollout: RolloutInfo): rollout is ConstrainedRolloutInfo {
return 'runtimeVersion' in rollout;
}
export function isConstrainedRollout<Branch extends BranchBasicInfo>(
rollout: Rollout<Branch>
): rollout is ConstrainedRollout<Branch> {
return isConstrainedRolloutInfo(rollout);
}
export function getRolloutInfo(basicChannelInfo: ChannelBasicInfo): RolloutInfo {
const rolloutBranchMapping = getRolloutBranchMapping(basicChannelInfo.branchMapping);
return getRolloutInfoFromBranchMapping(rolloutBranchMapping);
}
export function getRolloutInfoFromBranchMapping(branchMapping: RolloutBranchMapping): RolloutInfo {
const rolledOutBranchId = branchMapping.data[0].branchId;
const defaultBranchId = branchMapping.data[1].branchId;
if (isRtvConstrainedRollout(branchMapping)) {
const statementNode = branchMapping.data[0].branchMappingLogic;
assertStatement(statementNode);
const nodesFromStatement = getNodesFromStatement(statementNode);
const runtimeVersionNode = nodesFromStatement.find(isRuntimeVersionNode);
if (!runtimeVersionNode) {
throw new BranchMappingValidationError('Runtime version node must be defined.');
}
assertNodeObject(runtimeVersionNode);
const runtimeVersion = runtimeVersionNode.operand;
assertString(runtimeVersion);
const rolloutNode = nodesFromStatement.find(isRolloutNode);
if (!rolloutNode) {
throw new BranchMappingValidationError('Rollout node must be defined.');
}
assertNodeObject(rolloutNode);
const operand = rolloutNode.operand;
assertNumber(operand);
return {
rolledOutBranchId,
percentRolledOut: Math.round(operand * 100),
runtimeVersion,
defaultBranchId,
};
} else {
const rolloutNode = branchMapping.data[0].branchMappingLogic;
assertNodeObject(rolloutNode);
const operand = rolloutNode.operand;
assertNumber(operand);
return {
rolledOutBranchId,
percentRolledOut: Math.round(operand * 100),
defaultBranchId,
};
}
}
export function getRollout<Branch extends BranchBasicInfo>(
channel: UpdateChannelInfoWithBranches<Branch>
): Rollout<Branch> {
const rolloutBranchMapping = getRolloutBranchMapping(channel.branchMapping);
const rolledOutBranchId = rolloutBranchMapping.data[0].branchId;
const rolledOutBranch = getUpdateBranch(channel, rolledOutBranchId);
const defaultBranchId = rolloutBranchMapping.data[1].branchId;
const defaultBranch = getUpdateBranch(channel, defaultBranchId);
const rolloutInfo = getRolloutInfo(channel);
return composeRollout<Branch>(rolloutInfo, defaultBranch, rolledOutBranch);
}
export function composeRollout<Branch extends BranchBasicInfo>(
rolloutInfo: RolloutInfo,
defaultBranch: Branch,
rolledOutBranch: Branch
): Rollout<Branch> {
if (rolloutInfo.defaultBranchId !== defaultBranch.id) {
throw new BranchMappingValidationError(
`Default branch id must match. Received: ${JSON.stringify(rolloutInfo)} ${defaultBranch.id}`
);
}
if (rolloutInfo.rolledOutBranchId !== rolledOutBranch.id) {
throw new BranchMappingValidationError(
`Rolled out branch id must match. Received: ${JSON.stringify(rolloutInfo)} ${
rolledOutBranch.id
}`
);
}
return {
...rolloutInfo,
rolledOutBranch,
defaultBranch,
};
}
export function getRolloutBranchMapping(branchMappingString: string): RolloutBranchMapping {
const branchMapping = getBranchMapping(branchMappingString);
assertRolloutBranchMapping(branchMapping);
return branchMapping;
}
/**
* Detect if a branch mapping is a rollout.
*
* Types of rollout:
* 1. Legacy unconstrained rollout:
* Maps to a rollout branch via a rollout token
* Falls back to a default branch
*
* Example:
* {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
}
*
* 2. RTV constrained rollout:
* Maps to a rollout branch via a rollout token, constrained by runtime version
* Falls back to a default branch
*
* Example:
* {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
}
*/
export function isRolloutBranchMapping(
branchMapping: BranchMapping
): branchMapping is RolloutBranchMapping {
return isUnconstrainedRollout(branchMapping) || isRtvConstrainedRollout(branchMapping);
}
export function isRollout(channelInfo: ChannelBasicInfo): boolean {
const branchMapping = getBranchMapping(channelInfo.branchMapping);
return isRolloutBranchMapping(branchMapping);
}
export function doesTargetRollout(
branchMapping: RolloutBranchMapping,
runtimeVersion: string
): boolean {
const rolloutInfo = getRolloutInfoFromBranchMapping(branchMapping);
if (!isConstrainedRolloutInfo(rolloutInfo)) {
return true;
}
return rolloutInfo.runtimeVersion === runtimeVersion;
}
export function createRolloutBranchMapping({
defaultBranchId,
rolloutBranchId,
percent,
runtimeVersion,
}: {
defaultBranchId: string;
rolloutBranchId: string;
percent: number;
runtimeVersion: string;
}): ConstrainedRolloutBranchMapping {
assertPercent(percent);
return {
version: 0,
data: [
{
branchId: rolloutBranchId,
branchMappingLogic: [
'and',
{
operand: runtimeVersion,
clientKey: 'runtimeVersion',
branchMappingOperator: '==',
},
{
operand: percent / 100,
clientKey: 'rolloutToken',
branchMappingOperator: 'hash_lt',
},
],
},
{ branchId: defaultBranchId, branchMappingLogic: alwaysTrue() },
],
};
}
export function editRolloutBranchMapping(
branchMapping: RolloutBranchMapping,
percent: number
): RolloutBranchMapping {
assertPercent(percent);
if (isRtvConstrainedRollout(branchMapping)) {
return editRtvConstrainedRollout(branchMapping, percent);
} else {
return editLegacyRollout(branchMapping, percent);
}
}
function editRtvConstrainedRollout(
branchMapping: ConstrainedRolloutBranchMapping,
percent: number
): ConstrainedRolloutBranchMapping {
const newBranchMapping = { ...branchMapping };
const statementNode = newBranchMapping.data[0].branchMappingLogic;
const nodesFromStatement = getNodesFromStatement(statementNode);
const rolloutNode = nodesFromStatement.find(isRolloutNode);
if (!rolloutNode) {
throw new BranchMappingValidationError('Rollout node must be defined.');
}
rolloutNode.operand = percent / 100;
return newBranchMapping;
}
function editLegacyRollout(
branchMapping: LegacyRolloutBranchMapping,
percent: number
): LegacyRolloutBranchMapping {
const newBranchMapping = { ...branchMapping };
const rolloutNode = newBranchMapping.data[0].branchMappingLogic;
rolloutNode.operand = percent / 100;
return newBranchMapping;
}
function isRtvConstrainedRollout(
branchMapping: BranchMapping
): branchMapping is ConstrainedRolloutBranchMapping {
if (branchMapping.data.length !== 2) {
return false;
}
const hasRtvRolloutNode = isRtvConstrainedRolloutNode(branchMapping.data[0].branchMappingLogic);
const defaultsToAlwaysTrueNode = isAlwaysTrue(branchMapping.data[1].branchMappingLogic);
return hasRtvRolloutNode && defaultsToAlwaysTrueNode;
}
function isRtvConstrainedRolloutNode(node: BranchMappingNode): node is RtvConstrainedRolloutNode {
if (!isStatement(node) || !isAndStatement(node)) {
return false;
}
const statementNodes = getNodesFromStatement(node);
if (statementNodes.length !== 2) {
return false;
}
const hasRuntimeVersionNode = statementNodes.some(isRuntimeVersionNode);
const hasRolloutNode = statementNodes.some(isRolloutNode);
return hasRuntimeVersionNode && hasRolloutNode;
}
function isUnconstrainedRollout(
branchMapping: BranchMapping
): branchMapping is LegacyRolloutBranchMapping {
if (branchMapping.data.length !== 2) {
return false;
}
const hasRolloutNode = isRolloutNode(branchMapping.data[0].branchMappingLogic);
const defaultsToAlwaysTrueNode = isAlwaysTrue(branchMapping.data[1].branchMappingLogic);
return hasRolloutNode && defaultsToAlwaysTrueNode;
}
function isRuntimeVersionNode(node: BranchMappingNode): node is RuntimeVersionNode {
if (typeof node === 'string') {
return false;
}
if (Array.isArray(node)) {
return false;
}
return node.clientKey === 'runtimeVersion' && node.branchMappingOperator === '==';
}
function isRolloutNode(node: BranchMappingNode): node is RolloutNode {
if (typeof node === 'string') {
return false;
}
if (Array.isArray(node)) {
return false;
}
return node.clientKey === 'rolloutToken' && node.branchMappingOperator === 'hash_lt';
}
export function assertRolloutBranchMapping(
branchMapping: BranchMapping
): asserts branchMapping is RolloutBranchMapping {
if (!isRolloutBranchMapping(branchMapping)) {
throw new BranchMappingValidationError(
'Branch mapping node must be a rollout. Received: ' + JSON.stringify(branchMapping)
);
}
}
function assertPercent(percent: number): void {
const isPercent = Number.isInteger(percent) && percent >= 0 && percent <= 100;
if (!isPercent) {
throw new BranchMappingValidationError(
`The percentage must be an integer between 0 and 100 inclusive. Received: ${percent}`
);
}
}
+104 -101
View File
@@ -1,116 +1,119 @@
import chalk from 'chalk';
import {
BranchMapping,
BranchMappingNode,
getNodesFromStatement,
isAlwaysTrue,
isAndStatement,
isStatement,
} from '../channel/branch-mapping';
RuntimeFragment,
UpdateBranchBasicInfoFragment,
UpdateFragment,
} from '../graphql/generated';
import { UpdateBranchObject, UpdateChannelObject } from '../graphql/queries/ChannelQuery';
import Log from '../log';
import { promptAsync } from '../prompts';
import { FormattedUpdateGroupDescription, getUpdateGroupDescriptions } from '../update/utils';
import formatFields from '../utils/formatFields';
import { Rollout, getRollout, isConstrainedRollout } from './branch-mapping';
/**
* Detect if a branch mapping is a rollout.
*
* Types of rollout:
* 1. Legacy unconstrained rollout:
* Maps to a rollout branch via a rollout token
* Falls back to a default branch
*
* Example:
* {
version: 0,
data: [
export function printRollout(channel: UpdateChannelObject): void {
const rollout = getRollout(channel);
displayRolloutDetails(channel.name, rollout);
}
export function displayRolloutDetails(
channelName: string,
rollout: Rollout<UpdateBranchBasicInfoFragment>
): void {
const rolledOutPercent = rollout.percentRolledOut;
Log.newLine();
Log.log(chalk.bold('🚀 Rollout:'));
Log.log(
formatFields([
{ label: 'Channel', value: channelName },
...(isConstrainedRollout(rollout)
? [{ label: 'Runtime version', value: rollout.runtimeVersion }]
: []),
{
branchId: uuidv4(),
branchMappingLogic: {
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
label: 'Branches',
value: `${rollout.rolledOutBranch.name} (${rolledOutPercent}%), ${
rollout.defaultBranch.name
} (${100 - rolledOutPercent}%)`,
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
}
*
* 2. RTV constrained rollout:
* Maps to a rollout branch via a rollout token, constrained by runtime version
* Falls back to a default branch
*
* Example:
* {
version: 0,
data: [
{
branchId: uuidv4(),
branchMappingLogic: andStatement([
{
operand: '1.0.0',
clientKey: 'runtimeVersion',
branchMappingOperator: equalsOperator(),
},
{
operand: 10 / 100,
clientKey: 'rolloutToken',
branchMappingOperator: hashLtOperator(),
},
]),
},
{ branchId: uuidv4(), branchMappingLogic: alwaysTrue() },
],
}
*/
export function isRollout(branchMapping: BranchMapping): boolean {
return isUnconstrainedRollout(branchMapping) || isRtvConstrainedRollout(branchMapping);
])
);
Log.addNewLineIfNone();
}
function isRtvConstrainedRollout(branchMapping: BranchMapping): boolean {
if (branchMapping.data.length !== 2) {
return false;
export function formatBranchWithUpdateGroup(
maybeUpdateGroup: UpdateFragment[] | undefined | null,
branch: UpdateBranchObject,
percentRolledOut: number
): string {
const lines: string[] = [];
lines.push(
chalk.bold(
`➡️ 📱 Latest update on the ${chalk.bold(branch.name)} branch (${percentRolledOut}%)`
)
);
if (!maybeUpdateGroup) {
lines.push(`No updates for target runtime`);
} else {
const [updateGroupDescription] = getUpdateGroupDescriptions([maybeUpdateGroup]);
lines.push(...formatUpdateGroup(updateGroupDescription));
}
const hasRtvRolloutNode = isRtvConstrainedRolloutNode(branchMapping.data[0].branchMappingLogic);
const defaultsToAlwaysTrueNode = isAlwaysTrue(branchMapping.data[1].branchMappingLogic);
return hasRtvRolloutNode && defaultsToAlwaysTrueNode;
return lines.join('\n ');
}
function isRtvConstrainedRolloutNode(node: BranchMappingNode): boolean {
if (!isStatement(node) || !isAndStatement(node)) {
return false;
export function formatRuntimeWithUpdateGroup(
maybeUpdateGroup: UpdateFragment[] | undefined | null,
runtime: RuntimeFragment,
branchName: string
): string {
const lines: string[] = [];
lines.push(
chalk.bold(
`➡️ 📱 Latest update on the ${chalk.bold(branchName)} branch served to runtime ${chalk.bold(
runtime.version
)}:`
)
);
if (!maybeUpdateGroup) {
lines.push(`No updates published for this runtime`);
} else {
const [updateGroupDescription] = getUpdateGroupDescriptions([maybeUpdateGroup]);
lines.push(...formatUpdateGroup(updateGroupDescription));
}
const statementNodes = getNodesFromStatement(node);
if (statementNodes.length !== 2) {
return false;
}
const hasRuntimeVersionNode = statementNodes.some(isRuntimeVersionNode);
const hasRolloutNode = statementNodes.some(isRolloutNode);
return hasRuntimeVersionNode && hasRolloutNode;
return lines.join('\n ');
}
function isUnconstrainedRollout(branchMapping: BranchMapping): boolean {
if (branchMapping.data.length !== 2) {
return false;
}
const hasRolloutNode = isRolloutNode(branchMapping.data[0].branchMappingLogic);
const defaultsToAlwaysTrueNode = isAlwaysTrue(branchMapping.data[1].branchMappingLogic);
return hasRolloutNode && defaultsToAlwaysTrueNode;
function formatUpdateGroup(updateGroup: FormattedUpdateGroupDescription): string[] {
const lines: string[] = [];
const formattedLines = formatFields([
{ label: 'Message', value: updateGroup.message ?? 'N/A' },
{ label: 'Runtime version', value: updateGroup.runtimeVersion ?? 'N/A' },
{ label: 'Platforms', value: updateGroup.platforms ?? 'N/A' },
{ label: 'Group ID', value: updateGroup.group ?? 'N/A' },
]).split('\n');
lines.push(...formattedLines);
return lines;
}
function isRuntimeVersionNode(node: BranchMappingNode): boolean {
if (typeof node === 'string') {
return false;
}
if (Array.isArray(node)) {
return false;
}
return node.clientKey === 'runtimeVersion' && node.branchMappingOperator === '==';
}
function isRolloutNode(node: BranchMappingNode): boolean {
if (typeof node === 'string') {
return false;
}
if (Array.isArray(node)) {
return false;
}
return node.clientKey === 'rolloutToken' && node.branchMappingOperator === 'hash_lt';
export async function promptForRolloutPercentAsync({
promptMessage,
}: {
promptMessage: string;
}): Promise<number> {
const { name: rolloutPercent } = await promptAsync({
type: 'text',
name: 'name',
format: value => {
return parseInt(value, 10);
},
message: promptMessage,
initial: 0,
validate: (rolloutPercent: string): true | string => {
const floatValue = parseFloat(rolloutPercent);
return Number.isInteger(floatValue) && floatValue >= 0 && floatValue <= 100
? true
: 'The rollout percentage must be an integer between 0 and 100 inclusive.';
},
});
return rolloutPercent;
}
@@ -0,0 +1,52 @@
import { Workflow } from '@expo/eas-build-job';
import {
DEFAULT_BARE_RUNTIME_VERSION,
DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49,
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48,
getDefaultRuntimeVersion,
} from '../configure';
describe(getDefaultRuntimeVersion, () => {
it('gets the right rtv version/policy', () => {
expect(getDefaultRuntimeVersion(Workflow.MANAGED, '48.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.MANAGED, '49.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49
);
expect(getDefaultRuntimeVersion(Workflow.MANAGED, '50.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49
);
expect(getDefaultRuntimeVersion(Workflow.MANAGED, 'sdf')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.MANAGED, undefined)).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.UNKNOWN, '48.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.UNKNOWN, '49.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49
);
expect(getDefaultRuntimeVersion(Workflow.UNKNOWN, '50.0.0')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49
);
expect(getDefaultRuntimeVersion(Workflow.UNKNOWN, 'sdf')).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.UNKNOWN, undefined)).toBe(
DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48
);
expect(getDefaultRuntimeVersion(Workflow.GENERIC, '48.0.0')).toBe(DEFAULT_BARE_RUNTIME_VERSION);
expect(getDefaultRuntimeVersion(Workflow.GENERIC, '49.0.0')).toBe(DEFAULT_BARE_RUNTIME_VERSION);
expect(getDefaultRuntimeVersion(Workflow.GENERIC, '50.0.0')).toBe(DEFAULT_BARE_RUNTIME_VERSION);
expect(getDefaultRuntimeVersion(Workflow.GENERIC, 'sdf')).toBe(DEFAULT_BARE_RUNTIME_VERSION);
expect(getDefaultRuntimeVersion(Workflow.GENERIC, undefined)).toBe(
DEFAULT_BARE_RUNTIME_VERSION
);
});
});
@@ -115,6 +115,7 @@ function mockUpdateBranches(branchNames: string[]): UpdateBranch[] {
createdAt: '2022-12-07T02:24:29.786Z',
updatedAt: '2022-12-07T02:24:29.786Z',
updates: [],
runtimes: { edges: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } },
updateGroups: [
[
{
@@ -148,6 +149,7 @@ function mockUpdateBranches(branchNames: string[]): UpdateBranch[] {
updatedAt: '2022-12-07T02:24:29.786Z',
updateGroups: [],
updates: [],
runtimes: { edges: [], pageInfo: { hasNextPage: false, hasPreviousPage: false } },
__typename: 'UpdateBranch' as const,
},
codeSigningInfo: null,
+19 -7
View File
@@ -3,6 +3,7 @@ import { Platform, Workflow } from '@expo/eas-build-job';
import { EasJsonAccessor } from '@expo/eas-json';
import chalk from 'chalk';
import fs from 'fs-extra';
import semver from 'semver';
import { getEASUpdateURL } from '../api';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
@@ -20,13 +21,22 @@ import { confirmAsync } from '../prompts';
import { syncUpdatesConfigurationAsync as syncAndroidUpdatesConfigurationAsync } from './android/UpdatesModule';
import { syncUpdatesConfigurationAsync as syncIosUpdatesConfigurationAsync } from './ios/UpdatesModule';
export const DEFAULT_MANAGED_RUNTIME_VERSION = { policy: 'sdkVersion' } as const;
export const DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49 = { policy: 'appVersion' } as const;
export const DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48 = { policy: 'sdkVersion' } as const;
export const DEFAULT_BARE_RUNTIME_VERSION = '1.0.0' as const;
function getDefaultRuntimeVersion(workflow: Workflow): NonNullable<ExpoConfig['runtimeVersion']> {
return workflow === Workflow.GENERIC
? DEFAULT_BARE_RUNTIME_VERSION
: DEFAULT_MANAGED_RUNTIME_VERSION;
export function getDefaultRuntimeVersion(
workflow: Workflow,
sdkVersion: string | undefined
): NonNullable<ExpoConfig['runtimeVersion']> {
if (workflow === Workflow.GENERIC) {
return DEFAULT_BARE_RUNTIME_VERSION;
}
// Expo Go supports loading appVersion SDK 49 and above
const hasSupportedSdk = sdkVersion && semver.satisfies(sdkVersion, '>= 49.0.0');
return hasSupportedSdk
? DEFAULT_MANAGED_RUNTIME_VERSION_GTE_SDK_49
: DEFAULT_MANAGED_RUNTIME_VERSION_LTE_SDK_48;
}
function isRuntimeEqual(
@@ -108,8 +118,10 @@ async function ensureEASUpdatesIsConfiguredInExpoConfigAsync({
(['all', 'android'].includes(platform) && !androidRuntimeVersion) ||
(['all', 'ios'].includes(platform) && !iosRuntimeVersion)
) {
androidRuntimeVersion = androidRuntimeVersion ?? getDefaultRuntimeVersion(workflows.android);
iosRuntimeVersion = iosRuntimeVersion ?? getDefaultRuntimeVersion(workflows.ios);
androidRuntimeVersion =
androidRuntimeVersion ?? getDefaultRuntimeVersion(workflows.android, exp.sdkVersion);
iosRuntimeVersion =
iosRuntimeVersion ?? getDefaultRuntimeVersion(workflows.ios, exp.sdkVersion);
if (platform === 'all' && isRuntimeEqual(androidRuntimeVersion, iosRuntimeVersion)) {
modifyConfig.runtimeVersion = androidRuntimeVersion;
+201
View File
@@ -0,0 +1,201 @@
import { ExpoConfig } from '@expo/config';
import assert from 'assert';
import nullthrows from 'nullthrows';
import { getUpdateGroupUrl } from '../build/utils/url';
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
import fetch from '../fetch';
import { UpdateFragment, UpdateInfoGroup } from '../graphql/generated';
import { PublishMutation } from '../graphql/mutations/PublishMutation';
import Log, { link } from '../log';
import { ora } from '../ora';
import { getOwnerAccountForProjectIdAsync } from '../project/projectUtils';
import {
CodeSigningInfo,
checkDirectiveBodyAgainstUpdateInfoGroup,
checkManifestBodyAgainstUpdateInfoGroup,
getDirectiveBodyAsync,
getManifestBodyAsync,
signBody,
} from '../utils/code-signing';
import formatFields from '../utils/formatFields';
import { printJsonOnlyOutput } from '../utils/json';
export type UpdateToRepublish = {
groupId: string;
branchId: string;
branchName: string;
} & UpdateFragment;
/**
* @param updatesToPublish The update group to republish
* @param targetBranch The branch to repubish the update group on
*/
export async function republishAsync({
graphqlClient,
app,
updatesToPublish,
targetBranch,
updateMessage,
codeSigningInfo,
json,
}: {
graphqlClient: ExpoGraphqlClient;
app: { exp: ExpoConfig; projectId: string };
updatesToPublish: UpdateToRepublish[];
targetBranch: { branchName: string; branchId: string };
updateMessage: string;
codeSigningInfo?: CodeSigningInfo;
json?: boolean;
}): Promise<void> {
const { branchName: targetBranchName, branchId: targetBranchId } = targetBranch;
// The update group properties are the same for all updates
assert(updatesToPublish.length > 0, 'Updates to republish must be provided');
const arbitraryUpdate = updatesToPublish[0];
const isSameGroup = (update: UpdateToRepublish): boolean =>
update.groupId === arbitraryUpdate.groupId &&
update.branchId === arbitraryUpdate.branchId &&
update.branchName === arbitraryUpdate.branchName &&
update.runtimeVersion === arbitraryUpdate.runtimeVersion;
assert(updatesToPublish.every(isSameGroup), 'All updates must belong to the same update group');
assert(
updatesToPublish.every(u => u.isRollBackToEmbedded) ||
updatesToPublish.every(u => !u.isRollBackToEmbedded),
'All updates must either be roll back to embedded updates or not'
);
const { runtimeVersion } = arbitraryUpdate;
// If codesigning was created for the original update, we need to add it to the republish.
// If one wishes to not sign the republish or sign with a different key, a normal publish should
// be performed.
const shouldRepublishWithCodesigning = updatesToPublish.some(update => update.codeSigningInfo);
if (shouldRepublishWithCodesigning) {
if (!codeSigningInfo) {
throw new Error(
'Must specify --private-key-path argument to sign republished update group for code signing'
);
}
for (const update of updatesToPublish) {
if (
nullthrows(update.codeSigningInfo).alg !== codeSigningInfo.codeSigningMetadata.alg ||
nullthrows(update.codeSigningInfo).keyid !== codeSigningInfo.codeSigningMetadata.keyid
) {
throw new Error(
'Republished updates must use the same code signing key and algorithm as original update'
);
}
}
Log.withTick(`The republished update group will be signed`);
}
const publishIndicator = ora('Republishing...').start();
let updatesRepublished: Awaited<ReturnType<typeof PublishMutation.publishUpdateGroupAsync>>;
try {
const arbitraryUpdate = updatesToPublish[0];
const objectToMergeIn = arbitraryUpdate.isRollBackToEmbedded
? {
rollBackToEmbeddedInfoGroup: Object.fromEntries(
updatesToPublish.map(update => [update.platform, true])
),
}
: {
updateInfoGroup: Object.fromEntries(
updatesToPublish.map(update => [update.platform, JSON.parse(update.manifestFragment)])
),
};
updatesRepublished = await PublishMutation.publishUpdateGroupAsync(graphqlClient, [
{
branchId: targetBranchId,
runtimeVersion,
message: updateMessage,
...objectToMergeIn,
gitCommitHash: updatesToPublish[0].gitCommitHash,
awaitingCodeSigningInfo: !!codeSigningInfo,
},
]);
if (codeSigningInfo) {
Log.log('🔒 Signing republished update group');
await Promise.all(
updatesRepublished.map(async newUpdate => {
const response = await fetch(newUpdate.manifestPermalink, {
method: 'GET',
headers: { accept: 'multipart/mixed' },
});
let signature;
if (newUpdate.isRollBackToEmbedded) {
const directiveBody = nullthrows(await getDirectiveBodyAsync(response));
checkDirectiveBodyAgainstUpdateInfoGroup(directiveBody);
signature = signBody(directiveBody, codeSigningInfo);
} else {
const manifestBody = nullthrows(await getManifestBodyAsync(response));
checkManifestBodyAgainstUpdateInfoGroup(
manifestBody,
nullthrows(
nullthrows(objectToMergeIn.updateInfoGroup)[
newUpdate.platform as keyof UpdateInfoGroup
]
)
);
signature = signBody(manifestBody, codeSigningInfo);
}
await PublishMutation.setCodeSigningInfoAsync(graphqlClient, newUpdate.id, {
alg: codeSigningInfo.codeSigningMetadata.alg,
keyid: codeSigningInfo.codeSigningMetadata.keyid,
sig: signature,
});
})
);
}
publishIndicator.succeed('Republished update group');
} catch (error: any) {
publishIndicator.fail('Failed to republish update group');
throw error;
}
if (json) {
return printJsonOnlyOutput(updatesRepublished);
}
const updatesRepublishedByPlatform = Object.fromEntries(
updatesRepublished.map(update => [update.platform, update])
);
const arbitraryRepublishedUpdate = updatesRepublished[0];
const updateGroupUrl = getUpdateGroupUrl(
(await getOwnerAccountForProjectIdAsync(graphqlClient, app.projectId)).name,
app.exp.slug,
arbitraryRepublishedUpdate.group
);
Log.addNewLineIfNone();
Log.log(
formatFields([
{ label: 'Branch', value: targetBranchName },
{ label: 'Runtime version', value: arbitraryRepublishedUpdate.runtimeVersion },
{ label: 'Platform', value: updatesRepublished.map(update => update.platform).join(', ') },
{ label: 'Update group ID', value: arbitraryRepublishedUpdate.group },
...(updatesRepublishedByPlatform.android
? [{ label: 'Android update ID', value: updatesRepublishedByPlatform.android.id }]
: []),
...(updatesRepublishedByPlatform.ios
? [{ label: 'iOS update ID', value: updatesRepublishedByPlatform.ios.id }]
: []),
{ label: 'Message', value: updateMessage },
{ label: 'Website link', value: link(updateGroupUrl, { dim: false }) },
])
);
}
@@ -1,5 +1,8 @@
import { Platform } from '@expo/eas-build-job';
import { BuildProfile, EasJsonAccessor, EasJsonUtils, errors } from '@expo/eas-json';
import fs from 'fs-extra';
import { vol } from 'memfs';
import os from 'os';
import Log from '../../log';
import { selectAsync } from '../../prompts';
@@ -9,6 +12,7 @@ import {
maybePrintBuildProfileDeprecationWarningsAsync,
} from '../profiles';
jest.mock('fs');
jest.mock('../../prompts');
jest.mock('@expo/eas-json', () => {
const actual = jest.requireActual('@expo/eas-json');
@@ -32,6 +36,7 @@ const getBuildProfileDeprecationWarningsAsync = jest.spyOn(
);
const newLineSpy = jest.spyOn(Log, 'newLine');
const warnSpy = jest.spyOn(Log, 'warn');
const projectDir = '/app';
describe(getProfilesAsync, () => {
afterEach(() => {
@@ -51,6 +56,7 @@ describe(getProfilesAsync, () => {
platforms: [Platform.ANDROID, Platform.IOS],
profileName: undefined,
type: 'build',
projectDir,
});
expect(result[0].profileName).toBe('production');
@@ -71,6 +77,7 @@ describe(getProfilesAsync, () => {
platforms: [Platform.ANDROID],
profileName: undefined,
type: 'build',
projectDir,
})
).rejects.toThrowError(errors.MissingProfileError);
});
@@ -86,6 +93,7 @@ describe(getProfilesAsync, () => {
platforms: [Platform.ANDROID, Platform.IOS],
profileName: 'custom-profile',
type: 'build',
projectDir,
});
expect(result[0].profileName).toBe('custom-profile');
@@ -98,6 +106,52 @@ describe(getProfilesAsync, () => {
expect(getBuildProfileAsync).toBeCalledWith(easJsonAccessor, Platform.IOS, 'custom-profile');
});
describe('node version', () => {
const nodeVersion = '14.17.1';
it('is read from profile', async () => {
const easJsonAccessor = EasJsonAccessor.fromProjectPath(projectDir);
getBuildProfileAsync.mockImplementation(async () => {
return { node: nodeVersion } as BuildProfile<Platform.ANDROID>;
});
const result = await getProfilesAsync({
easJsonAccessor,
platforms: [Platform.ANDROID],
profileName: 'custom-profile',
type: 'build',
projectDir,
});
expect(result[0].profile.node).toBe(nodeVersion);
});
describe('with .nvmrc', () => {
beforeEach(async () => {
vol.reset();
await fs.mkdirp(os.tmpdir());
vol.fromJSON({ '.nvmrc': nodeVersion }, projectDir);
});
it('is read from .nvmrc', async () => {
const easJsonAccessor = EasJsonAccessor.fromProjectPath(projectDir);
getBuildProfileAsync.mockImplementation(async () => {
return {} as BuildProfile<Platform.ANDROID>;
});
const result = await getProfilesAsync({
easJsonAccessor,
platforms: [Platform.ANDROID],
profileName: 'custom-profile',
type: 'build',
projectDir,
});
expect(result[0].profile.node).toBe(nodeVersion);
});
});
});
it('throws validation error if eas.json is invalid', async () => {
getBuildProfileAsync.mockImplementation(() => {
throw new errors.InvalidEasJsonError('eas.json is not valid');
@@ -109,6 +163,7 @@ describe(getProfilesAsync, () => {
platforms: [Platform.ANDROID, Platform.IOS],
profileName: undefined,
type: 'build',
projectDir,
})
).rejects.toThrowError(/eas.json is not valid/);
});
@@ -0,0 +1,782 @@
import { promptAsync } from '../../prompts';
import {
Connection,
FilterPagination,
NEXT_PAGE_OPTION,
PREV_PAGE_OPTION,
QueryParams,
selectPaginatedAsync,
} from '../relay';
jest.mock('../../prompts');
describe(FilterPagination, () => {
describe(FilterPagination.getPageAsync, () => {
let queryParams: QueryParams;
let queryAsync: (queryParams: QueryParams) => Promise<Connection<any>>;
let filterPredicate: () => boolean;
let beforeEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[]
) => void;
let afterEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[],
willFetchAgain: boolean
) => void;
beforeEach(() => {
queryParams = {};
queryAsync = jest.fn();
filterPredicate = jest.fn();
beforeEachQuery = jest.fn();
afterEachQuery = jest.fn();
});
afterEach(() => {
jest.resetAllMocks();
jest.restoreAllMocks();
});
test('should call getFirstItemsAsync when isFirstAfter is true', async () => {
const originalFirstAfter = FilterPagination.isFirstAfter;
const originalGetFirstItemsAsync = FilterPagination.getFirstItemsAsync;
FilterPagination.isFirstAfter = jest.fn().mockReturnValue(true) as unknown as (
connectionArgs: QueryParams
) => connectionArgs is {
first: number;
after?: string;
};
FilterPagination.getFirstItemsAsync = jest.fn().mockResolvedValue({});
await FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery,
afterEachQuery,
});
expect(FilterPagination.isFirstAfter).toHaveBeenCalledWith(queryParams);
expect(FilterPagination.getFirstItemsAsync).toHaveBeenCalledWith(
queryParams,
expect.any(Object)
);
FilterPagination.isFirstAfter = originalFirstAfter;
FilterPagination.getFirstItemsAsync = originalGetFirstItemsAsync;
});
test('should call getLastItemsAsync when isLastBefore is true', async () => {
const originalIsLastBefore = FilterPagination.isLastBefore;
const originalGetLastItemsAsync = FilterPagination.getLastItemsAsync;
FilterPagination.isLastBefore = jest.fn().mockReturnValue(true) as unknown as (
connectionArgs: QueryParams
) => connectionArgs is {
last: number;
before?: string;
};
FilterPagination.getLastItemsAsync = jest.fn().mockResolvedValue({});
await FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery,
afterEachQuery,
});
expect(FilterPagination.isLastBefore).toHaveBeenCalledWith(queryParams);
expect(FilterPagination.getLastItemsAsync).toHaveBeenCalledWith(
queryParams,
expect.any(Object)
);
FilterPagination.isLastBefore = originalIsLastBefore;
FilterPagination.getLastItemsAsync = originalGetLastItemsAsync;
});
test('should throw an error for invalid query params', async () => {
const originalIsFirstAfter = FilterPagination.isFirstAfter;
const originalIsLastBefore = FilterPagination.isLastBefore;
FilterPagination.isFirstAfter = jest.fn().mockReturnValue(false) as unknown as (
connectionArgs: QueryParams
) => connectionArgs is {
first: number;
after?: string;
};
FilterPagination.isLastBefore = jest.fn().mockReturnValue(false) as unknown as (
connectionArgs: QueryParams
) => connectionArgs is {
last: number;
before?: string;
};
await expect(
FilterPagination.getPageAsync({
queryParams,
queryAsync,
filterPredicate,
beforeEachQuery,
afterEachQuery,
})
).rejects.toThrowError('Invalid query params');
FilterPagination.isFirstAfter = originalIsFirstAfter;
FilterPagination.isLastBefore = originalIsLastBefore;
});
});
describe(FilterPagination.isFirstAfter, () => {
test('should return true for object with first property', () => {
const connectionArgs = { first: 10 };
expect(FilterPagination.isFirstAfter(connectionArgs)).toBe(true);
});
test('should return false for object without first property', () => {
const connectionArgs = { last: 10 };
expect(FilterPagination.isFirstAfter(connectionArgs)).toBe(false);
});
});
describe(FilterPagination.isLastBefore, () => {
test('should return true for object with last property', () => {
const connectionArgs = { last: 10 };
expect(FilterPagination.isLastBefore(connectionArgs)).toBe(true);
});
test('should return false for object without last property', () => {
const connectionArgs = { first: 10 };
expect(FilterPagination.isLastBefore(connectionArgs)).toBe(false);
});
});
describe(FilterPagination.getFirstItemsAsync, () => {
let queryArgs: {
first: number;
after?: string | undefined;
};
let internalBatchSize: number;
let maxNodesFetched: number;
let filterPredicate: () => boolean;
let queryAsync: (queryParams: QueryParams) => Promise<Connection<any>>;
let beforeEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[]
) => void;
let afterEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[],
willFetchAgain: boolean
) => void;
beforeEach(() => {
queryArgs = { first: 10, after: 'cursor' };
internalBatchSize = 100;
maxNodesFetched = 10000;
filterPredicate = jest.fn();
queryAsync = jest.fn();
beforeEachQuery = jest.fn();
afterEachQuery = jest.fn();
});
afterEach(() => {
jest.resetAllMocks();
});
test('should call queryAsync with internalBatchSize and after', async () => {
const pageInfo = { hasNextPage: false };
const result = { edges: [], pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(queryAsync).toHaveBeenCalledWith({ first: internalBatchSize, after: queryArgs.after });
});
test('should call filterPredicate for each batch edge', async () => {
const pageInfo = { hasNextPage: false };
const edges = [{ node: 'node1' }, { node: 'node2' }, { node: 'node3' }];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(filterPredicate).toHaveBeenCalledTimes(edges.length);
expect(filterPredicate).toHaveBeenCalledWith(edges[0].node);
expect(filterPredicate).toHaveBeenCalledWith(edges[1].node);
expect(filterPredicate).toHaveBeenCalledWith(edges[2].node);
});
test('should append batch edges to the dataset', async () => {
const pageInfo = { hasNextPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
const connection = await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(connection.edges).toEqual(edges);
});
test('should stop appending batch edges when dataset reaches limit', async () => {
const pageInfo = { hasNextPage: true };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
{ node: 'node3', cursor: 'cursor3' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
const limit = 1;
const connection = await FilterPagination.getFirstItemsAsync(
{ first: limit },
{
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
}
);
expect(connection.edges.length).toBe(limit);
expect(connection.edges).toEqual([edges[0]]);
});
test('should call beforeEachQuery before each query', async () => {
const pageInfo = { hasNextPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(beforeEachQuery).toHaveBeenCalled();
});
test('should call afterEachQuery after each query', async () => {
const pageInfo = { hasNextPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(afterEachQuery).toHaveBeenCalled();
});
test('should pass the correct arguments to beforeEachQuery', async () => {
const pageInfo = { hasNextPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(beforeEachQuery).toHaveBeenCalledWith(queryArgs, 0, expect.any(Array));
});
test('should pass the correct arguments to afterEachQuery', async () => {
const pageInfo = { hasNextPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(afterEachQuery).toHaveBeenCalledWith(
queryArgs,
edges.length,
expect.any(Array),
pageInfo.hasNextPage
);
});
test('should throw an error when maxNodesFetched is exceeded', async () => {
const pageInfo = { hasNextPage: true };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
maxNodesFetched = edges.length;
await expect(
FilterPagination.getFirstItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
})
).rejects.toThrowError(`Max nodes of ${maxNodesFetched} fetched`);
});
});
describe(FilterPagination.getLastItemsAsync, () => {
let queryArgs: {
last: number;
before?: string | undefined;
};
let internalBatchSize: number;
let maxNodesFetched: number;
let filterPredicate: () => boolean;
let queryAsync: (queryParams: QueryParams) => Promise<Connection<any>>;
let beforeEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[]
) => void;
let afterEachQuery: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: any[],
willFetchAgain: boolean
) => void;
beforeEach(() => {
queryArgs = { last: 10, before: 'cursor' };
internalBatchSize = 100;
maxNodesFetched = 10000;
filterPredicate = jest.fn();
queryAsync = jest.fn();
beforeEachQuery = jest.fn();
afterEachQuery = jest.fn();
});
afterEach(() => {
jest.resetAllMocks();
});
test('should call queryAsync with internalBatchSize and after', async () => {
const pageInfo = { hasPreviousPage: false };
const result = { edges: [], pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(queryAsync).toHaveBeenCalledWith({
last: internalBatchSize,
before: queryArgs.before,
});
});
test('should call filterPredicate for each batch edge', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [{ node: 'node1' }, { node: 'node2' }, { node: 'node3' }];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(filterPredicate).toHaveBeenCalledTimes(edges.length);
expect(filterPredicate).toHaveBeenCalledWith(edges[0].node);
expect(filterPredicate).toHaveBeenCalledWith(edges[1].node);
expect(filterPredicate).toHaveBeenCalledWith(edges[2].node);
});
test('should append batch edges to the dataset', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
const connection = await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(connection.edges).toEqual(edges);
});
test('should stop appending batch edges when dataset reaches limit', async () => {
const pageInfo = { hasPreviousPage: true };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
{ node: 'node3', cursor: 'cursor3' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
(filterPredicate as jest.Mock).mockResolvedValue(true);
const limit = 1;
const connection = await FilterPagination.getLastItemsAsync(
{ last: limit },
{
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
}
);
expect(connection.edges.length).toBe(limit);
expect(connection.edges).toEqual([edges[2]]);
});
test('should call beforeEachQuery before each query', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(beforeEachQuery).toHaveBeenCalled();
});
test('should call afterEachQuery after each query', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(afterEachQuery).toHaveBeenCalled();
});
test('should pass the correct arguments to beforeEachQuery', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(beforeEachQuery).toHaveBeenCalledWith(queryArgs, 0, expect.any(Array));
});
test('should pass the correct arguments to afterEachQuery', async () => {
const pageInfo = { hasPreviousPage: false };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
await FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
});
expect(afterEachQuery).toHaveBeenCalledWith(
queryArgs,
edges.length,
expect.any(Array),
pageInfo.hasPreviousPage
);
});
test('should throw an error when maxNodesFetched is exceeded', async () => {
const pageInfo = { hasPreviousPage: true };
const edges = [
{ node: 'node1', cursor: 'cursor1' },
{ node: 'node2', cursor: 'cursor2' },
];
const result = { edges, pageInfo };
(queryAsync as jest.Mock).mockResolvedValue(result);
maxNodesFetched = edges.length;
await expect(
FilterPagination.getLastItemsAsync(queryArgs, {
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
})
).rejects.toThrowError(`Max nodes of ${maxNodesFetched} fetched`);
});
});
});
describe(selectPaginatedAsync, () => {
const queryAsync = jest.fn();
const getTitleAsync = jest.fn();
const printedType = 'Node';
const pageSize = 10;
afterEach(() => {
jest.clearAllMocks();
});
test('returns null when there are no items', async () => {
queryAsync.mockResolvedValueOnce({
edges: [],
});
const result = await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
expect(result).toBeNull();
expect(queryAsync).toHaveBeenCalledWith({ first: pageSize });
});
test('still prompts if there is only one item avaiable', async () => {
const node = { id: '1', name: 'Node 1' };
queryAsync.mockResolvedValueOnce({
edges: [{ node }],
pageInfo: { hasNextPage: false },
});
jest.mocked(promptAsync).mockImplementation(async () => ({
item: node,
}));
const result = await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
expect(result).toEqual(node);
expect(queryAsync).toHaveBeenCalledWith({
first: pageSize,
});
expect(promptAsync).toBeCalledTimes(1);
});
test('prompts for selection when there are multiple items', async () => {
const node1 = { id: '1', name: 'Node 1' };
const node2 = { id: '2', name: 'Node 2' };
queryAsync.mockResolvedValue({
edges: [{ node: node1 }, { node: node2 }],
pageInfo: { hasNextPage: false },
});
getTitleAsync.mockResolvedValueOnce('Node 1');
getTitleAsync.mockResolvedValueOnce('Node 2');
jest.mocked(promptAsync).mockImplementation(async () => ({
item: node1,
}));
const result = await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
expect(result).toEqual(node1);
expect(queryAsync).toHaveBeenCalledWith({ first: pageSize });
expect(getTitleAsync).toHaveBeenCalledWith(node1);
expect(getTitleAsync).toHaveBeenCalledWith(node2);
});
test('selects the previous page', async () => {
const node1 = { id: '1', name: 'Node 1' };
const node2 = { id: '2', name: 'Node 2' };
const node3 = { id: '3', name: 'Node 3' };
queryAsync.mockResolvedValueOnce({
edges: [{ node: node1 }, { node: node2 }],
pageInfo: {
endCursor: 'endCursor',
hasNextPage: true,
},
});
queryAsync.mockResolvedValueOnce({
edges: [{ node: node3 }],
pageInfo: {
startCursor: 'startCursor',
hasPreviousPage: true,
},
});
getTitleAsync.mockResolvedValueOnce('Node 1');
getTitleAsync.mockResolvedValueOnce('Node 2');
getTitleAsync.mockResolvedValueOnce('Node 3');
jest.mocked(promptAsync).mockImplementationOnce(async () => ({
item: NEXT_PAGE_OPTION.value,
}));
jest.mocked(promptAsync).mockImplementationOnce(async () => ({
item: PREV_PAGE_OPTION.value,
}));
jest.mocked(promptAsync).mockImplementationOnce(async () => ({
item: node1,
}));
const result = await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
expect(result).toEqual(node1);
expect(queryAsync).toHaveBeenCalledWith({ first: pageSize });
expect(queryAsync).toHaveBeenCalledWith({
last: pageSize,
before: 'startCursor',
});
expect(getTitleAsync).toHaveBeenCalledWith(node1);
expect(getTitleAsync).toHaveBeenCalledWith(node2);
expect(getTitleAsync).toHaveBeenCalledWith(node3);
});
test('selects the next page', async () => {
const node1 = { id: '1', name: 'Node 1' };
const node2 = { id: '2', name: 'Node 2' };
const node3 = { id: '3', name: 'Node 3' };
queryAsync.mockResolvedValueOnce({
edges: [{ node: node1 }, { node: node2 }],
pageInfo: {
endCursor: 'endCursor',
hasNextPage: true,
},
});
queryAsync.mockResolvedValueOnce({
edges: [{ node: node3 }],
pageInfo: {
startCursor: 'startCursor',
hasPreviousPage: true,
},
});
getTitleAsync.mockResolvedValueOnce('Node 1');
getTitleAsync.mockResolvedValueOnce('Node 2');
getTitleAsync.mockResolvedValueOnce('Node 3');
jest.mocked(promptAsync).mockImplementationOnce(async () => ({
item: NEXT_PAGE_OPTION.value,
}));
jest.mocked(promptAsync).mockImplementationOnce(async () => ({
item: node3,
}));
const result = await selectPaginatedAsync({
queryAsync,
getTitleAsync,
printedType,
pageSize,
});
expect(result).toEqual(node3);
expect(queryAsync).toHaveBeenCalledWith({ first: pageSize });
expect(queryAsync).toHaveBeenCalledWith({
first: pageSize,
after: 'endCursor',
});
expect(getTitleAsync).toHaveBeenCalledWith(node1);
expect(getTitleAsync).toHaveBeenCalledWith(node2);
expect(getTitleAsync).toHaveBeenCalledWith(node3);
});
});
+47 -2
View File
@@ -6,6 +6,9 @@ import {
ProfileType,
SubmitProfile,
} from '@expo/eas-json';
import fs from 'fs-extra';
import path from 'path';
import semver from 'semver';
import Log, { learnMore } from '../log';
@@ -24,19 +27,23 @@ export async function getProfilesAsync<T extends ProfileType>({
platforms,
profileName,
type,
projectDir,
}: {
easJsonAccessor: EasJsonAccessor;
platforms: Platform[];
profileName?: string;
projectDir: string;
type: T;
}): Promise<ProfileData<T>[]> {
const results = platforms.map(async function (platform) {
const profile = await readProfileAsync({
const profile = await readProfileWithOverridesAsync({
easJsonAccessor,
platform,
type,
profileName,
projectDir,
});
return {
profile,
profileName: profileName ?? 'production',
@@ -47,16 +54,53 @@ export async function getProfilesAsync<T extends ProfileType>({
return await Promise.all(results);
}
async function readProfileAsync<T extends ProfileType>({
async function maybeSetNodeVersionFromFileAsync(
projectDir: string,
profile: BuildProfile<Platform>
): Promise<void> {
if (profile?.node) {
return;
}
const nodeVersion = await getNodeVersionFromFileAsync(projectDir);
if (nodeVersion) {
Log.log(
`The EAS build profile does not specify a Node.js version. Using the version specified in .nvmrc: ${nodeVersion} `
);
profile.node = nodeVersion;
}
}
async function getNodeVersionFromFileAsync(projectDir: string): Promise<string | undefined> {
const nvmrcPath = path.join(projectDir, '.nvmrc');
if (!(await fs.pathExists(nvmrcPath))) {
return;
}
let nodeVersion: string;
try {
nodeVersion = (await fs.readFile(nvmrcPath, 'utf8')).toString().trim();
} catch {
return undefined;
}
if (!semver.valid(semver.coerce(nodeVersion))) {
throw new Error(`Invalid node version in .nvmrc: ${nodeVersion}`);
}
return nodeVersion;
}
async function readProfileWithOverridesAsync<T extends ProfileType>({
easJsonAccessor,
platform,
type,
profileName,
projectDir,
}: {
easJsonAccessor: EasJsonAccessor;
platform: Platform;
type: T;
profileName?: string;
projectDir: string;
}): Promise<EasProfile<T>> {
if (type === 'build') {
const buildProfile = await EasJsonUtils.getBuildProfileAsync(
@@ -66,6 +110,7 @@ async function readProfileAsync<T extends ProfileType>({
);
await maybePrintBuildProfileDeprecationWarningsAsync(easJsonAccessor, platform, profileName);
await maybeSetNodeVersionFromFileAsync(projectDir, buildProfile);
return buildProfile as EasProfile<T>;
} else {
+358
View File
@@ -0,0 +1,358 @@
import assert from 'assert';
import { PageInfo } from '../graphql/generated';
import { promptAsync } from '../prompts';
export type Connection<T> = {
edges: Edge<T>[];
pageInfo: PageInfo;
};
export type Edge<T> = {
cursor: string;
node: T;
};
export type QueryParams = {
first?: number;
after?: string;
last?: number;
before?: string;
};
/**
*
* Pagination that performs client side filtering on the nodes returned from a relay compliant datasource.
*
* @param queryParams The query params for the pagination.
* @param queryAsync A promise based function for querying.
* @param filterPredicate A predicate function to filter the node.
* @param beforeEachQuery Optional. A callback function to be called before each query
* @param afterEachQuery Optional. A callback function to be called after each query.
* @param internalBatchSize Optional. The batch size of queryAsync. Defaults to 100.
* @param maxNodesFetched Optional. The maximum number of nodes to fetch. Defaults to 10_000.
* @param beforeEachQuery Optional. A callback function to be called before each query
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @param afterEachQuery Optional. A callback function to be called after each query.
* @args externalQueryParams The query params for the pagination.
* @args totalNodesFetched The total number of nodes fetched so far.
* @args dataset The dataset so far.
* @args willFetchAgain If the query will fetch again to get a complete page.
*
* @throws {Error} - If an error occurs during execution of the query or pagination.
*/
export class FilterPagination {
static async getPageAsync<T>({
queryParams,
queryAsync,
filterPredicate,
internalBatchSize = 100,
maxNodesFetched = 10_000,
beforeEachQuery,
afterEachQuery,
}: {
queryParams: QueryParams;
queryAsync: (queryParams: QueryParams) => Promise<Connection<T>>;
filterPredicate: (node: T) => boolean;
internalBatchSize?: number;
maxNodesFetched?: number;
beforeEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[]
) => void;
afterEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[],
willFetchAgain: boolean
) => void;
}): Promise<Connection<T>> {
if (this.isFirstAfter(queryParams)) {
return await this.getFirstItemsAsync(queryParams, {
queryAsync,
filterPredicate,
internalBatchSize,
maxNodesFetched,
beforeEachQuery,
afterEachQuery,
});
} else if (this.isLastBefore(queryParams)) {
return await this.getLastItemsAsync(queryParams, {
queryAsync,
filterPredicate,
internalBatchSize,
maxNodesFetched,
beforeEachQuery,
afterEachQuery,
});
}
throw new Error('Invalid query params');
}
static isFirstAfter(connectionArgs: QueryParams): connectionArgs is {
first: number;
after?: string;
} {
return 'first' in connectionArgs;
}
static isLastBefore(connectionArgs: {
first?: number;
after?: string;
last?: number;
before?: string;
}): connectionArgs is {
last: number;
before?: string;
} {
return 'last' in connectionArgs;
}
static async getFirstItemsAsync<T>(
{ first, after }: { first: number; after?: string },
{
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
}: {
internalBatchSize?: number;
maxNodesFetched: number;
filterPredicate: (node: T) => boolean;
queryAsync: (queryParams: QueryParams) => Promise<Connection<T>>;
beforeEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[]
) => void;
afterEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[],
willFetchAgain: boolean
) => void;
}
): Promise<Connection<T>> {
const limit = first + 1;
const dataset = [] as Edge<T>[];
let hasMore = true;
let afterInternal: string | undefined = after;
let totalNodesFetched = 0;
while (hasMore && dataset.length < limit) {
if (beforeEachQuery) {
beforeEachQuery({ first, after }, totalNodesFetched, dataset);
}
const result = await queryAsync({ first: internalBatchSize, after: afterInternal });
const { edges: batchEdges, pageInfo } = result;
const batch = batchEdges.filter(edge => filterPredicate(edge.node));
const nodesRemaining = limit - dataset.length;
dataset.push(...batch.slice(0, nodesRemaining));
hasMore = pageInfo.hasNextPage;
afterInternal = pageInfo.endCursor ?? undefined;
totalNodesFetched += batchEdges.length;
if (afterEachQuery) {
afterEachQuery(
{ first, after },
totalNodesFetched,
dataset,
hasMore && dataset.length < limit
);
}
if (totalNodesFetched >= maxNodesFetched) {
throw new Error(`Max nodes of ${maxNodesFetched} fetched`);
}
}
const edges = dataset.slice(0, first);
return {
edges,
pageInfo: {
hasNextPage: dataset.length > first,
hasPreviousPage: false, // cannot be computed efficiently
startCursor: edges[0]?.cursor ?? null,
endCursor: edges[edges.length - 1]?.cursor ?? null,
},
};
}
static async getLastItemsAsync<T>(
{ last, before }: { last: number; before?: string },
{
internalBatchSize,
maxNodesFetched,
filterPredicate,
queryAsync,
beforeEachQuery,
afterEachQuery,
}: {
internalBatchSize?: number;
maxNodesFetched: number;
filterPredicate: (node: T) => boolean;
queryAsync: (queryParams: QueryParams) => Promise<Connection<T>>;
beforeEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[]
) => void;
afterEachQuery?: (
externalQueryParams: QueryParams,
totalNodesFetched: number,
dataset: Edge<T>[],
willFetchAgain: boolean
) => void;
}
): Promise<Connection<T>> {
const limit = last + 1;
const dataset = [] as Edge<T>[];
let hasMore = true;
let beforeInternal: string | undefined = before;
let totalNodesFetched = 0;
while (hasMore && dataset.length < limit) {
if (beforeEachQuery) {
beforeEachQuery({ last, before }, totalNodesFetched, dataset);
}
const result = await queryAsync({ last: internalBatchSize, before: beforeInternal });
const { edges: batchEdges, pageInfo } = result;
const batch = batchEdges.filter(edge => filterPredicate(edge.node));
const nodesRemaining = limit - dataset.length;
// relay orders pages from first to last, so we reverse the batch to to choose the last n
const nodesChosen = batch.reverse().slice(0, nodesRemaining);
dataset.push(...nodesChosen);
hasMore = pageInfo.hasPreviousPage;
beforeInternal = pageInfo.startCursor ?? undefined;
totalNodesFetched += batchEdges.length;
if (afterEachQuery) {
afterEachQuery(
{ last, before },
totalNodesFetched,
dataset,
hasMore && dataset.length < limit
);
}
if (totalNodesFetched >= maxNodesFetched) {
throw new Error(`Max nodes of ${maxNodesFetched} fetched`);
}
}
// we reverse our dataset again to restore the original order of first to last to match relay
const edges = dataset.slice(0, last).reverse();
return {
edges,
pageInfo: {
hasNextPage: false, // cannot be computed efficiently,
hasPreviousPage: dataset.length > last,
startCursor: edges[0]?.cursor ?? null,
endCursor: edges[edges.length - 1]?.cursor ?? null,
},
};
}
}
export async function selectPaginatedAsync<T>({
queryAsync,
getTitleAsync,
printedType,
pageSize,
}: {
pageSize: number;
queryAsync: (queryParams: QueryParams) => Promise<Connection<T>>;
getTitleAsync: (node: T) => Promise<string>;
printedType: string;
}): Promise<T | null> {
return await selectPaginatedInternalAsync({
queryAsync,
getTitleAsync,
printedType,
queryParams: { first: pageSize },
});
}
export const PREV_PAGE_OPTION = {
value: Symbol('PREV_PAGE'),
title: '⬆️ Previous page',
};
export const NEXT_PAGE_OPTION = {
value: Symbol('NEXT_PAGE'),
title: '⬇️ Next page',
};
async function selectPaginatedInternalAsync<T>({
queryAsync,
getTitleAsync,
printedType,
queryParams,
}: {
queryParams: QueryParams;
queryAsync: (queryParams: QueryParams) => Promise<Connection<T>>;
getTitleAsync: (node: T) => Promise<string>;
printedType: string;
}): Promise<T | null> {
const limit = queryParams.first ?? queryParams.last;
assert(limit, 'queryParams must have either first or last');
const connection = await queryAsync(queryParams);
const { edges, pageInfo } = connection;
if (edges.length === 0) {
return null;
}
/*
* The Relay spec has a weird definition on hasNextPage and hasPreviousPage:
* 'If the client is paginating with last/before, then the server must return true if prior edges
* exist, otherwise false. If the client is paginating with first/after, then the client may
* return true if edges prior to after exist, if it can do so efficiently, otherwise may return false.'
*
* This means if we are paginating with first/after, we can't rely on pageInfo.hasPreviousPage and vice versa.
*/
const {
endCursor,
hasNextPage: serverResponseHasNextPage,
startCursor,
hasPreviousPage: serverResponseHasPreviousPage,
} = pageInfo;
const hasPreviousPage = serverResponseHasPreviousPage || queryParams.after;
const hasNextPage = serverResponseHasNextPage || queryParams.before;
const nodes = edges.map(edge => edge.node);
const options: { value: symbol | T; title: string }[] = [];
if (hasPreviousPage) {
options.push(PREV_PAGE_OPTION);
}
const nodeTitles = await Promise.all(nodes.map(node => getTitleAsync(node)));
options.push(...nodes.map((node, index) => ({ value: node, title: nodeTitles[index] })));
if (hasNextPage) {
options.push(NEXT_PAGE_OPTION);
}
const { item: selectedItem } = await promptAsync({
type: 'select',
name: 'item',
message: `Select a ${printedType}`,
choices: options.map(option => ({
value: option.value,
title: option.title,
})),
});
if (selectedItem === PREV_PAGE_OPTION.value) {
return await selectPaginatedInternalAsync({
queryParams: {
last: limit,
before: startCursor ?? undefined,
},
queryAsync,
getTitleAsync,
printedType,
});
} else if (selectedItem === NEXT_PAGE_OPTION.value) {
return await selectPaginatedInternalAsync({
queryParams: {
first: limit,
after: endCursor ?? undefined,
},
queryAsync,
getTitleAsync,
printedType,
});
} else {
return selectedItem as T;
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "@expo/eas-json",
"description": "A library for interacting with eas.json",
"version": "3.17.0",
"version": "5.0.0",
"author": "Expo <[email protected]>",
"bugs": "https://github.com/expo/eas-cli/issues",
"dependencies": {
"@babel/code-frame": "7.18.6",
"@expo/eas-build-job": "1.0.13",
"@expo/eas-build-job": "1.0.39",
"chalk": "4.1.2",
"env-string": "1.0.1",
"fs-extra": "10.1.0",
+14 -2
View File
@@ -91,6 +91,12 @@
"type": "object",
"description": "The build profile configuration.",
"properties": {
"withoutCredentials": {
"type": "boolean",
"description": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when working with custom builds.",
"markdownDescription": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when working with custom builds.",
"default": false
},
"extends": {
"type": "string",
"description": "The name of the build profile that the current one should inherit values from. This value can't be specified per platform."
@@ -208,8 +214,8 @@
"properties": {
"withoutCredentials": {
"type": "boolean",
"description": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when you want to build debug binaries and the debug keystore is checked in to the repository.",
"markdownDescription": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when you want to build debug binaries and the debug keystore is checked in to the repository.",
"description": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when you want to build debug binaries and the debug keystore is checked in to the repository or working with custom builds.",
"markdownDescription": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when you want to build debug binaries and the debug keystore is checked in to the repository or working with custom builds.",
"default": false
},
"image": {
@@ -301,6 +307,12 @@
"type": "object",
"description": "The iOS-specific build profile configuration.",
"properties": {
"withoutCredentials": {
"type": "boolean",
"description": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when working with custom builds.",
"markdownDescription": "When set to `true`, EAS CLI won't require you to configure credentials when building the app. This comes in handy when working with custom builds.",
"default": false
},
"simulator": {
"type": "boolean",
"description": "If set to true, creates build for simulator.",
@@ -100,6 +100,105 @@ test('valid eas.json for development client builds', async () => {
});
});
test('valid eas.json with top level withoutCredentials property', async () => {
await fs.writeJson('/project/eas.json', {
build: {
production: {},
debug: {
developmentClient: true,
withoutCredentials: true,
},
},
});
const accessor = EasJsonAccessor.fromProjectPath('/project');
const iosProfile = await EasJsonUtils.getBuildProfileAsync(accessor, Platform.IOS, 'debug');
const androidProfile = await EasJsonUtils.getBuildProfileAsync(
accessor,
Platform.ANDROID,
'debug'
);
expect(androidProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
withoutCredentials: true,
});
expect(iosProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
withoutCredentials: true,
});
});
test('valid eas.json with iOS withoutCredentials property', async () => {
await fs.writeJson('/project/eas.json', {
build: {
production: {},
debug: {
developmentClient: true,
ios: { withoutCredentials: true },
},
},
});
const accessor = EasJsonAccessor.fromProjectPath('/project');
const iosProfile = await EasJsonUtils.getBuildProfileAsync(accessor, Platform.IOS, 'debug');
const androidProfile = await EasJsonUtils.getBuildProfileAsync(
accessor,
Platform.ANDROID,
'debug'
);
expect(androidProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
});
expect(iosProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
withoutCredentials: true,
});
});
test('valid eas.json with top level and platform-sepcific withoutCredentials property', async () => {
await fs.writeJson('/project/eas.json', {
build: {
production: {},
debug: {
developmentClient: true,
withoutCredentials: true,
ios: { withoutCredentials: false },
},
},
});
const accessor = EasJsonAccessor.fromProjectPath('/project');
const iosProfile = await EasJsonUtils.getBuildProfileAsync(accessor, Platform.IOS, 'debug');
const androidProfile = await EasJsonUtils.getBuildProfileAsync(
accessor,
Platform.ANDROID,
'debug'
);
expect(androidProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
withoutCredentials: true,
});
expect(iosProfile).toEqual({
credentialsSource: 'remote',
distribution: 'store',
developmentClient: true,
withoutCredentials: false,
});
});
test(`valid eas.json with autoIncrement flag at build profile root`, async () => {
await fs.writeJson('/project/eas.json', {
build: {
+7 -5
View File
@@ -25,9 +25,11 @@ const CacheSchema = Joi.object({
cacheDefaultPaths: Joi.boolean(),
customPaths: Joi.array().items(Joi.string()),
paths: Joi.array().items(Joi.string()),
}).rename('customPaths', 'paths')
})
.rename('customPaths', 'paths')
.messages({
'object.rename.override': 'Cannot provide both "cache.customPaths" and "cache.paths" - use "cache.paths"'
'object.rename.override':
'Cannot provide both "cache.customPaths" and "cache.paths" - use "cache.paths"',
});
const CommonBuildProfileSchema = Joi.object({
@@ -63,6 +65,9 @@ const CommonBuildProfileSchema = Joi.object({
// custom build configuration
config: Joi.string(),
// credentials
withoutCredentials: Joi.boolean(),
});
const PlatformBuildProfileSchema = CommonBuildProfileSchema.concat(
@@ -84,9 +89,6 @@ const AndroidBuildProfileSchema = PlatformBuildProfileSchema.concat(
// build environment
ndk: Joi.string().empty(null).custom(semverCheck),
// credentials
withoutCredentials: Joi.boolean(),
// build configuration
gradleCommand: Joi.string(),
buildType: Joi.string().valid('apk', 'app-bundle'),
+3 -3
View File
@@ -70,6 +70,9 @@ export interface CommonBuildProfile {
// custom build configuration
config?: string;
// credentials
withoutCredentials?: boolean;
}
interface PlatformBuildProfile extends Omit<CommonBuildProfile, 'autoIncrement'> {
@@ -86,9 +89,6 @@ export interface AndroidBuildProfile extends PlatformBuildProfile {
image?: Android.BuilderEnvironment['image'];
ndk?: string;
// credentials
withoutCredentials?: boolean;
// build configuration
gradleCommand?: string;
buildType?: Android.BuildType.APK | Android.BuildType.APP_BUNDLE;
Generated
+50 -27
View File
@@ -1395,13 +1395,13 @@
slugify "^1.3.4"
sucrase "^3.20.0"
"@expo/[email protected].13":
version "1.0.13"
resolved "https://registry.yarnpkg.com/@expo/eas-build-job/-/eas-build-job-1.0.13.tgz#1cd3981e86e1d4235f20a96f7ac768793b4f7c62"
integrity sha512-Q0i3GposBj/b2OPL0CV00HczawtslorNpoJSBQfB4aNR6i7DBIZZ1jWJtrFP8+zHZqlUi4d21aoblNUrKpgBew==
"@expo/[email protected]9":
version "1.0.39"
resolved "https://registry.yarnpkg.com/@expo/eas-build-job/-/eas-build-job-1.0.39.tgz#d3bc6cd50c499f07255bceeb9460e092a19505f7"
integrity sha512-OqCCxLx9HRMFQDiZvfpOfNmGhsTrV15IUOhmbp9iIa+uO/VyPpBvXqiA4ENCN9Jmf6yXtirIranCeJcm+jAuSA==
dependencies:
joi "^17.7.0"
semver "^7.3.8"
joi "^17.9.2"
semver "^7.5.4"
"@expo/[email protected]":
version "0.3.22"
@@ -1438,10 +1438,10 @@
json5 "^2.2.2"
write-file-atomic "^2.3.0"
"@expo/[email protected].21":
version "1.0.21"
resolved "https://registry.yarnpkg.com/@expo/logger/-/logger-1.0.21.tgz#9271b52b8e27159cbbe3385b9a01fca3317b37c2"
integrity sha512-Vz+LHDGWUfowAwL10nBKqxrMYvO4qdZ8hLKcqUYc5mXBt+jmv7RP+8fcsMIejJEMWmYC2meO5eeCMLKKhEIgMA==
"@expo/[email protected].30":
version "1.0.30"
resolved "https://registry.yarnpkg.com/@expo/logger/-/logger-1.0.30.tgz#f964cc7b73cbb0c05de44c874a9451f5cfd2ec2d"
integrity sha512-8wEUDZNLAv+Wi4jvo0kFErQ7nc4ZFfArq5GDeSCoIrRfdKK8baot7YJoJVsmpQ9/JXnTEAgwGDP3vYaR5wzcyg==
dependencies:
"@types/bunyan" "^1.8.8"
bunyan "^1.8.15"
@@ -1569,26 +1569,28 @@
dependencies:
cross-spawn "^7.0.3"
"@expo/spawn-async@^1.7.0":
"@expo/spawn-async@^1.7.2":
version "1.7.2"
resolved "https://registry.yarnpkg.com/@expo/spawn-async/-/spawn-async-1.7.2.tgz#fcfe66c3e387245e72154b1a7eae8cada6a47f58"
integrity sha512-QdWi16+CHB9JYP7gma19OVVg0BFkvU8zNj9GjWorYI8Iv8FUxjOCcYRuAmX4s/h91e4e7BPsskc8cSrZYho9Ew==
dependencies:
cross-spawn "^7.0.3"
"@expo/[email protected].25":
version "1.0.25"
resolved "https://registry.yarnpkg.com/@expo/steps/-/steps-1.0.25.tgz#04f8c18bb12f2445cdca443b48497d3c2be3e133"
integrity sha512-MBtJ/3+T5qvXxmnOVlfapKlKQsxPUyKoEUaA6lLbpmm8yCcXJEblnmQP/2ZokAG78IWjsYl5E02Ei/AnrIxB9g==
"@expo/[email protected].34":
version "1.0.34"
resolved "https://registry.yarnpkg.com/@expo/steps/-/steps-1.0.34.tgz#ba2f27a9d3e163b2d0fe6ef7775b237f7d18a286"
integrity sha512-jQoxeMWWl2mUwLGyiUD38z/FNao2jbDP8Tjvkr/YAfIOHaro36E3Vmn1YsKTYmtc41TGcFdCzqly95faRNrhvQ==
dependencies:
"@expo/logger" "1.0.21"
"@expo/spawn-async" "^1.7.0"
"@expo/logger" "1.0.30"
"@expo/spawn-async" "^1.7.2"
arg "^5.0.2"
joi "^17.7.0"
fs-extra "^11.1.1"
joi "^17.9.2"
lodash.clonedeep "^4.5.0"
lodash.get "^4.4.2"
this-file "^2.0.3"
uuid "^9.0.0"
yaml "^2.2.1"
yaml "^2.3.1"
"@expo/[email protected]":
version "1.0.0"
@@ -7495,6 +7497,15 @@ fs-extra@^11.1.0:
jsonfile "^6.0.1"
universalify "^2.0.0"
fs-extra@^11.1.1:
version "11.1.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-11.1.1.tgz#da69f7c39f3b002378b0954bb6ae7efdc0876e2d"
integrity sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==
dependencies:
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^2.0.0"
fs-extra@^8.1:
version "8.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
@@ -9363,10 +9374,10 @@ [email protected]:
"@sideway/formula" "^3.0.0"
"@sideway/pinpoint" "^2.0.0"
joi@^17.7.0:
version "17.8.3"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.8.3.tgz#d772fe27a87a5cda21aace5cf11eee8671ca7e6f"
integrity sha512-q5Fn6Tj/jR8PfrLrx4fpGH4v9qM6o+vDUfD4/3vxxyg34OmKcNqYZ1qn2mpLza96S8tL0p0rIw2gOZX+/cTg9w==
joi@^17.9.2:
version "17.9.2"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.9.2.tgz#8b2e4724188369f55451aebd1d0b1d9482470690"
integrity sha512-Itk/r+V4Dx0V3c7RLFdRh12IOjySm2/WGPMubBT92cQvRfYZhPM2W0hZlctjj72iES8jsRCwp7S/cRmWBnJ4nw==
dependencies:
"@hapi/hoek" "^9.0.0"
"@hapi/topo" "^5.0.0"
@@ -9728,6 +9739,11 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"
lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==
lodash.flatten@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
@@ -12101,6 +12117,13 @@ semver@^7.3.7:
dependencies:
lru-cache "^6.0.0"
semver@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
dependencies:
lru-cache "^6.0.0"
[email protected]:
version "0.18.0"
resolved "https://registry.yarnpkg.com/send/-/send-0.18.0.tgz#670167cc654b05f5aa4a767f9113bb371bc706be"
@@ -13829,10 +13852,10 @@ yaml@^1.10.0, yaml@^1.7.2:
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.10.0.tgz#3b593add944876077d4d683fee01081bd9fff31e"
integrity sha512-yr2icI4glYaNG+KWONODapy2/jDdMSDnrONSjblABjD9B4Z5LgiircSt8m8sRZFNi08kG9Sm0uSHtEmP3zaEGg==
yaml@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.2.1.tgz#3014bf0482dcd15147aa8e56109ce8632cd60ce4"
integrity sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw==
yaml@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/yaml/-/yaml-2.3.1.tgz#02fe0975d23cd441242aa7204e09fc28ac2ac33b"
integrity sha512-2eHWfjaoXgTBC2jNM1LRef62VQa0umtvRiDSk6HSzW7RvS5YtkabJrwYLLEKWBc8a5U2PTSCs+dJjUTJdlHsWQ==
[email protected], yargs-parser@^20.2.2:
version "20.2.4"