Skip to content

Commit 14bcf91

Browse files
[eas-cli] Add non-interactive and json flags to upload command (#2983)
* [eas-cli] Add non-interactive and json flags to upload command * Add changelog entry * Add update command to readme * Update packages/eas-cli/src/commands/upload.ts Co-authored-by: Quinlan Jung <[email protected]> --------- Co-authored-by: Quinlan Jung <[email protected]>
1 parent 6ae19df commit 14bcf91

File tree

3 files changed

+79
-14
lines changed

3 files changed

+79
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This is the log of notable changes to EAS CLI and related packages.
88

99
### 🎉 New features
1010

11+
- Add `eas upload` command. ([#2932](https://github.com/expo/eas-cli/pull/2932), [#2981](https://github.com/expo/eas-cli/pull/2981), [#2983](https://github.com/expo/eas-cli/pull/2983) by [@gabrieldonadel](https://github.com/gabrieldonadel))
1112
- Add `eas build:download` command. ([#2982](https://github.com/expo/eas-cli/pull/2982) by [@gabrieldonadel](https://github.com/gabrieldonadel))
1213

1314
### 🐛 Bug fixes

packages/eas-cli/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ eas --help COMMAND
132132
* [`eas update:roll-back-to-embedded`](#eas-updateroll-back-to-embedded)
133133
* [`eas update:rollback`](#eas-updaterollback)
134134
* [`eas update:view GROUPID`](#eas-updateview-groupid)
135+
* [`eas upload`](#eas-upload)
135136
* [`eas webhook:create`](#eas-webhookcreate)
136137
* [`eas webhook:delete [ID]`](#eas-webhookdelete-id)
137138
* [`eas webhook:list`](#eas-webhooklist)
@@ -472,6 +473,7 @@ FLAGS
472473
--dev-client=<value> Filter only dev-client builds.
473474
--fingerprint=<value> (required) Fingerprint hash of the build to run.
474475
--non-interactive Run the command in non-interactive mode.
476+
--json Enable JSON output, non-JSON messages will be printed to stderr.
475477
-p, --platform=(ios|android)
476478
477479
DESCRIPTION
@@ -1888,6 +1890,28 @@ DESCRIPTION
18881890

18891891
_See code: [packages/eas-cli/src/commands/update/view.ts](https://github.com/expo/eas-cli/blob/v16.2.2/packages/eas-cli/src/commands/update/view.ts)_
18901892

1893+
## `eas upload`
1894+
1895+
uploads a local build to EAS
1896+
1897+
```
1898+
USAGE
1899+
$ eas upload [-p ios|android] [--build-path <value>] [--fingerprint <value>]
1900+
1901+
FLAGS
1902+
--build-path=<value> Path to the build artifact.
1903+
--dev-client=<value> Filter only dev-client builds.
1904+
--fingerprint=<value> Manual fingerprint hash to include in the build.
1905+
--non-interactive Run the command in non-interactive mode.
1906+
--json Enable JSON output, non-JSON messages will be printed to stderr.
1907+
-p, --platform=(ios|android)
1908+
1909+
DESCRIPTION
1910+
upload a local build and generates a sharable link
1911+
```
1912+
1913+
_See code: [packages/eas-cli/src/commands/build/download.ts](https://github.com/expo/eas-cli/blob/v16.2.2/packages/eas-cli/src/commands/build/download.ts)_
1914+
18911915
## `eas webhook:create`
18921916

18931917
create a webhook

packages/eas-cli/src/commands/upload.ts

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { v4 as uuidv4 } from 'uuid';
1111
import { getBuildLogsUrl } from '../build/utils/url';
1212
import EasCommand from '../commandUtils/EasCommand';
1313
import { ExpoGraphqlClient } from '../commandUtils/context/contextUtils/createGraphqlClient';
14-
import { EASNonInteractiveFlag } from '../commandUtils/flags';
14+
import { EasNonInteractiveAndJsonFlags } from '../commandUtils/flags';
1515
import {
1616
DistributionType,
1717
LocalBuildArchiveSourceType,
@@ -24,6 +24,7 @@ import Log from '../log';
2424
import { promptAsync } from '../prompts';
2525
import * as xcode from '../run/ios/xcode';
2626
import { uploadFileAtPathToGCSAsync } from '../uploads';
27+
import { enableJsonOutput, printJsonOnlyOutput } from '../utils/json';
2728
import { getTmpDirectory } from '../utils/paths';
2829
import { createProgressTracker } from '../utils/progress';
2930

@@ -42,7 +43,7 @@ export default class BuildUpload extends EasCommand {
4243
fingerprint: Flags.string({
4344
description: 'Fingerprint hash of the local build',
4445
}),
45-
...EASNonInteractiveFlag,
46+
...EasNonInteractiveAndJsonFlags,
4647
};
4748

4849
static override contextDefinition = {
@@ -52,16 +53,29 @@ export default class BuildUpload extends EasCommand {
5253

5354
async runAsync(): Promise<void> {
5455
const { flags } = await this.parse(BuildUpload);
55-
const { 'build-path': buildPath, fingerprint: manualFingerprintHash } = flags;
56+
const {
57+
'build-path': buildPath,
58+
fingerprint: manualFingerprintHash,
59+
json: jsonFlag,
60+
'non-interactive': nonInteractive,
61+
} = flags;
5662
const {
5763
projectId,
5864
loggedIn: { graphqlClient },
5965
} = await this.getContextAsync(BuildUpload, {
60-
nonInteractive: false,
66+
nonInteractive,
6167
});
6268

63-
const platform = await this.selectPlatformAsync(flags.platform);
64-
const localBuildPath = await resolveLocalBuildPathAsync(platform, buildPath);
69+
if (jsonFlag) {
70+
enableJsonOutput();
71+
}
72+
73+
const platform = await this.selectPlatformAsync({ platform: flags.platform, nonInteractive });
74+
const localBuildPath = await resolveLocalBuildPathAsync({
75+
platform,
76+
inputBuildPath: buildPath,
77+
nonInteractive,
78+
});
6579

6680
const {
6781
fingerprintHash: buildFingerprintHash,
@@ -74,7 +88,8 @@ export default class BuildUpload extends EasCommand {
7488
if (
7589
manualFingerprintHash &&
7690
buildFingerprintHash &&
77-
manualFingerprintHash !== buildFingerprintHash
91+
manualFingerprintHash !== buildFingerprintHash &&
92+
!nonInteractive
7893
) {
7994
const selectedAnswer = await promptAsync({
8095
name: 'fingerprint',
@@ -107,10 +122,26 @@ export default class BuildUpload extends EasCommand {
107122
{ distribution: DistributionType.Internal, fingerprintHash: fingerprint, developmentClient }
108123
);
109124

110-
Log.withTick(`Here is a sharable link of your build: ${getBuildLogsUrl(build)}`);
125+
if (jsonFlag) {
126+
printJsonOnlyOutput({ url: getBuildLogsUrl(build) });
127+
return;
128+
}
129+
130+
Log.withTick(`Shareable link to the build: ${getBuildLogsUrl(build)}`);
131+
111132
}
112133

113-
private async selectPlatformAsync(platform?: Platform): Promise<Platform> {
134+
private async selectPlatformAsync({
135+
nonInteractive,
136+
platform,
137+
}: {
138+
nonInteractive: boolean;
139+
platform?: Platform;
140+
}): Promise<Platform> {
141+
if (nonInteractive && !platform) {
142+
throw new Error('Platform must be provided in non-interactive mode');
143+
}
144+
114145
if (platform) {
115146
return platform;
116147
}
@@ -127,10 +158,15 @@ export default class BuildUpload extends EasCommand {
127158
}
128159
}
129160

130-
async function resolveLocalBuildPathAsync(
131-
platform: Platform,
132-
inputBuildPath?: string
133-
): Promise<string> {
161+
async function resolveLocalBuildPathAsync({
162+
platform,
163+
inputBuildPath,
164+
nonInteractive,
165+
}: {
166+
platform: Platform;
167+
inputBuildPath?: string;
168+
nonInteractive: boolean;
169+
}): Promise<string> {
134170
const rootDir = process.cwd();
135171
let applicationArchivePatternOrPath: string[] = [];
136172

@@ -156,7 +192,7 @@ async function resolveLocalBuildPathAsync(
156192
patternOrPathArray: applicationArchivePatternOrPath,
157193
});
158194

159-
if (applicationArchives.length === 0 && !inputBuildPath) {
195+
if (applicationArchives.length === 0 && !nonInteractive && !inputBuildPath) {
160196
Log.warn(`No application archives found at ${applicationArchivePatternOrPath}.`);
161197
const { path } = await promptAsync({
162198
type: 'text',
@@ -175,6 +211,10 @@ async function resolveLocalBuildPathAsync(
175211
}
176212

177213
if (applicationArchives.length > 1) {
214+
if (nonInteractive) {
215+
return applicationArchives[0];
216+
}
217+
178218
const { path } = await promptAsync({
179219
type: 'select',
180220
name: 'path',

0 commit comments

Comments
 (0)