Skip to content

Conversation

@godrei
Copy link
Contributor

@godrei godrei commented Aug 5, 2025

This PR fixes a bug with the fallback manual code signing mechanism of the automatic code signing logic.

After the automatic code signing logic gathers all the project required code signing files, it updates the project settings to use that signing files for the project archive. When automatic code signing fails, the step can fall back to installing manually provided signing files, but in this case the step was not updating the project settings, which led to failing project archive processes:

~/project_name.xcodeproj: error: No profile for team 'team_id' matching 'profile_name' found: Xcode couldn't find any provisioning profiles matching 'team_id/profile_name'. Install the profile (by dragging and dropping it onto Xcode's dock item) or select a different one in the Signing & Capabilities tab of the target editor. (in target 'target_name' from project 'project_name')

Here is an example build, which reproduces the bug: https://app.bitrise.io/build/25a26f21-a721-414e-a070-c4e032602e42
and here is a build with the fix: https://app.bitrise.io/build/8edd6044-0488-4b8a-984c-e21b55efd44a

PR for integrating this fix to the xcode-archive step: bitrise-steplib/steps-xcode-archive#385

@bitrise-ip-bot
Copy link
Contributor

bitrise-ip-bot commented Aug 12, 2025

Summary

This PR fixes fallback manual code signing mechanism by updating project settings when automatic code signing fails. The changes refactor code signing logic, improve error handling, and add proper project configuration updates for manual signing fallback scenarios.

Walkthrough

File Summary
autocodesign/projectmanager/projectmanager.go Fixed format string specifier from %s to %d
codesign/codesign.go Enhanced fallback logic and error handling
codesign/codesign_test.go Updated test mocks and assertions
exportoptionsgenerator/*.go Refactored code signing group provider logic

Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 5

Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 1

Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 1

@godrei godrei marked this pull request as ready for review August 14, 2025 11:45
for _, cert := range certificates {
m.logger.Printf("- %s", cert.String())
// Empty passphrase provided, as already parsed certificate + private key
if err := m.assetInstaller.InstallCertificate(cert); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is installCertificates already called in line 536. Seems duplicate.

Copy link
Contributor Author

@godrei godrei Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch removed the latter, it was a leftover, I switched to manually installing each cert for having more control over the logs and make it similar to the profile installation logs.
Updated the code here: 314d8f0

wantErr: "failed to determine codesign group for development distribution: no signing assets found",
},
{
name: "Project entitlements are not filtering the profiles",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is needed that project entitlements not filter the profiles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh it seems we filter based on entitlements, but the filter only works with the known entitlements, whil in the test I used fake entitlements.

Hare we create a map of bundle ids and entitlements:

bundleIDEntitlementsMap := map[string]plistutil.PlistData{}
for bundleID, entitlements := range appLayout.EntitlementsByArchivableTargetBundleID {
bundleIDEntitlementsMap[bundleID] = plistutil.PlistData(entitlements)
}

Here we pass the map to the codesign group creator function:

signingAssets, err := provider.DetermineCodesignGroup(certificates, profiles, nil, bundleIDEntitlementsMap, exportoptions.Method(distributionType), m.opts.TeamID, true)

Which does the entitlements filtering here:

codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlementsMap))

And the entitlement filter only works with the known entitlements.

I will update the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated here: 14fff2c


assetsByDistributionType := map[autocodesign.DistributionType]autocodesign.AppCodesignAssets{}
for _, distributionType := range distributionTypes {
signingAssets, err := provider.DetermineCodesignGroup(certificates, profiles, nil, bundleIDEntitlementsMap, exportoptions.Method(distributionType), m.opts.TeamID, true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an observation: we pass xcodeManage = true, this allows use of Xcode managed profiles (good).
We also do not set a default (Bitrise provided) profile, which should be ok (if automatic code signing is already set up, it makes no sense). (also good)

Copy link
Contributor

@lpusok lpusok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok overall.

@godrei godrei requested a review from lpusok August 15, 2025 08:33
Copy link
Contributor

@bitrise-ip-bot bitrise-ip-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an AI-generated review. Please review it carefully.

Actionable comments posted: 2

@godrei godrei merged commit bd31090 into master Aug 15, 2025
3 checks passed
@godrei godrei deleted the fallback-profiles-fix branch August 15, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants