-
Notifications
You must be signed in to change notification settings - Fork 199
[eas-cli] Add --refresh-distribution-certificate for non-intractive builds
#3739
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
base: graphite-base/3739
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||||||||
| import assert from 'assert'; | ||||||||||||||||||
|
|
||||||||||||||||||
| import { resolveAppleTeamIfAuthenticatedAsync } from './AppleTeamUtils'; | ||||||||||||||||||
| import { resolveAscApiKeyForAppCredentialsAsync } from './AscApiKeyUtils'; | ||||||||||||||||||
| import { CreateDistributionCertificate } from './CreateDistributionCertificate'; | ||||||||||||||||||
| import { formatDistributionCertificate } from './DistributionCertificateUtils'; | ||||||||||||||||||
| import { | ||||||||||||||||||
|
|
@@ -16,6 +17,8 @@ import { MissingCredentialsNonInteractiveError } from '../../errors'; | |||||||||||||||||
| import { AppleDistributionCertificateMutationResult } from '../api/graphql/mutations/AppleDistributionCertificateMutation'; | ||||||||||||||||||
| import { AppLookupParams } from '../api/graphql/types/AppLookupParams'; | ||||||||||||||||||
| import { getValidCertSerialNumbers } from '../appstore/CredentialsUtils'; | ||||||||||||||||||
| import { AppleTeamType, AuthenticationMode } from '../appstore/authenticateTypes'; | ||||||||||||||||||
| import { hasAscEnvVars } from '../appstore/resolveCredentials'; | ||||||||||||||||||
| import { AppleTeamMissingError } from '../errors'; | ||||||||||||||||||
|
|
||||||||||||||||||
| export class SetUpDistributionCertificate { | ||||||||||||||||||
|
|
@@ -50,13 +53,64 @@ export class SetUpDistributionCertificate { | |||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private async ensureAppStoreAuthenticatedForDistCertRefreshAsync( | ||||||||||||||||||
| ctx: CredentialsContext | ||||||||||||||||||
| ): Promise<void> { | ||||||||||||||||||
| if (ctx.appStore.authCtx) { | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
| if (hasAscEnvVars()) { | ||||||||||||||||||
| await ctx.appStore.ensureAuthenticatedAsync({ mode: AuthenticationMode.API_KEY }); | ||||||||||||||||||
| return; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| const resolvedKey = await resolveAscApiKeyForAppCredentialsAsync({ | ||||||||||||||||||
| graphqlClient: ctx.graphqlClient, | ||||||||||||||||||
| app: this.app, | ||||||||||||||||||
| }); | ||||||||||||||||||
| if (!resolvedKey) { | ||||||||||||||||||
| throw new Error( | ||||||||||||||||||
| 'No App Store Connect API Key found for distribution certificate refresh. In non-interactive mode, provide one via:\n' + | ||||||||||||||||||
| ' - Environment variables: EXPO_ASC_API_KEY_PATH, EXPO_ASC_KEY_ID, EXPO_ASC_ISSUER_ID\n' + | ||||||||||||||||||
| ' - EAS credentials service: configure an App Store Connect API Key for submissions on this app' | ||||||||||||||||||
| ); | ||||||||||||||||||
| } | ||||||||||||||||||
| await ctx.appStore.ensureAuthenticatedAsync({ | ||||||||||||||||||
| mode: AuthenticationMode.API_KEY, | ||||||||||||||||||
| ascApiKey: resolvedKey.ascApiKey, | ||||||||||||||||||
| teamId: resolvedKey.teamId, | ||||||||||||||||||
| teamName: resolvedKey.teamName, | ||||||||||||||||||
| teamType: AppleTeamType.COMPANY_OR_ORGANIZATION, | ||||||||||||||||||
| }); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private async runNonInteractiveAsync( | ||||||||||||||||||
| _ctx: CredentialsContext, | ||||||||||||||||||
| ctx: CredentialsContext, | ||||||||||||||||||
| currentCertificate: AppleDistributionCertificateFragment | null | ||||||||||||||||||
| ): Promise<AppleDistributionCertificateFragment> { | ||||||||||||||||||
| // TODO: implement validation | ||||||||||||||||||
| if (ctx.refreshDistributionCertificate) { | ||||||||||||||||||
| await this.ensureAppStoreAuthenticatedForDistCertRefreshAsync(ctx); | ||||||||||||||||||
|
|
||||||||||||||||||
| if (await this.isCurrentCertificateValidAsync(ctx, currentCertificate)) { | ||||||||||||||||||
| assert(currentCertificate, 'currentCertificate is defined here'); | ||||||||||||||||||
|
Comment on lines
+94
to
+95
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
this makes more sense to me? |
||||||||||||||||||
| Log.log('Using existing valid distribution certificate.'); | ||||||||||||||||||
| return currentCertificate; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Log.warn('Current distribution certificate is invalid. Creating a new one...'); | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this log.warn to when we actually create a new cert, since it's possible we could reuse
Suggested change
|
||||||||||||||||||
| const validDistCerts = await this.getValidDistCertsAsync(ctx); | ||||||||||||||||||
| if (validDistCerts.length > 0) { | ||||||||||||||||||
| const cert = validDistCerts[0]; | ||||||||||||||||||
| Log.log(`Reusing distribution certificate with serial number ${cert.serialNumber}`); | ||||||||||||||||||
| return cert; | ||||||||||||||||||
| } | ||||||||||||||||||
| return await this.createNewDistCertAsync(ctx); | ||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how likely is that we're going to hit eas-cli/packages/eas-cli/src/credentials/ios/actions/DistributionCertificateUtils.ts Lines 219 to 223 in 62ab329
|
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| Log.addNewLineIfNone(); | ||||||||||||||||||
| Log.warn('Distribution Certificate is not validated for non-interactive builds.'); | ||||||||||||||||||
| Log.warn( | ||||||||||||||||||
| 'Using the existing distribution certificate without validating it against Apple servers. Use --refresh-distribution-certificate to validate and refresh if needed.' | ||||||||||||||||||
| ); | ||||||||||||||||||
| if (!currentCertificate) { | ||||||||||||||||||
| throw new MissingCredentialsNonInteractiveError(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ugh it's still weird to me we're saying to use key for submissions to generate certificates