Skip to content

Commit 16729ba

Browse files
authored
Fall back to manual profiles on code singing error (#294)
* Added Step input `fallback_provisioning_profile_url_list`. If set the listed profiles will be installed when Automatic code signing fails (for example due to an API or authentication failure).
1 parent ffdfc83 commit 16729ba

File tree

15 files changed

+444
-134
lines changed

15 files changed

+444
-134
lines changed

e2e/bitrise.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@ workflows:
106106
- keychain_path: $BITRISE_KEYCHAIN_PATH
107107
- keychain_password: $BITRISE_KEYCHAIN_PASSWORD
108108

109+
test_api_key_signing_manual_fallback_on_error:
110+
description: |-
111+
Running in isolation as overwrites auth params.
112+
steps:
113+
- bitrise-run:
114+
inputs:
115+
- workflow_id: utility_test_api_key_signing_manual_fallback_on_error
116+
- bitrise_config_path: ./e2e/bitrise.yml
117+
118+
utility_test_api_key_signing_manual_fallback_on_error:
119+
description: Test fallback to manual signing on code signing error
120+
envs:
121+
- TEST_APP_URL: https://github.com/bitrise-io/sample-apps-ios-simple-objc.git
122+
- TEST_APP_BRANCH: new-certificates
123+
- BITRISE_PROJECT_PATH: ios-simple-objc/ios-simple-objc.xcodeproj
124+
- BITRISE_SCHEME: ios-simple-objc
125+
- CODE_SIGNING_METHOD: api-key
126+
- XCCONFIG_CONTENT: |
127+
COMPILER_INDEX_STORE_ENABLE = NO
128+
CODE_SIGN_IDENTITY = iPhone Developer: Dev Portal Bot Bitrise
129+
- MIN_DAYS_PROFILE_VALID: 0
130+
- IPA_EXPORT_METHOD: development
131+
- LOG_FORMATTER: xcodebuild
132+
- FALLBACK_PROFILES: $BITFALL_APPLE_PROVISIONING_PROFILE_URL_LIST
133+
after_run:
134+
- _invalid_login
135+
- _run
136+
- _check_outputs
137+
- _check_exported_artifacts
138+
109139
test_api_key_signing_managed:
110140
description: Fruta project requires Xcode 13+. Remove this conditional run if we don't run tests on Xcode 12 anymore
111141
steps:
@@ -375,12 +405,14 @@ workflows:
375405
- certificate_url_list: $BITFALL_APPLE_APPLE_CERTIFICATE_URL_LIST|$BITFALL_APPLE_IOS_CERTIFICATE_URL_LIST
376406
- passphrase_list: $BITFALL_APPLE_APPLE_CERTIFICATE_PASSPHRASE_LIST|$BITFALL_APPLE_IOS_CERTIFICATE_PASSPHRASE_LIST
377407
- distribution_method: $IPA_EXPORT_METHOD
408+
- xcconfig_content: $XCCONFIG_CONTENT
378409
- icloud_container_environment: $IPA_EXPORT_ICLOUD_CONTAINER_ENVIRONMENT
379410
- export_development_team: $TEAM_ID
380411
- log_formatter: $LOG_FORMATTER
381412
- verbose_log: "yes"
382413
- keychain_path: $BITRISE_KEYCHAIN_PATH
383414
- keychain_password: $BITRISE_KEYCHAIN_PASSWORD
415+
- fallback_provisioning_profile_url_list: $FALLBACK_PROFILES
384416

385417
_check_outputs:
386418
steps:
@@ -456,3 +488,22 @@ workflows:
456488
echo "$infoplist_path does not exist."
457489
exit 1
458490
fi
491+
492+
_invalid_login:
493+
steps:
494+
- script:
495+
title: Set invalid login
496+
inputs:
497+
- content: |-
498+
#!/bin/env bash
499+
set -ex
500+
INVALID_BUILD_URL=./_invalid_authinfo
501+
echo '{"key_id": "x", "issuer_id": "x", "private_key": "x"}' > $INVALID_BUILD_URL
502+
503+
BITRISE_BUILD_URL="file://$INVALID_BUILD_URL"
504+
BITRISE_BUILD_API_TOKEN="x"
505+
506+
export BITRISE_BUILD_API_TOKEN
507+
export BITRISE_BUILD_API_TOKEN
508+
envman add --key BITRISE_BUILD_URL --value $BITRISE_BUILD_URL
509+
envman add --key BITRISE_BUILD_API_TOKEN --value $BITRISE_BUILD_API_TOKEN

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/bitrise-io/go-utils v1.0.1
88
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.2
99
github.com/bitrise-io/go-xcode v1.0.6
10-
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.13
10+
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.14
1111
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
1212
github.com/stretchr/testify v1.7.0
1313
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b

go.sum

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ github.com/bitrise-io/go-utils v1.0.1/go.mod h1:ZY1DI+fEpZuFpO9szgDeICM4QbqoWVt0
99
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.1/go.mod h1:sy+Ir1X8P3tAAx/qU/r+hqDjHDcrMjIzDEvId1wqNc4=
1010
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.2 h1:w3fwgLLmxMOpYNa6W5aLtJZE8M8+qGE5VPOcr+st59c=
1111
github.com/bitrise-io/go-utils/v2 v2.0.0-alpha.2/go.mod h1:sy+Ir1X8P3tAAx/qU/r+hqDjHDcrMjIzDEvId1wqNc4=
12-
github.com/bitrise-io/go-xcode v1.0.1/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY=
13-
github.com/bitrise-io/go-xcode v1.0.5 h1:T0I1ED5oDifbO57VSNxhLh+8T9vcdGt+5U/kOrzFKeQ=
14-
github.com/bitrise-io/go-xcode v1.0.5/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY=
1512
github.com/bitrise-io/go-xcode v1.0.6 h1:hSKwkDXUn9/gMk6HiJRUvurGWelfQEBWcO7JAvXi+y8=
1613
github.com/bitrise-io/go-xcode v1.0.6/go.mod h1:Y0Wu2dXm0MilJ/4D3+gPHaNMlUcP+1DjIPoLPykq7wY=
17-
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.11 h1:g2e1BcYQaF/vJatXQ/IbTWJuEdGVTrnz8dADtSawsdU=
18-
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.11/go.mod h1:6YbvyYwZgSTt96CQSQ6QlrkcRiv3ssX8zLijh2TPnbU=
19-
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.13 h1:IxlmYKYrKF2/LsjtKWNjTCyh+no6/fPZJiWK1Jo6ZME=
20-
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.13/go.mod h1:IhG2l/bM8+809Jlwt4hgRzOkRfPmhEybfWMOJdEGnEU=
14+
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.14 h1:Tfo5QuCZmb/BTC8QWEhPxuP02FzjnjEE19jTzQFag2o=
15+
github.com/bitrise-io/go-xcode/v2 v2.0.0-alpha.14/go.mod h1:IhG2l/bM8+809Jlwt4hgRzOkRfPmhEybfWMOJdEGnEU=
2116
github.com/bitrise-io/pkcs12 v0.0.0-20211108084543-e52728e011c8 h1:kmvU8AxrNTxXsVPKepBHD8W+eCVmeaKyTkRuUJB2K38=
2217
github.com/bitrise-io/pkcs12 v0.0.0-20211108084543-e52728e011c8/go.mod h1:UiXKNs0essbC14a2TvGlnUKo9isP9m4guPrp8KJHJpU=
2318
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

main.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/bitrise-io/go-xcode/v2/autocodesign/codesignasset"
3434
"github.com/bitrise-io/go-xcode/v2/autocodesign/devportalclient"
3535
"github.com/bitrise-io/go-xcode/v2/autocodesign/localcodesignasset"
36+
"github.com/bitrise-io/go-xcode/v2/autocodesign/profiledownloader"
3637
"github.com/bitrise-io/go-xcode/v2/autocodesign/projectmanager"
3738
"github.com/bitrise-io/go-xcode/v2/codesign"
3839
"github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator"
@@ -97,15 +98,16 @@ type Inputs struct {
9798

9899
CacheLevel string `env:"cache_level,opt[none,swift_packages]"`
99100

100-
CodeSigningAuthSource string `env:"automatic_code_signing,opt[off,api-key,apple-id]"`
101-
CertificateURLList string `env:"certificate_url_list"`
102-
CertificatePassphraseList stepconf.Secret `env:"passphrase_list"`
103-
KeychainPath string `env:"keychain_path"`
104-
KeychainPassword stepconf.Secret `env:"keychain_password"`
105-
RegisterTestDevices bool `env:"register_test_devices,opt[yes,no]"`
106-
MinDaysProfileValid int `env:"min_profile_validity,required"`
107-
BuildURL string `env:"BITRISE_BUILD_URL"`
108-
BuildAPIToken stepconf.Secret `env:"BITRISE_BUILD_API_TOKEN"`
101+
CodeSigningAuthSource string `env:"automatic_code_signing,opt[off,api-key,apple-id]"`
102+
CertificateURLList string `env:"certificate_url_list"`
103+
CertificatePassphraseList stepconf.Secret `env:"passphrase_list"`
104+
KeychainPath string `env:"keychain_path"`
105+
KeychainPassword stepconf.Secret `env:"keychain_password"`
106+
RegisterTestDevices bool `env:"register_test_devices,opt[yes,no]"`
107+
MinDaysProfileValid int `env:"min_profile_validity,required"`
108+
FallbackProvisioningProfileURLs string `env:"fallback_provisioning_profile_url_list"`
109+
BuildURL string `env:"BITRISE_BUILD_URL"`
110+
BuildAPIToken stepconf.Secret `env:"BITRISE_BUILD_API_TOKEN"`
109111
}
110112

111113
// Config ...
@@ -314,12 +316,13 @@ func (s XcodeArchiveStep) createCodesignManager(config Config) (codesign.Manager
314316
}
315317

316318
codesignInputs := codesign.Input{
317-
AuthType: authType,
318-
DistributionMethod: config.ExportMethod,
319-
CertificateURLList: config.CertificateURLList,
320-
CertificatePassphraseList: config.CertificatePassphraseList,
321-
KeychainPath: config.KeychainPath,
322-
KeychainPassword: config.KeychainPassword,
319+
AuthType: authType,
320+
DistributionMethod: config.ExportMethod,
321+
CertificateURLList: config.CertificateURLList,
322+
CertificatePassphraseList: config.CertificatePassphraseList,
323+
KeychainPath: config.KeychainPath,
324+
KeychainPassword: config.KeychainPassword,
325+
FallbackProvisioningProfiles: config.FallbackProvisioningProfileURLs,
323326
}
324327

325328
codesignConfig, err := codesign.ParseConfig(codesignInputs, cmdFactory)
@@ -361,12 +364,14 @@ func (s XcodeArchiveStep) createCodesignManager(config Config) (codesign.Manager
361364
return codesign.Manager{}, err
362365
}
363366

367+
client := retry.NewHTTPClient().StandardClient()
364368
return codesign.NewManagerWithProject(
365369
opts,
366370
appleAuthCredentials,
367371
serviceConnection,
368372
devPortalClientFactory,
369-
certdownloader.NewDownloader(codesignConfig.CertificatesAndPassphrases, retry.NewHTTPClient().StandardClient()),
373+
certdownloader.NewDownloader(codesignConfig.CertificatesAndPassphrases, client),
374+
profiledownloader.New(codesignConfig.FallbackProvisioningProfiles, client),
370375
codesignasset.NewWriter(codesignConfig.Keychain),
371376
localcodesignasset.NewManager(localcodesignasset.NewProvisioningProfileProvider(), localcodesignasset.NewProvisioningProfileConverter()),
372377
project,

step.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,22 @@ inputs:
263263
is_sensitive: true
264264
is_dont_change_value: true
265265

266+
- fallback_provisioning_profile_url_list:
267+
opts:
268+
category: Automatic code signing
269+
title: Fallback provisioning profile URLs
270+
description: |
271+
If set, provided provisioning profiles will be used on Automatic code signing error.
272+
273+
URL of the provisioning profile to download. Multiple URLs can be specified, separated by a newline or pipe (`|`) character.
274+
275+
You can specify a local path as well, using the `file://` scheme.
276+
For example: `file://./BuildAnything.mobileprovision`.
277+
278+
Can also provide a local directory that contains files with `.mobileprovision` extension.
279+
For example: `./profilesDirectory/`
280+
is_sensitive: true
281+
266282
# IPA export configuration
267283

268284
- export_development_team:
@@ -407,7 +423,6 @@ outputs:
407423
opts:
408424
title: .xcarchive.zip path
409425
summary: The created .xcarchive.zip file's path.
410-
411426
- BITRISE_XCODEBUILD_ARCHIVE_LOG_PATH:
412427
opts:
413428
title: "`xcodebuild archive` command log file path"

vendor/github.com/bitrise-io/go-xcode/v2/autocodesign/autocodesign.go

Lines changed: 26 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/bitrise-io/go-xcode/v2/autocodesign/certificates.go

Lines changed: 8 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)