Compare commits

..
3 Commits
Author SHA1 Message Date
Expo CI b547b4d94a chore: create new release 8.2.0
## [8.2.0](https://github.com/expo/expo-github-action/compare/8.1.0...8.2.0) (2023-12-02)

### New features

* **preview:** add `qr-target` and use proper QR codes for `expo-go` and `dev-build` ([#247](https://github.com/expo/expo-github-action/issues/247)) ([54efbfd](https://github.com/expo/expo-github-action/commit/54efbfdf1d130888a5f13b73fb7adc85edeb8855))

### Documentation changes

* **preview:** clarify the branch and workflow trigger relations ([#246](https://github.com/expo/expo-github-action/issues/246)) ([ccfad6f](https://github.com/expo/expo-github-action/commit/ccfad6f148eaa709959a64b1be216481f4ca54ff))
2023-12-02 15:49:36 +00:00
Cedric van Putten 54efbfdf1d feature(preview): add qr-target and use proper QR codes for expo-go and dev-build (#247)
* fix(preview): use app slug to generate proper EAS Update preview

* ci(test): remove faulty implemented test case for app schemes

* chore: add jest snapshot workaround for prettier v2

See https://jestjs.io/docs/configuration/\#prettierpath-string

* chore(preview): rebuild preview subaction

* fix(preview): allow users to force EAS Update QR codes to Expo Go

* refactor(preview): use `qr-target` with automatically inferred value instead of `expo-go`

* chore: rebuild files

* refactor(preview): use `dev-build` instead of `dev-client` and validate input

* chore: rebuild files

* test(preview): add e2e test for infered `dev-build` qr code
2023-12-02 16:48:22 +01:00
Cedric van Putten ccfad6f148 docs(preview): clarify the branch and workflow trigger relations (#246) 2023-11-27 09:44:36 +01:00
17 changed files with 719 additions and 160 deletions

No files matched your search

+34 -8
View File
@@ -84,6 +84,10 @@ jobs:
- name: 🏗 Setup project
run: bun create expo ./temp --template blank
- name: 🏗 Setup `expo-dev-client`
working-directory: ./temp
run: bun expo install expo-dev-client
- name: 👷 Configure project
working-directory: ./temp
run: |
@@ -165,27 +169,49 @@ jobs:
throw new Error('Message output is empty');
}
- name: 🚀 Create preview (with custom app scheme)
- name: 🚀 Create preview (with "dev-build" QR target)
if: ${{ env.hasAuth == 'true' }}
uses: ./preview
id: custom-app-scheme
id: dev-build-qr
env:
EXPO_TEST_GITHUB_PULL: 206
with:
app-scheme: thisisacustomscheme
working-directory: ./temp
command: eas update --branch test --message "This is a test"
comment: false
- name: 🧪 Comment has custom app scheme
- name: 🧪 Comment has "dev-build" QR
if: ${{ env.hasAuth == 'true' }}
uses: actions/github-script@v7
with:
script: |
const comment = `${{ steps.custom-app-scheme.outputs.comment }}`
if (!comment || !comment.includes('thisisacustomscheme')) {
console.log({ comment });
throw new Error('Message output does not include the app scheme from action input');
const qrUrl = `${{ steps.dev-build-qr.outputs.qr }}`
if (!qrUrl || !qrUrl.includes('appScheme')) {
console.log({ qrUrl });
throw new Error('QR URL is missing "appScheme" to point to a dev build');
}
- name: 🚀 Create preview (with "expo-go" QR target from input)
if: ${{ env.hasAuth == 'true' }}
uses: ./preview
id: expo-go-qr
env:
EXPO_TEST_GITHUB_PULL: 206
with:
working-directory: ./temp
qr-target: expo-go
command: eas update --branch test --message "This is a test"
comment: false
- name: 🧪 Comment has "expo-go" QR code
if: ${{ env.hasAuth == 'true' }}
uses: actions/github-script@v7
with:
script: |
const qrUrl = `${{ steps.expo-go-qr.outputs.qr }}`
if (!qrUrl || qrUrl.includes('appScheme')) {
console.log({ qrUrl });
throw new Error('QR URL points to a dev build, not Expo Go');
}
preview-comment:
+12
View File
@@ -1,3 +1,15 @@
## [8.2.0](https://github.com/expo/expo-github-action/compare/8.1.0...8.2.0) (2023-12-02)
### New features
* **preview:** add `qr-target` and use proper QR codes for `expo-go` and `dev-build` ([#247](https://github.com/expo/expo-github-action/issues/247)) ([54efbfd](https://github.com/expo/expo-github-action/commit/54efbfdf1d130888a5f13b73fb7adc85edeb8855))
### Documentation changes
* **preview:** clarify the branch and workflow trigger relations ([#246](https://github.com/expo/expo-github-action/issues/246)) ([ccfad6f](https://github.com/expo/expo-github-action/commit/ccfad6f148eaa709959a64b1be216481f4ca54ff))
## [8.1.0](https://github.com/expo/expo-github-action/compare/8.0.0...8.1.0) (2023-11-24)
+3 -1
View File
@@ -174,7 +174,9 @@ jobs:
- name: 🚀 Create preview
uses: expo/expo-github-action/preview@v8
with:
command: eas update --auto
# `github.event.pull_request.head.ref` is only available on `pull_request` triggers.
# Use your own, or keep the automatically infered branch name from `--auto`, when using different triggers.
command: eas update --auto --branch ${{ github.event.pull_request.head.ref }}
```
## Things to know
+27 -2
View File
@@ -38691,16 +38691,20 @@ function createBuildComment(builds) {
/***/ }),
/***/ 2489:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectAppType = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const assert_1 = __nccwpck_require__(9491);
const path_1 = __importDefault(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
var AppPlatform;
(function (AppPlatform) {
@@ -38869,6 +38873,27 @@ async function projectInfo(dir) {
return { name, slug, owner };
}
exports.projectInfo = projectInfo;
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
function projectAppType(dir) {
const packageFile = path_1.default.resolve(dir, 'package.json');
let packageJson = {};
try {
packageJson = require(packageFile);
}
catch (error) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
exports.projectAppType = projectAppType;
/**
* Create a QR code for an update on project, with an optional release channel.
*/
+27 -2
View File
@@ -89233,16 +89233,20 @@ exports.handleCacheError = handleCacheError;
/***/ }),
/***/ 2489:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectAppType = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const assert_1 = __nccwpck_require__(9491);
const path_1 = __importDefault(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
var AppPlatform;
(function (AppPlatform) {
@@ -89411,6 +89415,27 @@ async function projectInfo(dir) {
return { name, slug, owner };
}
exports.projectInfo = projectInfo;
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
function projectAppType(dir) {
const packageFile = path_1.default.resolve(dir, 'package.json');
let packageJson = {};
try {
packageJson = require(packageFile);
}
catch (error) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
exports.projectAppType = projectAppType;
/**
* Create a QR code for an update on project, with an optional release channel.
*/
+27 -2
View File
@@ -38635,16 +38635,20 @@ exports.commentAction = commentAction;
/***/ }),
/***/ 2489:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectAppType = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const assert_1 = __nccwpck_require__(9491);
const path_1 = __importDefault(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
var AppPlatform;
(function (AppPlatform) {
@@ -38813,6 +38817,27 @@ async function projectInfo(dir) {
return { name, slug, owner };
}
exports.projectInfo = projectInfo;
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
function projectAppType(dir) {
const packageFile = path_1.default.resolve(dir, 'package.json');
let packageJson = {};
try {
packageJson = require(packageFile);
}
catch (error) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
exports.projectAppType = projectAppType;
/**
* Create a QR code for an update on project, with an optional release channel.
*/
+315 -27
View File
@@ -41838,22 +41838,28 @@ try {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createSummary = exports.getSchemeFromConfig = exports.getVariables = exports.previewAction = exports.previewInput = exports.MESSAGE_ID = void 0;
exports.createSummary = exports.getSchemesInOrderFromConfig = exports.getQrTarget = exports.getVariables = exports.previewAction = exports.previewInput = exports.MESSAGE_ID = void 0;
const core_1 = __nccwpck_require__(2186);
const eas_1 = __nccwpck_require__(3251);
const expo_1 = __nccwpck_require__(2489);
const github_1 = __nccwpck_require__(978);
const project_1 = __nccwpck_require__(7191);
const utils_1 = __nccwpck_require__(1314);
const worker_1 = __nccwpck_require__(8912);
exports.MESSAGE_ID = 'projectId:{projectId}';
function previewInput() {
const qrTarget = (0, core_1.getInput)('qr-target') || undefined;
if (qrTarget && !['expo-go', 'dev-client'].includes(qrTarget)) {
throw new Error(`Invalid QR code target: "${qrTarget}", expected "expo-go" or "dev-build"`);
}
return {
command: (0, core_1.getInput)('command'),
shouldComment: !(0, core_1.getInput)('comment') || (0, core_1.getBooleanInput)('comment'),
commentId: (0, core_1.getInput)('comment-id') || exports.MESSAGE_ID,
workingDirectory: (0, core_1.getInput)('working-directory'),
githubToken: (0, core_1.getInput)('github-token'),
appScheme: (0, core_1.getInput)('app-scheme'),
// Note, `dev-build` is prefered, but `dev-client` is supported to aovid confusion
qrTarget: qrTarget,
};
}
exports.previewInput = previewInput;
@@ -41923,22 +41929,25 @@ function sanitizeCommand(input) {
/**
* Generate useful variables for the message body, and as step outputs.
*/
function getVariables(config, updates, input) {
function getVariables(config, updates, options) {
const projectId = config.extra?.eas?.projectId;
const android = updates.find(update => update.platform === 'android');
const ios = updates.find(update => update.platform === 'ios');
const appScheme = input.appScheme || getSchemeFromConfig(config) || '';
const appSchemes = getSchemesInOrderFromConfig(config) || [];
const appSlug = config.slug;
const qrTarget = getQrTarget(options);
return {
// EAS / Expo specific
projectId,
projectName: config.name,
projectSlug: config.slug,
projectScheme: appScheme,
projectSlug: appSlug,
projectScheme: appSchemes[0] || '', // This is the longest scheme from one or more custom app schemes
projectSchemes: JSON.stringify(appSchemes), // These are all custom app schemes, in order from longest to shortest as JSON
// Shared update properties
// Note, only use these properties when the update groups are identical
groupId: updates[0].group,
runtimeVersion: updates[0].runtimeVersion,
qr: (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: updates[0].group, appScheme }),
qr: (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: updates[0].group, appSlug, qrTarget }),
link: (0, eas_1.getUpdateGroupWebsite)({ projectId, updateGroupId: updates[0].group }),
// These are safe to access regardless of the update groups
branchName: updates[0].branch,
@@ -41952,7 +41961,7 @@ function getVariables(config, updates, input) {
androidManifestPermalink: android?.manifestPermalink || '',
androidMessage: android?.message || '',
androidRuntimeVersion: android?.runtimeVersion || '',
androidQR: android ? (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: android.group, appScheme }) : '',
androidQR: android ? (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: android.group, appSlug, qrTarget }) : '',
androidLink: android ? (0, eas_1.getUpdateGroupWebsite)({ projectId, updateGroupId: android.group }) : '',
// iOS update
iosId: ios?.id || '',
@@ -41961,27 +41970,47 @@ function getVariables(config, updates, input) {
iosManifestPermalink: ios?.manifestPermalink || '',
iosMessage: ios?.message || '',
iosRuntimeVersion: ios?.runtimeVersion || '',
iosQR: ios ? (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: ios.group, appScheme }) : '',
iosQR: ios ? (0, eas_1.getUpdateGroupQr)({ projectId, updateGroupId: ios.group, appSlug, qrTarget }) : '',
iosLink: ios ? (0, eas_1.getUpdateGroupWebsite)({ projectId, updateGroupId: ios.group }) : '',
};
}
exports.getVariables = getVariables;
/**
* Retrieve the app scheme from project config, using the following criteria:
* - If the scheme is a string, return that.
* - If the scheme is an array, return the longest scheme.
*/
function getSchemeFromConfig(config) {
if (typeof config.scheme === 'string') {
return config.scheme;
function getQrTarget(input) {
if (!input.qrTarget) {
const appType = (0, expo_1.projectAppType)(input.workingDirectory);
(0, core_1.debug)(`Using inferred QR code target: "${appType}"`);
return appType;
}
if (Array.isArray(config.scheme) && config.scheme.length > 0) {
const longestToShortest = config.scheme.sort((a, b) => b.length - a.length);
return longestToShortest[0];
switch (input.qrTarget) {
// Note, `dev-build` is prefered, but `dev-client` is supported to aovid confusion
case 'dev-client':
case 'dev-build':
(0, core_1.debug)(`Using QR code target: "dev-build"`);
return 'dev-build';
case 'expo-go':
(0, core_1.debug)(`Using QR code target: "expo-go"`);
return 'expo-go';
default:
throw new Error(`Invalid QR code target: "${input.qrTarget}", expected "expo-go" or "dev-build"`);
}
return null;
}
exports.getSchemeFromConfig = getSchemeFromConfig;
exports.getQrTarget = getQrTarget;
/**
* Retrieve the app schemes, in correct priority order, from project config.
* - If the scheme is a string, return `[scheme]`.
* - If the scheme is an array, return the schemes sorted by length, longest first.
* - If the scheme is empty/incorrect, return an empty array.
*/
function getSchemesInOrderFromConfig(config) {
if (typeof config.scheme === 'string') {
return [config.scheme];
}
if (Array.isArray(config.scheme)) {
return config.scheme.sort((a, b) => b.length - a.length);
}
return [];
}
exports.getSchemesInOrderFromConfig = getSchemesInOrderFromConfig;
/**
* Generate the message body for a single update.
* Note, this is not configurable, but you can use the variables used to construct your own.
@@ -42001,12 +42030,12 @@ function createSummaryHeader(updates, vars) {
.sort((a, b) => a.localeCompare(b))
.map(platform => `**${platform}**`)
.join(', ');
const appScheme = vars.projectScheme ? `- Scheme → **${vars.projectScheme}**` : '';
const appSchemes = vars.projectScheme ? `- Scheme → **${JSON.parse(vars.projectSchemes).join('**, **')}**` : '';
return `🚀 Expo preview is ready!
- Project → **${vars.projectSlug}**
- ${platformName} → ${platformValue}
${appScheme}`.trim();
${appSchemes}`.trim();
}
function createSingleQrSummary(updates, vars) {
return `${createSummaryHeader(updates, vars)}
@@ -42099,10 +42128,12 @@ exports.createUpdate = createUpdate;
/**
* Create a QR code link for an EAS Update.
*/
function getUpdateGroupQr({ projectId, updateGroupId, appScheme, }) {
function getUpdateGroupQr({ projectId, updateGroupId, appSlug, qrTarget, }) {
const url = new url_1.URL('https://qr.expo.dev/eas-update');
if (appScheme) {
url.searchParams.append('appScheme', appScheme);
if (qrTarget === 'dev-build') {
// While the parameter is called `appScheme`, it's actually the app's slug
// This should only be added when using dev clients as target
url.searchParams.append('appScheme', appSlug);
}
url.searchParams.append('projectId', projectId);
url.searchParams.append('groupId', updateGroupId);
@@ -42116,6 +42147,263 @@ function getUpdateGroupWebsite({ projectId, updateGroupId, }) {
exports.getUpdateGroupWebsite = getUpdateGroupWebsite;
/***/ }),
/***/ 2489:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectAppType = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const assert_1 = __nccwpck_require__(9491);
const path_1 = __importDefault(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
var AppPlatform;
(function (AppPlatform) {
AppPlatform["Android"] = "ANDROID";
AppPlatform["Ios"] = "IOS";
})(AppPlatform || (exports.AppPlatform = AppPlatform = {}));
exports.appPlatformDisplayNames = {
[AppPlatform.Android]: 'Android',
[AppPlatform.Ios]: 'iOS',
};
exports.appPlatformEmojis = {
[AppPlatform.Ios]: '🍎',
[AppPlatform.Android]: '🤖',
};
const CommandRegExp = /^#(eas|expo)\s+(.+)?$/im;
function parseCommand(input) {
const matches = CommandRegExp.exec(input);
if (matches != null) {
return {
cli: matches[1],
raw: input.trimStart().substring(1).trim(),
args: matches[2]
?.split(' ')
.map(s => s.trim())
.filter(Boolean) ?? [],
};
}
return null;
}
exports.parseCommand = parseCommand;
/**
* Try to authenticate the user using either Expo or EAS CLI.
* This method tries to invoke 'whoami' to validate if the token is valid.
* If that passes, the token is exported as EXPO_TOKEN for all steps within the job.
*/
async function authenticate(token, cli = 'expo') {
if (!cli) {
(0, core_1.info)(`Skipped token validation: no CLI installed, can't run 'whoami'.`);
}
else {
await (0, exec_1.exec)(await (0, io_1.which)(cli), ['whoami'], {
env: { ...process.env, EXPO_TOKEN: token },
});
}
(0, core_1.exportVariable)('EXPO_TOKEN', token);
}
exports.authenticate = authenticate;
/**
* Try to resolve the project owner, by running 'eas|expo whoami'.
*/
async function projectOwner(cli = 'expo') {
let stdout = '';
try {
({ stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)(cli), ['whoami'], { silent: true }));
}
catch (error) {
throw new Error(`Could not fetch the project owner`, { cause: error });
}
if (!stdout) {
throw new Error(`Could not fetch the project owner, not authenticated`);
}
else if (stdout.endsWith(' (robot)')) {
throw new Error(`Could not fetch the project owner, used robot account`);
}
return stdout.trim();
}
exports.projectOwner = projectOwner;
async function runCommand(cmd) {
let stdout = '';
let stderr = '';
try {
({ stderr, stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)(cmd.cli), cmd.args.concat('--non-interactive'), {
silent: false,
}));
}
catch (error) {
throw new Error(`Could not run command ${cmd.args.join(' ')}`, { cause: error });
}
return [stdout.trim(), stderr.trim()];
}
exports.runCommand = runCommand;
async function easBuild(cmd) {
let stdout = '';
try {
const args = cmd.args.concat('--json', '--non-interactive', '--no-wait');
({ stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), args, {
silent: false,
}));
}
catch (error) {
throw new Error(`Could not run command eas build`, { cause: error });
}
return JSON.parse(stdout);
}
exports.easBuild = easBuild;
/**
* Create an new EAS build using the user-provided command.
*/
async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
let stdout = '';
let cmd = command;
if (!cmd.includes('--json')) {
cmd += ' --json';
}
if (!cmd.includes('--non-interactive')) {
cmd += ' --non-interactive';
}
if (!cmd.includes('--no-wait')) {
cmd += ' --no-wait';
}
try {
({ stdout } = await (0, exec_1.getExecOutput)((await (0, io_1.which)('eas', true)) + ` ${cmd}`, extraArgs, {
cwd,
}));
}
catch (error) {
throw new Error(`Could not run command eas build`, { cause: error });
}
return JSON.parse(stdout);
}
exports.createEasBuildFromRawCommandAsync = createEasBuildFromRawCommandAsync;
/**
* Cancel an EAS build.
*/
async function cancelEasBuildAsync(cwd, buildId) {
try {
await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), ['build:cancel', buildId], { cwd });
}
catch (error) {
(0, core_1.info)(`Failed to cancel build ${buildId}: ${String(error)}`);
}
}
exports.cancelEasBuildAsync = cancelEasBuildAsync;
/**
* Query the EAS BuildInfo from given buildId.
*/
async function queryEasBuildInfoAsync(cwd, buildId) {
try {
const { stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)('eas', true), ['build:view', buildId, '--json'], {
cwd,
silent: true,
});
return JSON.parse(stdout);
}
catch (error) {
(0, core_1.info)(`Failed to query eas build ${buildId}: ${String(error)}`);
}
return null;
}
exports.queryEasBuildInfoAsync = queryEasBuildInfoAsync;
/**
* Try to resolve the project info, by running 'expo config --type prebuild'.
*/
async function projectInfo(dir) {
let stdout = '';
try {
({ stdout } = await (0, exec_1.getExecOutput)(await (0, io_1.which)('expo', true), ['config', '--json', '--type', 'prebuild'], {
cwd: dir,
silent: true,
}));
}
catch (error) {
throw new Error(`Could not fetch the project info from ${dir}`, { cause: error });
}
const { name, slug, owner } = JSON.parse(stdout);
return { name, slug, owner };
}
exports.projectInfo = projectInfo;
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
function projectAppType(dir) {
const packageFile = path_1.default.resolve(dir, 'package.json');
let packageJson = {};
try {
packageJson = require(packageFile);
}
catch (error) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
exports.projectAppType = projectAppType;
/**
* Create a QR code for an update on project, with an optional release channel.
*/
function projectQR(project, channel) {
(0, assert_1.ok)(project.owner, 'Could not create a QR code for project without owner');
const url = new url_1.URL('https://qr.expo.dev/expo-go');
url.searchParams.append('owner', project.owner);
url.searchParams.append('slug', project.slug);
if (channel) {
url.searchParams.append('releaseChannel', channel);
}
return url.toString();
}
exports.projectQR = projectQR;
/**
* Create a link for the project in Expo.
*/
function projectLink(project, channel) {
(0, assert_1.ok)(project.owner, 'Could not create a QR code for project without owner');
const url = new url_1.URL(`https://expo.dev/@${project.owner}/${project.slug}`);
if (channel) {
url.searchParams.append('release-channel', channel);
}
return url.toString();
}
exports.projectLink = projectLink;
/**
* Create a deep link to open the project in Expo Go
*/
function projectDeepLink(project, channel) {
(0, assert_1.ok)(project.owner, 'Could not create a deep link for project without owner');
const url = new url_1.URL(`exp://exp.host/@${project.owner}/${project.slug}`);
if (channel) {
url.searchParams.append('release-channel', channel);
}
return url.toString();
}
exports.projectDeepLink = projectDeepLink;
function getBuildLogsUrl(build) {
// TODO: reuse this function from the original source
// see: https://github.com/expo/eas-cli/blob/896f7f038582347c57dc700be9ea7d092b5a3a21/packages/eas-cli/src/build/utils/url.ts#L13-L21
const { project } = build;
const path = project
? `/accounts/${project.ownerAccount.name}/projects/${project.slug}/builds/${build.id}`
: `/builds/${build.id}`;
const url = new url_1.URL(path, 'https://expo.dev');
return url.toString();
}
exports.getBuildLogsUrl = getBuildLogsUrl;
/***/ }),
/***/ 978:
+27 -2
View File
@@ -88912,16 +88912,20 @@ exports.handleCacheError = handleCacheError;
/***/ }),
/***/ 2489:
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
exports.getBuildLogsUrl = exports.projectDeepLink = exports.projectLink = exports.projectQR = exports.projectAppType = exports.projectInfo = exports.queryEasBuildInfoAsync = exports.cancelEasBuildAsync = exports.createEasBuildFromRawCommandAsync = exports.easBuild = exports.runCommand = exports.projectOwner = exports.authenticate = exports.parseCommand = exports.appPlatformEmojis = exports.appPlatformDisplayNames = exports.AppPlatform = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const assert_1 = __nccwpck_require__(9491);
const path_1 = __importDefault(__nccwpck_require__(1017));
const url_1 = __nccwpck_require__(7310);
var AppPlatform;
(function (AppPlatform) {
@@ -89090,6 +89094,27 @@ async function projectInfo(dir) {
return { name, slug, owner };
}
exports.projectInfo = projectInfo;
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
function projectAppType(dir) {
const packageFile = path_1.default.resolve(dir, 'package.json');
let packageJson = {};
try {
packageJson = require(packageFile);
}
catch (error) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
exports.projectAppType = projectAppType;
/**
* Create a QR code for an update on project, with an optional release channel.
*/
BIN
View File
Binary file not shown.
+2 -1
View File
@@ -1,8 +1,9 @@
/** @type {import('@jest/types').Config.InitialOptions} */
/** @type {import('jest').Config} */
module.exports = {
verbose: true,
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
prettierPath: require.resolve('jest-snapshot-prettier'),
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
transform: {
+2 -1
View File
@@ -1,7 +1,7 @@
{
"private": true,
"name": "expo-github-action",
"version": "8.1.0",
"version": "8.2.0",
"description": "Expo CLI in your GitHub Actions workflow",
"main": "build/index.js",
"repository": {
@@ -47,6 +47,7 @@
"eslint-config-universe": "^12.0.0",
"getenv": "^1.0.0",
"jest": "^29.3.1",
"jest-snapshot-prettier": "npm:prettier@^2.8.8",
"prettier": "^3.1.0",
"semantic-release": "^19.0.5",
"sqlite3": "^5.1.6",
+38 -18
View File
@@ -42,28 +42,29 @@ It can help speed up the review process by letting the reviewer load the app dir
This action is customizable through variables defined in the [`action.yml`](action.yml).
Here is a summary of all the input options you can use.
| variable | default | description |
| --------------------- | --------------------------- | ---------------------------------------------------------------------------------------------- |
| **command** | - | EAS CLI command to run when creating updates |
| **working-directory** | - | The relative directory of your Expo app |
| **app-scheme** | - | The (custom) app scheme to use when creating the preview QR code |
| **comment** | `true` | If the action should summarize the EAS Update information as comment on a pull request |
| **comment-id** | _[see code][code-defaults]_ | unique id template to prevent duplicate comments ([read more](#preventing-duplicate-comments)) |
| **github-token** | `github.token` | GitHub token to use when commenting on PR ([read more](#github-tokens)) |
| variable | default | description |
| --------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **command** | - | EAS CLI command to run when creating updates |
| **working-directory** | - | The relative directory of your Expo app |
| **comment** | `true` | If the action should summarize the EAS Update information as comment on a pull request |
| **comment-id** | _[see code][code-defaults]_ | Unique id template to prevent duplicate comments ([read more](#preventing-duplicate-comments)) |
| **qr-target** | _inferred from project_ | Either `dev-build` or `expo-go`, affects how the EAS Update is opened through the QR code. <br /> Defaults to `dev-build` when `expo-dev-client` is detected within the project. |
| **github-token** | `github.token` | GitHub token to use when commenting on PR ([read more](#github-tokens)) |
## Available outputs
There are a few variables available that you can use to set up your own notifications.
These variables are strings; some may be empty because of your project configuration.
| output name | description |
| ----------------- | ------------------------------------------------------------------------------------------------- |
| **projectId** | The resolved EAS project ID |
| **projectName** | The name of your project ([read more](https://docs.expo.dev/versions/latest/config/app/#name)) |
| **projectSlug** | The slug of your project ([read more](https://docs.expo.dev/versions/latest/config/app/#slug)) |
| **projectScheme** | The (custom) app scheme ([read more](https://docs.expo.dev/versions/latest/config/app/#scheme)) |
| **commentId** | The unique comment ID to prevent duplicate comments ([read more](#preventing-duplicate-comments)) |
| **comment** | The comment with information about the updates |
| output name | description |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| **projectId** | The resolved EAS project ID |
| **projectName** | The name of your project ([read more](https://docs.expo.dev/versions/latest/config/app/#name)) |
| **projectSlug** | The slug of your project ([read more](https://docs.expo.dev/versions/latest/config/app/#slug)) |
| **projectScheme** | The longest (custom) app scheme ([read more](https://docs.expo.dev/versions/latest/config/app/#scheme)) |
| **projectSchemes** | All (custom) app schemes in order of longest to shortest, as JSON string ([read more](https://docs.expo.dev/versions/latest/config/app/#scheme)) |
| **commentId** | The unique comment ID to prevent duplicate comments ([read more](#preventing-duplicate-comments)) |
| **comment** | The comment with information about the updates |
### Update information
@@ -123,7 +124,13 @@ You can read more about this in the [GitHub Actions documentation][link-actions]
### Create previews on pull requests
This workflow creates a new EAS Update every time a pull request is created or updated.
Since we're using the `--auto` flag, the EAS branch will be named after the GitHub branch, and the message for the update will match the commit's message.
We are using the `--auto`, together with the `--branch`, flag in this example.
- `--auto` will automatically create an update using the current git commit message and git branch.
- `--branch` will overwrite this value infere from git with our own value.
> **Warning**
> GitHub Actions might use a temporary merge branch for PRs. To avoid using this merge branch for our update, we overwrite the branch name from `--auto` with our own `--branch` value.
```yml
on:
@@ -156,7 +163,9 @@ jobs:
- name: 🚀 Create preview
uses: expo/expo-github-action/preview@v8
with:
command: eas update --auto
# `github.event.pull_request.head.ref` is only available on `pull_request` triggers.
# Use your own, or keep the automatically infered branch name from `--auto`, when using different triggers.
command: eas update --auto --branch ${{ github.event.pull_request.head.ref }}
```
### Sending preview information elsewhere
@@ -197,6 +206,8 @@ jobs:
uses: expo/expo-github-action/preview@v8
id: preview
with:
# In this example, we use the `push` trigger which will always use the branch name that was pushed to.
# By using `--auto` we both use the git commit message and branch name for the update.
command: eas update --auto
comment: false
@@ -216,6 +227,13 @@ jobs:
When automating these preview comments, you have to be careful not to spam a pull request on every successful run.
Every comment contains a generated **message-id** to identify previously made comments and update them instead of creating a new comment.
### Update branch and workflow triggers
GitHub Actions uses slightly different checkout logic for different workflow triggers.
When using the `push` trigger, GitHub Actions checks out the branch that was pushed to.
But for [`pull_request` triggers][link-gha-trigger-pull], GitHub Actions might use a temporary branch name.
This affects in what "branch" your EAS Update is created when using the `--auto` flag.
### GitHub tokens
When using the GitHub API, you always need to be authenticated.
@@ -231,3 +249,5 @@ You can overwrite the token by adding the `GITHUB_TOKEN` environment variable or
[code-defaults]: ../src/actions/preview.ts#L10
[link-actions]: https://help.github.com/en/categories/automating-your-workflow-with-github-actions
[link-gha-token]: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
[link-gha-trigger-pull]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
[link-gha-trigger-push]: https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#push
+8 -3
View File
@@ -12,15 +12,15 @@ inputs:
command:
description: EAS CLI command to run when creating updates
required: true
app-scheme:
description: The (custom) app scheme to use when creating the preview QR code
required: false
comment:
description: If the action should summarize the EAS Update information as comment on a pull request
required: false
default: true
comment-id:
description: unique id template to prevent duplicate comments
qr-target:
description: How the EAS Update is opened through the QR code, either `dev-build` or `expo-go`. Defaults to `dev-build` if `expo-dev-client` is used in project.
required: false
working-directory:
description: The relative directory of your Expo app
required: false
@@ -29,6 +29,11 @@ inputs:
description: GitHub token to use when commenting on PR
required: false
default: ${{ github.token }}
# Below are deprecated and won't be supported anymore
app-scheme:
deprecated: true
description: The (custom) app scheme to use when creating the preview QR code
required: false
outputs:
projectId:
description: The resolved EAS project ID
+53 -20
View File
@@ -1,7 +1,8 @@
import { getBooleanInput, getInput, setOutput, group, setFailed, info } from '@actions/core';
import { getBooleanInput, getInput, setOutput, group, setFailed, info, debug } from '@actions/core';
import { ExpoConfig } from '@expo/config';
import { assertEasVersion, createUpdate, EasUpdate, getUpdateGroupQr, getUpdateGroupWebsite } from '../eas';
import { projectAppType } from '../expo';
import { createIssueComment, hasPullContext, pullContext } from '../github';
import { loadProjectConfig } from '../project';
import { template } from '../utils';
@@ -10,13 +11,19 @@ import { executeAction } from '../worker';
export const MESSAGE_ID = 'projectId:{projectId}';
export function previewInput() {
const qrTarget = getInput('qr-target') || undefined;
if (qrTarget && !['expo-go', 'dev-client'].includes(qrTarget)) {
throw new Error(`Invalid QR code target: "${qrTarget}", expected "expo-go" or "dev-build"`);
}
return {
command: getInput('command'),
shouldComment: !getInput('comment') || getBooleanInput('comment'),
commentId: getInput('comment-id') || MESSAGE_ID,
workingDirectory: getInput('working-directory'),
githubToken: getInput('github-token'),
appScheme: getInput('app-scheme'),
// Note, `dev-build` is prefered, but `dev-client` is supported to aovid confusion
qrTarget: qrTarget as undefined | 'expo-go' | 'dev-build' | 'dev-client',
};
}
@@ -96,24 +103,27 @@ function sanitizeCommand(input: string): string {
/**
* Generate useful variables for the message body, and as step outputs.
*/
export function getVariables(config: ExpoConfig, updates: EasUpdate[], input: ReturnType<typeof previewInput>) {
export function getVariables(config: ExpoConfig, updates: EasUpdate[], options: ReturnType<typeof previewInput>) {
const projectId: string = config.extra?.eas?.projectId;
const android = updates.find(update => update.platform === 'android');
const ios = updates.find(update => update.platform === 'ios');
const appScheme = input.appScheme || getSchemeFromConfig(config) || '';
const appSchemes = getSchemesInOrderFromConfig(config) || [];
const appSlug = config.slug;
const qrTarget = getQrTarget(options);
return {
// EAS / Expo specific
projectId,
projectName: config.name,
projectSlug: config.slug,
projectScheme: appScheme,
projectSlug: appSlug,
projectScheme: appSchemes[0] || '', // This is the longest scheme from one or more custom app schemes
projectSchemes: JSON.stringify(appSchemes), // These are all custom app schemes, in order from longest to shortest as JSON
// Shared update properties
// Note, only use these properties when the update groups are identical
groupId: updates[0].group,
runtimeVersion: updates[0].runtimeVersion,
qr: getUpdateGroupQr({ projectId, updateGroupId: updates[0].group, appScheme }),
qr: getUpdateGroupQr({ projectId, updateGroupId: updates[0].group, appSlug, qrTarget }),
link: getUpdateGroupWebsite({ projectId, updateGroupId: updates[0].group }),
// These are safe to access regardless of the update groups
branchName: updates[0].branch,
@@ -127,7 +137,7 @@ export function getVariables(config: ExpoConfig, updates: EasUpdate[], input: Re
androidManifestPermalink: android?.manifestPermalink || '',
androidMessage: android?.message || '',
androidRuntimeVersion: android?.runtimeVersion || '',
androidQR: android ? getUpdateGroupQr({ projectId, updateGroupId: android.group, appScheme }) : '',
androidQR: android ? getUpdateGroupQr({ projectId, updateGroupId: android.group, appSlug, qrTarget }) : '',
androidLink: android ? getUpdateGroupWebsite({ projectId, updateGroupId: android.group }) : '',
// iOS update
iosId: ios?.id || '',
@@ -136,27 +146,50 @@ export function getVariables(config: ExpoConfig, updates: EasUpdate[], input: Re
iosManifestPermalink: ios?.manifestPermalink || '',
iosMessage: ios?.message || '',
iosRuntimeVersion: ios?.runtimeVersion || '',
iosQR: ios ? getUpdateGroupQr({ projectId, updateGroupId: ios.group, appScheme }) : '',
iosQR: ios ? getUpdateGroupQr({ projectId, updateGroupId: ios.group, appSlug, qrTarget }) : '',
iosLink: ios ? getUpdateGroupWebsite({ projectId, updateGroupId: ios.group }) : '',
};
}
export function getQrTarget(input: Pick<ReturnType<typeof previewInput>, 'qrTarget' | 'workingDirectory'>) {
if (!input.qrTarget) {
const appType = projectAppType(input.workingDirectory);
debug(`Using inferred QR code target: "${appType}"`);
return appType;
}
switch (input.qrTarget) {
// Note, `dev-build` is prefered, but `dev-client` is supported to aovid confusion
case 'dev-client':
case 'dev-build':
debug(`Using QR code target: "dev-build"`);
return 'dev-build';
case 'expo-go':
debug(`Using QR code target: "expo-go"`);
return 'expo-go';
default:
throw new Error(`Invalid QR code target: "${input.qrTarget}", expected "expo-go" or "dev-build"`);
}
}
/**
* Retrieve the app scheme from project config, using the following criteria:
* - If the scheme is a string, return that.
* - If the scheme is an array, return the longest scheme.
* Retrieve the app schemes, in correct priority order, from project config.
* - If the scheme is a string, return `[scheme]`.
* - If the scheme is an array, return the schemes sorted by length, longest first.
* - If the scheme is empty/incorrect, return an empty array.
*/
export function getSchemeFromConfig(config: ExpoConfig) {
export function getSchemesInOrderFromConfig(config: ExpoConfig) {
if (typeof config.scheme === 'string') {
return config.scheme;
return [config.scheme];
}
if (Array.isArray(config.scheme) && config.scheme.length > 0) {
const longestToShortest = config.scheme.sort((a, b) => b.length - a.length);
return longestToShortest[0];
if (Array.isArray(config.scheme)) {
return config.scheme.sort((a, b) => b.length - a.length);
}
return null;
return [];
}
/**
@@ -180,13 +213,13 @@ function createSummaryHeader(updates: EasUpdate[], vars: ReturnType<typeof getVa
.map(platform => `**${platform}**`)
.join(', ');
const appScheme = vars.projectScheme ? `- Scheme → **${vars.projectScheme}**` : '';
const appSchemes = vars.projectScheme ? `- Scheme → **${JSON.parse(vars.projectSchemes).join('**, **')}**` : '';
return `🚀 Expo preview is ready!
- Project → **${vars.projectSlug}**
- ${platformName} → ${platformValue}
${appScheme}`.trim();
${appSchemes}`.trim();
}
function createSingleQrSummary(updates: EasUpdate[], vars: ReturnType<typeof getVariables>) {
+8 -4
View File
@@ -71,16 +71,20 @@ export async function createUpdate(cwd: string, command: string): Promise<EasUpd
export function getUpdateGroupQr({
projectId,
updateGroupId,
appScheme,
appSlug,
qrTarget,
}: {
projectId: string;
updateGroupId: string;
appScheme?: string;
appSlug: string;
qrTarget: 'expo-go' | 'dev-build';
}): string {
const url = new URL('https://qr.expo.dev/eas-update');
if (appScheme) {
url.searchParams.append('appScheme', appScheme);
if (qrTarget === 'dev-build') {
// While the parameter is called `appScheme`, it's actually the app's slug
// This should only be added when using dev clients as target
url.searchParams.append('appScheme', appSlug);
}
url.searchParams.append('projectId', projectId);
+24
View File
@@ -2,6 +2,7 @@ import { info, exportVariable } from '@actions/core';
import { exec, getExecOutput } from '@actions/exec';
import { which } from '@actions/io';
import { ok as assert } from 'assert';
import path from 'path';
import { URL } from 'url';
export type CliName = 'expo' | 'eas';
@@ -216,6 +217,29 @@ export async function projectInfo(dir: string): Promise<ProjectInfo> {
return { name, slug, owner };
}
/**
* Determine if the current project is using `dev-build` or `expo-go`.
* This is based on the `@expo/cli` check to enable dev client mode.
*
* @see https://github.com/expo/expo/blob/190a80f393bc730eb3f300df52d82b701e4b8ff5/packages/%40expo/cli/src/utils/analytics/getDevClientProperties.ts#L12-L15
*/
export function projectAppType(dir: string): 'expo-go' | 'dev-build' {
const packageFile = path.resolve(dir, 'package.json');
let packageJson: any = {};
try {
packageJson = require(packageFile);
} catch (error: unknown) {
throw new Error(`Could not load the project package file in: ${packageFile}`, { cause: error });
}
if (packageJson?.dependencies?.['expo-dev-client'] || packageJson?.devDependencies?.['expo-dev-client']) {
return 'dev-build';
}
return 'expo-go';
}
/**
* Create a QR code for an update on project, with an optional release channel.
*/
+112 -69
View File
@@ -1,9 +1,20 @@
import { ExpoConfig } from '@expo/config';
import { createSummary, getSchemeFromConfig, getVariables, previewInput } from '../../src/actions/preview';
import {
createSummary,
getQrTarget,
getSchemesInOrderFromConfig,
getVariables,
previewInput,
} from '../../src/actions/preview';
import { EasUpdate } from '../../src/eas';
import { projectAppType } from '../../src/expo';
const fakeInput = {} as unknown as ReturnType<typeof previewInput>;
jest.mock('../../src/expo');
const fakeOptions = {
qrTarget: 'dev-client',
} as unknown as ReturnType<typeof previewInput>;
const fakeExpoConfig = {
slug: 'fake-project',
@@ -39,24 +50,57 @@ const fakeUpdatesSingle: EasUpdate[] = [
const fakeUpdatesMultiple = fakeUpdatesSingle.map(update => ({ ...update, group: `fake-group-${update.id}` }));
describe(getSchemeFromConfig, () => {
it('returns `null` when not defined', () => {
expect(getSchemeFromConfig({} as ExpoConfig)).toBeNull();
describe(getQrTarget, () => {
it('returns `dev-build` for `qr-target: dev-build`', () => {
expect(getQrTarget({ ...fakeOptions, qrTarget: 'dev-build' })).toBe('dev-build');
});
it('returns scheme when defined as string', () => {
expect(getSchemeFromConfig({ scheme: 'ega' } as ExpoConfig)).toBe('ega');
it('returns `dev-build` for `qr-target: dev-client`', () => {
expect(getQrTarget({ ...fakeOptions, qrTarget: 'dev-client' })).toBe('dev-build');
});
it('returns longest scheme when defined as array', () => {
expect(getSchemeFromConfig({ scheme: ['ega', 'expogithubaction'] } as ExpoConfig)).toBe('expogithubaction');
it('returns `expo-go` for `qr-target: expo-go`', () => {
expect(getQrTarget({ ...fakeOptions, qrTarget: 'expo-go' })).toBe('expo-go');
});
it('throws for unknown `qr-target`', () => {
expect(() => getQrTarget({ ...fakeOptions, qrTarget: 'unknown' } as any)).toThrow(
`Invalid QR code target: "unknown", expected "expo-go" or "dev-build"`
);
});
it('returns infered `dev-build` when input is omitted', () => {
jest.mocked(projectAppType).mockReturnValue('dev-build');
expect(getQrTarget({ ...fakeOptions, qrTarget: undefined })).toBe('dev-build');
});
it('returns infered `expo-go` when input is omitted', () => {
jest.mocked(projectAppType).mockReturnValue('expo-go');
expect(getQrTarget({ ...fakeOptions, qrTarget: undefined })).toBe('expo-go');
});
});
describe(getSchemesInOrderFromConfig, () => {
it('returns empty array when not defined', () => {
expect(getSchemesInOrderFromConfig({} as ExpoConfig)).toEqual([]);
});
it('returns scheme as array when defined as string', () => {
expect(getSchemesInOrderFromConfig({ scheme: 'ega' } as ExpoConfig)).toEqual(['ega']);
});
it('returns schemes in order when defined as array', () => {
expect(getSchemesInOrderFromConfig({ scheme: ['ega', 'expogithubaction'] } as ExpoConfig)).toEqual([
'expogithubaction',
'ega',
]);
});
});
describe(createSummary, () => {
describe('single update group', () => {
it('returns expected message for both platforms', () => {
expect(createSummary(fakeUpdatesSingle, getVariables(fakeExpoConfig, fakeUpdatesSingle, fakeInput)))
expect(createSummary(fakeUpdatesSingle, getVariables(fakeExpoConfig, fakeUpdatesSingle, fakeOptions)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
@@ -65,7 +109,7 @@ describe(createSummary, () => {
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
@@ -73,35 +117,17 @@ describe(createSummary, () => {
it('returns expected message for both platforms with custom app scheme', () => {
const customSchemeConfig = { ...fakeExpoConfig, scheme: ['ega', 'expogithubaction'] };
expect(createSummary(fakeUpdatesSingle, getVariables(customSchemeConfig, fakeUpdatesSingle, fakeInput)))
expect(createSummary(fakeUpdatesSingle, getVariables(customSchemeConfig, fakeUpdatesSingle, fakeOptions)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platforms → **android**, **ios**
- Scheme → **expogithubaction**
- Scheme → **expogithubaction**, **ega**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns expected message for both platforms with overwriten app scheme', () => {
const customInput = { ...fakeInput, appScheme: 'expogithubaction' };
expect(createSummary(fakeUpdatesSingle, getVariables(fakeExpoConfig, fakeUpdatesSingle, customInput)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platforms → **android**, **ios**
- Scheme → **expogithubaction**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=expogithubaction&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
@@ -109,7 +135,7 @@ describe(createSummary, () => {
it('returns expected message for android only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'android');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeInput))).toMatchInlineSnapshot(`
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeOptions))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
@@ -117,7 +143,7 @@ describe(createSummary, () => {
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
@@ -125,7 +151,7 @@ describe(createSummary, () => {
it('returns expected message for ios only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'ios');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeInput))).toMatchInlineSnapshot(`
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeOptions))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
@@ -133,7 +159,7 @@ describe(createSummary, () => {
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
@@ -142,7 +168,56 @@ describe(createSummary, () => {
describe('mutliple update groups', () => {
it('returns expected message for both platforms', () => {
expect(createSummary(fakeUpdatesMultiple, getVariables(fakeExpoConfig, fakeUpdatesMultiple, fakeInput)))
expect(createSummary(fakeUpdatesMultiple, getVariables(fakeExpoConfig, fakeUpdatesMultiple, fakeOptions)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platforms → **android**, **ios**
Android <br /> _(exposdk:47.0.0)_ <br /> **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-fake-android-id)** | iOS <br /> _(exposdk:47.0.0)_ <br /> **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-fake-ios-id)**
--- | ---
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-fake-android-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-fake-android-id" width="250px" height="250px" /></a> | <a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-fake-ios-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-fake-ios-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns expected message for android only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'android');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeOptions))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platform → **android**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns expected message for ios only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'ios');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeOptions))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platform → **ios**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?appScheme=fake-project&projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns Expo Go compatible QR code when forced', () => {
const customOptions: typeof fakeOptions = { ...fakeOptions, qrTarget: 'expo-go' };
expect(createSummary(fakeUpdatesMultiple, getVariables(fakeExpoConfig, fakeUpdatesMultiple, customOptions)))
.toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
@@ -156,37 +231,5 @@ describe(createSummary, () => {
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns expected message for android only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'android');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeInput))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platform → **android**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
it('returns expected message for ios only', () => {
const fakeUpdate = fakeUpdatesSingle.filter(update => update.platform === 'ios');
expect(createSummary(fakeUpdate, getVariables(fakeExpoConfig, fakeUpdate, fakeInput))).toMatchInlineSnapshot(`
"🚀 Expo preview is ready!
- Project → **fake-project**
- Platform → **ios**
- Runtime Version → **exposdk:47.0.0**
- **[More info](https://expo.dev/projects/fake-project-id/updates/fake-group-id)**
<a href="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id"><img src="https://qr.expo.dev/eas-update?projectId=fake-project-id&groupId=fake-group-id" width="250px" height="250px" /></a>
> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview#example-workflows)"
`);
});
});
});