Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[eas-cli] integrated credentials service with android submissions #664

Merged
merged 7 commits into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is the log of notable changes to EAS CLI and related packages.

### 🎉 New features

- Integrate credentials service with Android submissions. ([#664](https://github.com/expo/eas-cli/pull/664) by [@quinlanj](https://github.com/quinlanj))

### 🐛 Bug fixes

### 🧹 Chores
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe(CreateGoogleServiceAccountKey, () => {
'/google-service-account-key.json': JSON.stringify({
type: 'service_account',
private_key: 'super secret',
client_email: 'beep-boop@iam.gserviceaccount.com',
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe(SetupGoogleServiceAccountKey, () => {
'/google-service-account-key.json': JSON.stringify({
type: 'service_account',
private_key: 'super secret',
client_email: 'beep-boop@iam.gserviceaccount.com',
}),
});
const ctx = createCtxMock({
Expand Down
2 changes: 2 additions & 0 deletions packages/eas-cli/src/credentials/android/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export type KeystoreWithType = Keystore & {
export type GoogleServiceAccountKey = {
[key: string]: any;
private_key: string;
type: string;
client_email: string;
};

export type AndroidCredentials = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ beforeAll(() => {
const mockDetectableServiceAccountJson = JSON.stringify({
type: 'service_account',
private_key: 'super secret',
client_email: 'beep-boop@iam.gserviceaccount.com',
});

vol.fromJSON({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { GoogleServiceAccountKey } from '../credentials';
export const MinimalGoogleServiceAccountKeySchema = Joi.object({
type: Joi.string().required(),
private_key: Joi.string().required(),
client_email: Joi.string().required(),
});

function fileIsServiceAccountKey(keyJsonPath: string): boolean {
Expand Down
9 changes: 3 additions & 6 deletions packages/eas-cli/src/submit/android/AndroidSubmitCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,9 @@ export default class AndroidSubmitCommand {
sourceType: ServiceAccountSourceType.path,
path: serviceAccountKeyPath,
});
} else if (this.ctx.nonInteractive) {
return result(new Error('Set serviceAccountKeyPath in the submit profile (eas.json).'));
} else {
return result({
sourceType: ServiceAccountSourceType.detect,
});
}
return result({
sourceType: ServiceAccountSourceType.credentialsService,
});
}
}
41 changes: 29 additions & 12 deletions packages/eas-cli/src/submit/android/AndroidSubmitter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Platform } from '@expo/eas-build-job';
import fs from 'fs-extra';

import {
AndroidSubmissionConfigInput,
Expand All @@ -16,7 +15,11 @@ import {
printSummary,
} from '../utils/summary';
import { AndroidPackageSource, getAndroidPackageAsync } from './AndroidPackageSource';
import { ServiceAccountSource, getServiceAccountAsync } from './ServiceAccountSource';
import {
ServiceAccountKeyResult,
ServiceAccountSource,
getServiceAccountKeyResultAsync,
} from './ServiceAccountSource';

export interface AndroidSubmissionOptions
extends Pick<
Expand All @@ -32,7 +35,7 @@ export interface AndroidSubmissionOptions
interface ResolvedSourceOptions {
androidPackage: string;
archive: Archive;
serviceAccountPath: string;
serviceAccountKeyResult: ServiceAccountKeyResult;
}

export default class AndroidSubmitter extends BaseSubmitter<
Expand Down Expand Up @@ -73,35 +76,43 @@ export default class AndroidSubmitter extends BaseSubmitter<
private async resolveSourceOptionsAsync(): Promise<ResolvedSourceOptions> {
const androidPackage = await getAndroidPackageAsync(this.options.androidPackageSource);
const archive = await getArchiveAsync(this.options.archiveSource);
const serviceAccountPath = await getServiceAccountAsync(this.options.serviceAccountSource);
const serviceAccountKeyResult = await getServiceAccountKeyResultAsync(
this.ctx,
this.options.serviceAccountSource,
androidPackage
);
return {
androidPackage,
archive,
serviceAccountPath,
serviceAccountKeyResult,
};
}

private async formatSubmissionConfigAsync(
options: AndroidSubmissionOptions,
{ archive, androidPackage, serviceAccountPath }: ResolvedSourceOptions
{ archive, androidPackage, serviceAccountKeyResult }: ResolvedSourceOptions
): Promise<AndroidSubmissionConfigInput> {
const serviceAccount = await fs.readFile(serviceAccountPath, 'utf-8');
const { track, releaseStatus, changesNotSentForReview } = options;
return {
applicationIdentifier: androidPackage,
archiveUrl: archive.url,
track,
changesNotSentForReview,
releaseStatus,
googleServiceAccountKeyJson: serviceAccount,
...serviceAccountKeyResult.result,
};
}

private prepareSummaryData(
options: AndroidSubmissionOptions,
{ archive, androidPackage, serviceAccountPath }: ResolvedSourceOptions
{ archive, androidPackage, serviceAccountKeyResult }: ResolvedSourceOptions
): SummaryData {
const { projectId, track, releaseStatus, changesNotSentForReview } = options;
const {
email: serviceAccountEmail,
path: serviceAccountKeyPath,
source: serviceAccountKeySource,
} = serviceAccountKeyResult.summary;

// structuring order affects table rows order
return {
Expand All @@ -110,7 +121,9 @@ export default class AndroidSubmitter extends BaseSubmitter<
track,
changesNotSentForReview: changesNotSentForReview ?? undefined,
releaseStatus: releaseStatus ?? undefined,
serviceAccountPath,
serviceAccountEmail,
serviceAccountKeySource,
...(serviceAccountKeyPath ? { serviceAccountKeyPath } : {}),
...formatArchiveSourceSummary(archive),
};
}
Expand All @@ -121,7 +134,9 @@ type SummaryData = {
changesNotSentForReview?: boolean;
projectId: string;
releaseStatus?: SubmissionAndroidReleaseStatus;
serviceAccountPath: string;
serviceAccountKeySource: string;
serviceAccountKeyPath?: string;
serviceAccountEmail: string;
track: SubmissionAndroidTrack;
} & ArchiveSourceSummaryFields;

Expand All @@ -133,6 +148,8 @@ const SummaryHumanReadableKeys: Record<keyof SummaryData, string> = {
formattedBuild: 'Build',
projectId: 'Project ID',
releaseStatus: 'Release status',
serviceAccountPath: 'Google Service Key',
serviceAccountKeySource: 'Google Service Key Source',
serviceAccountKeyPath: 'Google Service Key Path',
serviceAccountEmail: 'Google Service Account',
track: 'Release track',
};
Loading