Skip to content

Commit 6e66109

Browse files
authored
fix(appflow): Default should be all available not hard-coded by platform (#4645)
* fix(appflow): Default should be all available not hard-coded by platform * Update error messages
1 parent bce15d1 commit 6e66109

File tree

1 file changed

+46
-35
lines changed
  • packages/@ionic/cli/src/commands/package

1 file changed

+46
-35
lines changed

packages/@ionic/cli/src/commands/package/build.ts

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const IOS_ARTIFACT_TYPES = ['ipa', 'dsym'];
2727
const ARTIFACT_TYPES = ANDROID_ARTIFACT_TYPES.concat(IOS_ARTIFACT_TYPES);
2828
const TARGET_PLATFORM = ['Android', 'iOS - Xcode 11 (Preferred)', 'iOS - Xcode 10'];
2929

30+
interface Artifact {
31+
name: string;
32+
url: string;
33+
artifact_type: string;
34+
}
35+
3036
export interface PackageBuild {
3137
job_id: number;
3238
id: string;
@@ -48,6 +54,7 @@ export interface PackageBuild {
4854
distribution_credential_name: string;
4955
job: any;
5056
distribution_trace: string;
57+
artifacts: Artifact[];
5158
}
5259

5360
interface DownloadUrl {
@@ -293,16 +300,6 @@ if you do not wish to download ${input('apk')}.
293300
const token = await this.env.session.getUserToken();
294301
const appflowId = await this.project.requireAppflowId();
295302
const [ platform, buildType ] = inputs;
296-
let artifactTypes;
297-
298-
if (Array.isArray(options['artifact-type'])) {
299-
artifactTypes = options['artifact-type'].map(val => val.toUpperCase());
300-
} else if (typeof options['artifact-type'] == 'string' && ARTIFACT_TYPES.includes(options['artifact-type'])) {
301-
artifactTypes = [options['artifact-type'].toUpperCase()]
302-
} else {
303-
const useOriginalDefault = !!(options['build-file-name']);
304-
artifactTypes = await this.getDefaultArtifactType(platform, useOriginalDefault);
305-
}
306303

307304
if (!options.commit) {
308305
options.commit = (await this.env.shell.output('git', ['rev-parse', 'HEAD'], { cwd: this.project.directory })).trim();
@@ -318,7 +315,7 @@ if you do not wish to download ${input('apk')}.
318315
['Commit', strong(`${build.commit.sha.substring(0, 6)} ${build.commit.note}`)],
319316
['Target Platform', strong(build.stack.friendly_name)],
320317
['Build Type', strong(build.build_type)],
321-
['Artifact Type(s)', strong(`${artifactTypes}`)],
318+
['Artifact Type(s)', options['artifact-type'] ? strong(`${options['artifact-type']}`.toUpperCase()) : weak('all available')],
322319
['Security Profile', build.profile_tag ? strong(build.profile_tag) : weak('not set')],
323320
['Environment', build.environment_name ? strong(build.environment_name) : weak('not set')],
324321
['Native Config', build.native_config_name ? strong(build.native_config_name) : weak('not set')],
@@ -335,24 +332,28 @@ if you do not wish to download ${input('apk')}.
335332
throw new Error(`Build ${build.state}`);
336333
}
337334

338-
for (const artifactType of artifactTypes) {
339-
const url = await this.getDownloadUrl(appflowId, buildId, artifactType, token);
335+
const availableArtifactTypes = build.artifacts.map((artifact) => artifact.artifact_type);
340336

341-
if (!url.url) {
342-
throw new Error('Missing URL in response');
337+
if (Array.isArray(options['artifact-type'])) {
338+
let errors = [];
339+
for (const artifactType of new Set(options['artifact-type'])) {
340+
try {
341+
await this.downloadArtifact(appflowId, buildId, artifactType, token, options);
342+
} catch (error) {
343+
errors.push(error);
344+
}
343345
}
344346

345-
let customBuildFileName = '';
346-
347-
if (options['build-file-name']) {
348-
this.env.log.warn(`The ${input('--build-file-name')} option has been deprecated. Please use ${input('--ipa-name')}, ${input('--apk-name')} or ${input('--{ artifact }-name')}.`);
349-
customBuildFileName = await this.sanitizeString(options['build-file-name']);
350-
} else {
351-
customBuildFileName = await this.sanitizeString(options[`${artifactType.toLowerCase()}-name`]);
347+
if (errors.length) {
348+
throw new FatalException(`There were issues downloading artifacts: ${errors.join('\n')}`);
352349
}
353350

354-
const filename = await this.downloadBuild(url.url, customBuildFileName);
355-
this.env.log.ok(`Artifact downloaded: ${filename}`);
351+
} else if (typeof options['artifact-type'] == 'string') {
352+
await this.downloadArtifact(appflowId, buildId, options['artifact-type'], token, options);
353+
} else {
354+
for (const artifactType of availableArtifactTypes) {
355+
await this.downloadArtifact(appflowId, buildId, artifactType.toUpperCase(), token, options);
356+
}
356357
}
357358
}
358359

@@ -369,17 +370,6 @@ if you do not wish to download ${input('apk')}.
369370
return String(value);
370371
}
371372

372-
async getDefaultArtifactType(platform: string, useOriginalDefault?: boolean): Promise<Array<string>> {
373-
switch (platform) {
374-
case 'ios':
375-
return useOriginalDefault ? ['IPA'] : ['IPA', 'DSYM'];
376-
case 'android':
377-
return useOriginalDefault ? ['APK'] : ['APK', 'AAB'] ;
378-
default:
379-
throw new Error(`No default artifact type for platform '${platform}'`);
380-
}
381-
}
382-
383373
async createPackageBuild(appflowId: string, token: string, platform: string, buildType: string, options: CommandLineOptions): Promise<PackageBuild> {
384374
const { req } = await this.env.client.make('POST', `/apps/${appflowId}/packages/verbose_post`);
385375
req.set('Authorization', `Bearer ${token}`).send({
@@ -502,4 +492,25 @@ if you do not wish to download ${input('apk')}.
502492
fs.unlinkSync(tmpFile);
503493
return filename;
504494
}
495+
496+
async downloadArtifact(appflowId: string, buildId: number, artifactType: string, token: string, options: CommandLineOptions) {
497+
498+
const url = await this.getDownloadUrl(appflowId, buildId, artifactType.toUpperCase(), token);
499+
500+
if (!url.url) {
501+
throw new Error(`Artifact type '${artifactType}' not found`);
502+
}
503+
504+
let customBuildFileName = '';
505+
506+
if (options['build-file-name']) {
507+
this.env.log.warn(`The ${input('--build-file-name')} option has been deprecated. Please use ${input('--ipa-name')}, ${input('--apk-name')} or ${input('--{ artifact }-name')}.`);
508+
customBuildFileName = await this.sanitizeString(options['build-file-name']);
509+
} else {
510+
customBuildFileName = await this.sanitizeString(options[`${artifactType.toLowerCase()}-name`]);
511+
}
512+
513+
const filename = await this.downloadBuild(url.url, customBuildFileName);
514+
this.env.log.ok(`Artifact downloaded: ${filename}`);
515+
}
505516
}

0 commit comments

Comments
 (0)