From 973a8eb6f35c337551d71be1c321e4ff825ad3c9 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Wed, 21 Jan 2026 18:05:01 +0100 Subject: [PATCH 1/9] Moved export package as-is --- .../codesign_group_provider.go | 2 +- .../export/codesing_group.go | 13 + exportoptionsgenerator/export/export.go | 125 +++++++ exportoptionsgenerator/export/filter.go | 203 +++++++++++ exportoptionsgenerator/export/ios.go | 321 ++++++++++++++++++ exportoptionsgenerator/export/mac.go | 73 ++++ .../exportoptionsgenerator.go | 2 +- 7 files changed, 737 insertions(+), 2 deletions(-) create mode 100644 exportoptionsgenerator/export/codesing_group.go create mode 100644 exportoptionsgenerator/export/export.go create mode 100644 exportoptionsgenerator/export/filter.go create mode 100644 exportoptionsgenerator/export/ios.go create mode 100644 exportoptionsgenerator/export/mac.go diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 60f95086..2ee2ad0b 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -3,9 +3,9 @@ package exportoptionsgenerator import ( "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/certificateutil" - "github.com/bitrise-io/go-xcode/export" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" "github.com/bitrise-io/go-xcode/v2/plistutil" ) diff --git a/exportoptionsgenerator/export/codesing_group.go b/exportoptionsgenerator/export/codesing_group.go new file mode 100644 index 00000000..50316fb5 --- /dev/null +++ b/exportoptionsgenerator/export/codesing_group.go @@ -0,0 +1,13 @@ +package export + +import ( + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/profileutil" +) + +// CodeSignGroup ... +type CodeSignGroup interface { + Certificate() certificateutil.CertificateInfoModel + InstallerCertificate() *certificateutil.CertificateInfoModel + BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel +} diff --git a/exportoptionsgenerator/export/export.go b/exportoptionsgenerator/export/export.go new file mode 100644 index 00000000..d62d86c6 --- /dev/null +++ b/exportoptionsgenerator/export/export.go @@ -0,0 +1,125 @@ +package export + +import ( + "encoding/json" + "fmt" + "sort" + + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/profileutil" + "github.com/ryanuber/go-glob" +) + +// SelectableCodeSignGroup ... +type SelectableCodeSignGroup struct { + Certificate certificateutil.CertificateInfoModel + BundleIDProfilesMap map[string][]profileutil.ProvisioningProfileInfoModel +} + +// String ... +func (group SelectableCodeSignGroup) String() string { + printable := map[string]interface{}{} + printable["team"] = fmt.Sprintf("%s (%s)", group.Certificate.TeamName, group.Certificate.TeamID) + printable["certificate"] = fmt.Sprintf("%s (%s)", group.Certificate.CommonName, group.Certificate.Serial) + + bundleIDProfiles := map[string][]string{} + for bundleID, profileInfos := range group.BundleIDProfilesMap { + printableProfiles := []string{} + for _, profileInfo := range profileInfos { + printableProfiles = append(printableProfiles, fmt.Sprintf("%s (%s)", profileInfo.Name, profileInfo.UUID)) + } + bundleIDProfiles[bundleID] = printableProfiles + } + printable["bundle_id_profiles"] = bundleIDProfiles + + data, err := json.MarshalIndent(printable, "", "\t") + if err != nil { + log.Errorf("Failed to marshal: %v, error: %s", printable, err) + return "" + } + + return string(data) +} + +func isCertificateInstalled(installedCertificates []certificateutil.CertificateInfoModel, certificate certificateutil.CertificateInfoModel) bool { + for _, cert := range installedCertificates { + if cert.Serial == certificate.Serial { + return true + } + } + return false +} + +// CreateSelectableCodeSignGroups ... +func CreateSelectableCodeSignGroups(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { + groups := []SelectableCodeSignGroup{} + + serialProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + serialCertificateMap := map[string]certificateutil.CertificateInfoModel{} + for _, profile := range profiles { + for _, certificate := range profile.DeveloperCertificates { + if !isCertificateInstalled(certificates, certificate) { + continue + } + + certificateProfiles, ok := serialProfilesMap[certificate.Serial] + if !ok { + certificateProfiles = []profileutil.ProvisioningProfileInfoModel{} + } + certificateProfiles = append(certificateProfiles, profile) + serialProfilesMap[certificate.Serial] = certificateProfiles + serialCertificateMap[certificate.Serial] = certificate + } + } + + for serial, profiles := range serialProfilesMap { + certificate := serialCertificateMap[serial] + + bundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + for _, bundleID := range bundleIDs { + + matchingProfiles := []profileutil.ProvisioningProfileInfoModel{} + for _, profile := range profiles { + if !glob.Glob(profile.BundleID, bundleID) { + continue + } + + matchingProfiles = append(matchingProfiles, profile) + } + + if len(matchingProfiles) > 0 { + sort.Sort(ByBundleIDLength(matchingProfiles)) + bundleIDProfilesMap[bundleID] = matchingProfiles + } + } + + if len(bundleIDProfilesMap) == len(bundleIDs) { + group := SelectableCodeSignGroup{ + Certificate: certificate, + BundleIDProfilesMap: bundleIDProfilesMap, + } + groups = append(groups, group) + } + } + + return groups +} + +// ByBundleIDLength ... +type ByBundleIDLength []profileutil.ProvisioningProfileInfoModel + +// Len .. +func (s ByBundleIDLength) Len() int { + return len(s) +} + +// Swap ... +func (s ByBundleIDLength) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +// Less ... +func (s ByBundleIDLength) Less(i, j int) bool { + return len(s[i].BundleID) > len(s[j].BundleID) +} diff --git a/exportoptionsgenerator/export/filter.go b/exportoptionsgenerator/export/filter.go new file mode 100644 index 00000000..a85302ef --- /dev/null +++ b/exportoptionsgenerator/export/filter.go @@ -0,0 +1,203 @@ +package export + +import ( + "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-xcode/exportoptions" + "github.com/bitrise-io/go-xcode/plistutil" + "github.com/bitrise-io/go-xcode/profileutil" +) + +// SelectableCodeSignGroupFilter ... +type SelectableCodeSignGroupFilter func(group *SelectableCodeSignGroup) bool + +// FilterSelectableCodeSignGroups ... +func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFuncs ...SelectableCodeSignGroupFilter) []SelectableCodeSignGroup { + filteredGroups := []SelectableCodeSignGroup{} + + for _, group := range groups { + allowed := true + + for _, filterFunc := range filterFuncs { + if !filterFunc(&group) { + allowed = false + break + } + } + + if allowed { + filteredGroups = append(filteredGroups, group) + } + } + + return filteredGroups +} + +// CreateEntitlementsSelectableCodeSignGroupFilter ... +func CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlementsMap map[string]plistutil.PlistData) SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Entitlements filter - removes profile if has missing capabilities") + + filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + + for bundleID, profiles := range group.BundleIDProfilesMap { + filteredProfiles := []profileutil.ProvisioningProfileInfoModel{} + + for _, profile := range profiles { + missingEntitlements := profileutil.MatchTargetAndProfileEntitlements(bundleIDEntitlementsMap[bundleID], profile.Entitlements, profile.Type) + if len(missingEntitlements) == 0 { + filteredProfiles = append(filteredProfiles, profile) + } + } + + if len(filteredProfiles) == 0 { + break + } + + filteredBundleIDProfilesMap[bundleID] = filteredProfiles + } + + if len(filteredBundleIDProfilesMap) == len(group.BundleIDProfilesMap) { + group.BundleIDProfilesMap = filteredBundleIDProfilesMap + return true + } + + return false + } +} + +// CreateExportMethodSelectableCodeSignGroupFilter ... +func CreateExportMethodSelectableCodeSignGroupFilter(exportMethod exportoptions.Method) SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Export method filter - removes profile if distribution type is not: %s", exportMethod) + + filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + + for bundleID, profiles := range group.BundleIDProfilesMap { + filteredProfiles := []profileutil.ProvisioningProfileInfoModel{} + + for _, profile := range profiles { + if profile.ExportType == exportMethod { + filteredProfiles = append(filteredProfiles, profile) + } + } + + if len(filteredProfiles) == 0 { + break + } + + filteredBundleIDProfilesMap[bundleID] = filteredProfiles + } + + if len(filteredBundleIDProfilesMap) == len(group.BundleIDProfilesMap) { + group.BundleIDProfilesMap = filteredBundleIDProfilesMap + return true + } + + return false + } +} + +// CreateTeamSelectableCodeSignGroupFilter ... +func CreateTeamSelectableCodeSignGroupFilter(teamID string) SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Development Team filter - restrict group if team is not: %s", teamID) + + return group.Certificate.TeamID == teamID + } +} + +// CreateNotXcodeManagedSelectableCodeSignGroupFilter ... +func CreateNotXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Xcode managed filter - removes profile if xcode managed") + + filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + + for bundleID, profiles := range group.BundleIDProfilesMap { + filteredProfiles := []profileutil.ProvisioningProfileInfoModel{} + + for _, profile := range profiles { + if !profile.IsXcodeManaged() { + filteredProfiles = append(filteredProfiles, profile) + } + } + + if len(filteredProfiles) == 0 { + break + } + + filteredBundleIDProfilesMap[bundleID] = filteredProfiles + } + + if len(filteredBundleIDProfilesMap) == len(group.BundleIDProfilesMap) { + group.BundleIDProfilesMap = filteredBundleIDProfilesMap + return true + } + + return false + } +} + +// CreateXcodeManagedSelectableCodeSignGroupFilter ... +func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Xcode managed filter - removes profile if not xcode managed") + + filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + + for bundleID, profiles := range group.BundleIDProfilesMap { + filteredProfiles := []profileutil.ProvisioningProfileInfoModel{} + + for _, profile := range profiles { + if profile.IsXcodeManaged() { + filteredProfiles = append(filteredProfiles, profile) + } + } + + if len(filteredProfiles) == 0 { + break + } + + filteredBundleIDProfilesMap[bundleID] = filteredProfiles + } + + if len(filteredBundleIDProfilesMap) == len(group.BundleIDProfilesMap) { + group.BundleIDProfilesMap = filteredBundleIDProfilesMap + return true + } + + return false + } +} + +// CreateExcludeProfileNameSelectableCodeSignGroupFilter ... +func CreateExcludeProfileNameSelectableCodeSignGroupFilter(name string) SelectableCodeSignGroupFilter { + return func(group *SelectableCodeSignGroup) bool { + log.Debugf("Profile name filter - removes profile with name: %s", name) + + filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + + for bundleID, profiles := range group.BundleIDProfilesMap { + filteredProfiles := []profileutil.ProvisioningProfileInfoModel{} + + for _, profile := range profiles { + if profile.Name != name { + filteredProfiles = append(filteredProfiles, profile) + } + } + + if len(filteredProfiles) == 0 { + break + } + + filteredBundleIDProfilesMap[bundleID] = filteredProfiles + } + + if len(filteredBundleIDProfilesMap) == len(group.BundleIDProfilesMap) { + group.BundleIDProfilesMap = filteredBundleIDProfilesMap + return true + } + + return false + } +} diff --git a/exportoptionsgenerator/export/ios.go b/exportoptionsgenerator/export/ios.go new file mode 100644 index 00000000..a9d3a43c --- /dev/null +++ b/exportoptionsgenerator/export/ios.go @@ -0,0 +1,321 @@ +package export + +import ( + "sort" + + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/profileutil" + glob "github.com/ryanuber/go-glob" +) + +// IosCodeSignGroup ... +type IosCodeSignGroup struct { + certificate certificateutil.CertificateInfoModel + bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel +} + +// Certificate ... +func (signGroup *IosCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { + return signGroup.certificate +} + +// InstallerCertificate ... +func (signGroup *IosCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { + return nil +} + +// BundleIDProfileMap ... +func (signGroup *IosCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { + return signGroup.bundleIDProfileMap +} + +// NewIOSGroup ... +func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *IosCodeSignGroup { + return &IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, + } +} + +func createSingleWildcardGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { + groups := []IosCodeSignGroup{} + + certificate := group.Certificate + bundleIDProfilesMap := group.BundleIDProfilesMap + + bundleIDs := []string{} + profiles := []profileutil.ProvisioningProfileInfoModel{} + for bundleID, matchingProfiles := range bundleIDProfilesMap { + bundleIDs = append(bundleIDs, bundleID) + profiles = append(profiles, matchingProfiles...) + } + + for _, profile := range profiles { + if alreadyUsedProfileUUIDMap[profile.UUID] { + continue + } + + matchesForAllBundleID := true + for _, bundleID := range bundleIDs { + if !glob.Glob(profile.BundleID, bundleID) { + matchesForAllBundleID = false + break + } + } + if matchesForAllBundleID { + bundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} + for _, bundleID := range bundleIDs { + bundleIDProfileMap[bundleID] = profile + } + + group := IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, + } + groups = append(groups, group) + + alreadyUsedProfileUUIDMap[profile.UUID] = true + } + } + return groups +} + +func createXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { + groups := []IosCodeSignGroup{} + + certificate := group.Certificate + bundleIDProfilesMap := group.BundleIDProfilesMap + + bundleIDs := []string{} + profiles := []profileutil.ProvisioningProfileInfoModel{} + for bundleID, matchingProfiles := range bundleIDProfilesMap { + bundleIDs = append(bundleIDs, bundleID) + profiles = append(profiles, matchingProfiles...) + } + + // collect xcode managed profiles + xcodeManagedProfiles := []profileutil.ProvisioningProfileInfoModel{} + for _, profile := range profiles { + if !alreadyUsedProfileUUIDMap[profile.UUID] && profile.IsXcodeManaged() { + xcodeManagedProfiles = append(xcodeManagedProfiles, profile) + } + } + sort.Sort(ByBundleIDLength(xcodeManagedProfiles)) + + // map profiles to bundle ids + remove the already used profiles + bundleIDMannagedProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + for _, bundleID := range bundleIDs { + for _, profile := range xcodeManagedProfiles { + if !glob.Glob(profile.BundleID, bundleID) { + continue + } + + matchingProfiles := bundleIDMannagedProfilesMap[bundleID] + if matchingProfiles == nil { + matchingProfiles = []profileutil.ProvisioningProfileInfoModel{} + } + matchingProfiles = append(matchingProfiles, profile) + bundleIDMannagedProfilesMap[bundleID] = matchingProfiles + } + } + + if len(bundleIDMannagedProfilesMap) == len(bundleIDs) { + // if only one profile can sign a bundle id, remove it from bundleIDMannagedProfilesMap + alreadyUsedManagedProfileMap := map[string]bool{} + for _, profiles := range bundleIDMannagedProfilesMap { + if len(profiles) == 1 { + profile := profiles[0] + alreadyUsedManagedProfileMap[profile.UUID] = true + } + } + + bundleIDMannagedProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} + for bundleID, profiles := range bundleIDMannagedProfilesMap { + if len(profiles) == 1 { + bundleIDMannagedProfileMap[bundleID] = profiles[0] + } else { + remainingProfiles := []profileutil.ProvisioningProfileInfoModel{} + for _, profile := range profiles { + if !alreadyUsedManagedProfileMap[profile.UUID] { + remainingProfiles = append(remainingProfiles, profile) + } + } + if len(remainingProfiles) == 1 { + bundleIDMannagedProfileMap[bundleID] = remainingProfiles[0] + } + } + } + + // create code sign group + if len(bundleIDMannagedProfileMap) == len(bundleIDs) { + for _, profile := range bundleIDMannagedProfileMap { + alreadyUsedProfileUUIDMap[profile.UUID] = true + } + + group := IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDMannagedProfileMap, + } + groups = append(groups, group) + } + } + + return groups +} + +func createNotXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { + groups := []IosCodeSignGroup{} + + certificate := group.Certificate + bundleIDProfilesMap := group.BundleIDProfilesMap + + bundleIDs := []string{} + profiles := []profileutil.ProvisioningProfileInfoModel{} + for bundleID, matchingProfiles := range bundleIDProfilesMap { + bundleIDs = append(bundleIDs, bundleID) + profiles = append(profiles, matchingProfiles...) + } + + // collect xcode managed profiles + notXcodeManagedProfiles := []profileutil.ProvisioningProfileInfoModel{} + for _, profile := range profiles { + if !alreadyUsedProfileUUIDMap[profile.UUID] && !profile.IsXcodeManaged() { + notXcodeManagedProfiles = append(notXcodeManagedProfiles, profile) + } + } + sort.Sort(ByBundleIDLength(notXcodeManagedProfiles)) + + // map profiles to bundle ids + remove the already used profiles + bundleIDNotMannagedProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + for _, bundleID := range bundleIDs { + for _, profile := range notXcodeManagedProfiles { + if !glob.Glob(profile.BundleID, bundleID) { + continue + } + + matchingProfiles := bundleIDNotMannagedProfilesMap[bundleID] + if matchingProfiles == nil { + matchingProfiles = []profileutil.ProvisioningProfileInfoModel{} + } + matchingProfiles = append(matchingProfiles, profile) + bundleIDNotMannagedProfilesMap[bundleID] = matchingProfiles + } + } + + if len(bundleIDNotMannagedProfilesMap) == len(bundleIDs) { + // if only one profile can sign a bundle id, remove it from bundleIDNotMannagedProfilesMap + alreadyUsedNotManagedProfileMap := map[string]bool{} + for _, profiles := range bundleIDNotMannagedProfilesMap { + if len(profiles) == 1 { + profile := profiles[0] + alreadyUsedNotManagedProfileMap[profile.UUID] = true + } + } + + bundleIDNotMannagedProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} + for bundleID, profiles := range bundleIDNotMannagedProfilesMap { + if len(profiles) == 1 { + bundleIDNotMannagedProfileMap[bundleID] = profiles[0] + } else { + remainingProfiles := []profileutil.ProvisioningProfileInfoModel{} + for _, profile := range profiles { + if !alreadyUsedNotManagedProfileMap[profile.UUID] { + remainingProfiles = append(remainingProfiles, profile) + } + } + if len(remainingProfiles) == 1 { + bundleIDNotMannagedProfileMap[bundleID] = remainingProfiles[0] + } + } + } + + // create code sign group + if len(bundleIDNotMannagedProfileMap) == len(bundleIDs) { + for _, profile := range bundleIDNotMannagedProfileMap { + alreadyUsedProfileUUIDMap[profile.UUID] = true + } + + codeSignGroup := IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDNotMannagedProfileMap, + } + groups = append(groups, codeSignGroup) + } + } + + return groups +} + +func createRemainingGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { + groups := []IosCodeSignGroup{} + + certificate := group.Certificate + bundleIDProfilesMap := group.BundleIDProfilesMap + + bundleIDs := []string{} + profiles := []profileutil.ProvisioningProfileInfoModel{} + for bundleID, matchingProfiles := range bundleIDProfilesMap { + bundleIDs = append(bundleIDs, bundleID) + profiles = append(profiles, matchingProfiles...) + } + + if len(alreadyUsedProfileUUIDMap) != len(profiles) { + bundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} + for _, bundleID := range bundleIDs { + for _, profile := range profiles { + if alreadyUsedProfileUUIDMap[profile.UUID] { + continue + } + + if !glob.Glob(profile.BundleID, bundleID) { + continue + } + + bundleIDProfileMap[bundleID] = profile + break + } + } + + if len(bundleIDProfileMap) == len(bundleIDs) { + group := IosCodeSignGroup{ + certificate: certificate, + bundleIDProfileMap: bundleIDProfileMap, + } + groups = append(groups, group) + } + } + + return groups +} + +// CreateIosCodeSignGroups ... +func CreateIosCodeSignGroups(selectableGroups []SelectableCodeSignGroup) []IosCodeSignGroup { + alreadyUsedProfileUUIDMap := map[string]bool{} + + singleWildcardGroups := []IosCodeSignGroup{} + xcodeManagedGroups := []IosCodeSignGroup{} + notXcodeManagedGroups := []IosCodeSignGroup{} + remainingGroups := []IosCodeSignGroup{} + + for _, selectableGroup := range selectableGroups { + // create groups with single wildcard profiles + singleWildcardGroups = append(singleWildcardGroups, createSingleWildcardGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) + + // create groups with xcode managed profiles + xcodeManagedGroups = append(xcodeManagedGroups, createXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) + + // create groups with NOT xcode managed profiles + notXcodeManagedGroups = append(notXcodeManagedGroups, createNotXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) + + // if there are remaining profiles we create a not exact group by using the first matching profile for every bundle id + remainingGroups = append(remainingGroups, createRemainingGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) + } + + codeSignGroups := []IosCodeSignGroup{} + codeSignGroups = append(codeSignGroups, notXcodeManagedGroups...) + codeSignGroups = append(codeSignGroups, xcodeManagedGroups...) + codeSignGroups = append(codeSignGroups, singleWildcardGroups...) + codeSignGroups = append(codeSignGroups, remainingGroups...) + + return codeSignGroups +} diff --git a/exportoptionsgenerator/export/mac.go b/exportoptionsgenerator/export/mac.go new file mode 100644 index 00000000..e3fcd42d --- /dev/null +++ b/exportoptionsgenerator/export/mac.go @@ -0,0 +1,73 @@ +package export + +import ( + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/exportoptions" + "github.com/bitrise-io/go-xcode/profileutil" +) + +// MacCodeSignGroup ... +type MacCodeSignGroup struct { + certificate certificateutil.CertificateInfoModel + installerCertificate *certificateutil.CertificateInfoModel + bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel +} + +// Certificate ... +func (signGroup *MacCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { + return signGroup.certificate +} + +// InstallerCertificate ... +func (signGroup *MacCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { + return signGroup.installerCertificate +} + +// BundleIDProfileMap ... +func (signGroup *MacCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { + return signGroup.bundleIDProfileMap +} + +// NewMacGroup ... +func NewMacGroup(certificate certificateutil.CertificateInfoModel, installerCertificate *certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *MacCodeSignGroup { + return &MacCodeSignGroup{ + certificate: certificate, + installerCertificate: installerCertificate, + bundleIDProfileMap: bundleIDProfileMap, + } +} + +// CreateMacCodeSignGroup ... +func CreateMacCodeSignGroup(selectableGroups []SelectableCodeSignGroup, installedInstallerCertificates []certificateutil.CertificateInfoModel, exportMethod exportoptions.Method) []MacCodeSignGroup { + macosCodeSignGroups := []MacCodeSignGroup{} + + iosCodesignGroups := CreateIosCodeSignGroups(selectableGroups) + + for _, group := range iosCodesignGroups { + if exportMethod.IsAppStore() { + installerCertificates := []certificateutil.CertificateInfoModel{} + + for _, installerCertificate := range installedInstallerCertificates { + if installerCertificate.TeamID == group.certificate.TeamID { + installerCertificates = append(installerCertificates, installerCertificate) + } + } + + if len(installerCertificates) > 0 { + installerCertificate := installerCertificates[0] + macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ + certificate: group.certificate, + installerCertificate: &installerCertificate, + bundleIDProfileMap: group.bundleIDProfileMap, + }) + } + } else { + macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ + certificate: group.certificate, + bundleIDProfileMap: group.bundleIDProfileMap, + }) + } + } + + return macosCodeSignGroups +} diff --git a/exportoptionsgenerator/exportoptionsgenerator.go b/exportoptionsgenerator/exportoptionsgenerator.go index 61c8a533..13a3c34b 100644 --- a/exportoptionsgenerator/exportoptionsgenerator.go +++ b/exportoptionsgenerator/exportoptionsgenerator.go @@ -5,9 +5,9 @@ import ( "github.com/bitrise-io/go-utils/sliceutil" "github.com/bitrise-io/go-utils/v2/log" - "github.com/bitrise-io/go-xcode/export" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" "github.com/bitrise-io/go-xcode/v2/plistutil" "github.com/bitrise-io/go-xcode/v2/xcodeversion" ) From 48ce7ce16fbc854990de110d5132e47ea095da72 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Thu, 29 Jan 2026 10:55:25 +0100 Subject: [PATCH 2/9] removed dead code, added simple test, renamed map variable --- exportoptionsgenerator/export/export.go | 28 ++++---- exportoptionsgenerator/export/export_test.go | 62 +++++++++++++++++ exportoptionsgenerator/export/filter.go | 2 + exportoptionsgenerator/export/ios.go | 53 +++++++------- exportoptionsgenerator/export/mac.go | 73 -------------------- 5 files changed, 104 insertions(+), 114 deletions(-) create mode 100644 exportoptionsgenerator/export/export_test.go delete mode 100644 exportoptionsgenerator/export/mac.go diff --git a/exportoptionsgenerator/export/export.go b/exportoptionsgenerator/export/export.go index d62d86c6..199885c0 100644 --- a/exportoptionsgenerator/export/export.go +++ b/exportoptionsgenerator/export/export.go @@ -42,7 +42,7 @@ func (group SelectableCodeSignGroup) String() string { return string(data) } -func isCertificateInstalled(installedCertificates []certificateutil.CertificateInfoModel, certificate certificateutil.CertificateInfoModel) bool { +func containsCertificate(installedCertificates []certificateutil.CertificateInfoModel, certificate certificateutil.CertificateInfoModel) bool { for _, cert := range installedCertificates { if cert.Serial == certificate.Serial { return true @@ -52,31 +52,31 @@ func isCertificateInstalled(installedCertificates []certificateutil.CertificateI } // CreateSelectableCodeSignGroups ... -func CreateSelectableCodeSignGroups(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { +func CreateSelectableCodeSignGroups(installedCertificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { groups := []SelectableCodeSignGroup{} - serialProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} - serialCertificateMap := map[string]certificateutil.CertificateInfoModel{} + serialToProfiles := map[string][]profileutil.ProvisioningProfileInfoModel{} + serialToCertificate := map[string]certificateutil.CertificateInfoModel{} for _, profile := range profiles { for _, certificate := range profile.DeveloperCertificates { - if !isCertificateInstalled(certificates, certificate) { + if !containsCertificate(installedCertificates, certificate) { continue } - certificateProfiles, ok := serialProfilesMap[certificate.Serial] + certificateProfiles, ok := serialToProfiles[certificate.Serial] if !ok { certificateProfiles = []profileutil.ProvisioningProfileInfoModel{} } certificateProfiles = append(certificateProfiles, profile) - serialProfilesMap[certificate.Serial] = certificateProfiles - serialCertificateMap[certificate.Serial] = certificate + serialToProfiles[certificate.Serial] = certificateProfiles + serialToCertificate[certificate.Serial] = certificate } } - for serial, profiles := range serialProfilesMap { - certificate := serialCertificateMap[serial] + for serial, profiles := range serialToProfiles { + certificate := serialToCertificate[serial] - bundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} + bundleIDToProfiles := map[string][]profileutil.ProvisioningProfileInfoModel{} for _, bundleID := range bundleIDs { matchingProfiles := []profileutil.ProvisioningProfileInfoModel{} @@ -90,14 +90,14 @@ func CreateSelectableCodeSignGroups(certificates []certificateutil.CertificateIn if len(matchingProfiles) > 0 { sort.Sort(ByBundleIDLength(matchingProfiles)) - bundleIDProfilesMap[bundleID] = matchingProfiles + bundleIDToProfiles[bundleID] = matchingProfiles } } - if len(bundleIDProfilesMap) == len(bundleIDs) { + if len(bundleIDToProfiles) == len(bundleIDs) { group := SelectableCodeSignGroup{ Certificate: certificate, - BundleIDProfilesMap: bundleIDProfilesMap, + BundleIDProfilesMap: bundleIDToProfiles, } groups = append(groups, group) } diff --git a/exportoptionsgenerator/export/export_test.go b/exportoptionsgenerator/export/export_test.go new file mode 100644 index 00000000..507918cd --- /dev/null +++ b/exportoptionsgenerator/export/export_test.go @@ -0,0 +1,62 @@ +package export_test + +import ( + "testing" + + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/exportoptions" + "github.com/bitrise-io/go-xcode/profileutil" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" + "github.com/stretchr/testify/require" +) + +func TestCreateSelectableCodeSignGroups(t *testing.T) { + certDev := certificateutil.CertificateInfoModel{ + CommonName: "iPhone Distribution: Bitrise Test (ABCD1234)", + TeamID: "ABCD1234", + } + profileDev := profileutil.ProvisioningProfileInfoModel{ + Name: "Bitrise Test Profile", + UUID: "PROFILE-UUID-1234", + TeamID: "ABCD1234", + BundleID: "io.bitrise.testapp", + ExportType: exportoptions.MethodAppStore, + DeveloperCertificates: []certificateutil.CertificateInfoModel{certDev}, + } + + tests := []struct { + name string + certificates []certificateutil.CertificateInfoModel + profiles []profileutil.ProvisioningProfileInfoModel + bundleIDs []string + want []export.SelectableCodeSignGroup + }{ + { + name: "empty inputs", + certificates: []certificateutil.CertificateInfoModel{}, + profiles: []profileutil.ProvisioningProfileInfoModel{}, + bundleIDs: []string{}, + want: []export.SelectableCodeSignGroup{}, + }, + { + name: "single matching profile and certificate", + certificates: []certificateutil.CertificateInfoModel{certDev}, + profiles: []profileutil.ProvisioningProfileInfoModel{profileDev}, + bundleIDs: []string{"io.bitrise.testapp"}, + want: []export.SelectableCodeSignGroup{ + { + Certificate: certDev, + BundleIDProfilesMap: map[string][]profileutil.ProvisioningProfileInfoModel{ + "io.bitrise.testapp": {profileDev}, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := export.CreateSelectableCodeSignGroups(tt.certificates, tt.profiles, tt.bundleIDs) + require.Equal(t, tt.want, got) + }) + } +} diff --git a/exportoptionsgenerator/export/filter.go b/exportoptionsgenerator/export/filter.go index a85302ef..deac64d6 100644 --- a/exportoptionsgenerator/export/filter.go +++ b/exportoptionsgenerator/export/filter.go @@ -138,6 +138,7 @@ func CreateNotXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGrou } } +/* // CreateXcodeManagedSelectableCodeSignGroupFilter ... func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { @@ -169,6 +170,7 @@ func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFi return false } } +*/ // CreateExcludeProfileNameSelectableCodeSignGroupFilter ... func CreateExcludeProfileNameSelectableCodeSignGroupFilter(name string) SelectableCodeSignGroupFilter { diff --git a/exportoptionsgenerator/export/ios.go b/exportoptionsgenerator/export/ios.go index a9d3a43c..754be5bf 100644 --- a/exportoptionsgenerator/export/ios.go +++ b/exportoptionsgenerator/export/ios.go @@ -1,11 +1,8 @@ package export import ( - "sort" - "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/profileutil" - glob "github.com/ryanuber/go-glob" ) // IosCodeSignGroup ... @@ -37,6 +34,7 @@ func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfi } } +/* func createSingleWildcardGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { groups := []IosCodeSignGroup{} @@ -288,34 +286,35 @@ func createRemainingGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUID return groups } -// CreateIosCodeSignGroups ... -func CreateIosCodeSignGroups(selectableGroups []SelectableCodeSignGroup) []IosCodeSignGroup { - alreadyUsedProfileUUIDMap := map[string]bool{} +// // CreateIosCodeSignGroups ... +// func CreateIosCodeSignGroups(selectableGroups []SelectableCodeSignGroup) []IosCodeSignGroup { +// alreadyUsedProfileUUIDMap := map[string]bool{} - singleWildcardGroups := []IosCodeSignGroup{} - xcodeManagedGroups := []IosCodeSignGroup{} - notXcodeManagedGroups := []IosCodeSignGroup{} - remainingGroups := []IosCodeSignGroup{} +// singleWildcardGroups := []IosCodeSignGroup{} +// xcodeManagedGroups := []IosCodeSignGroup{} +// notXcodeManagedGroups := []IosCodeSignGroup{} +// remainingGroups := []IosCodeSignGroup{} - for _, selectableGroup := range selectableGroups { - // create groups with single wildcard profiles - singleWildcardGroups = append(singleWildcardGroups, createSingleWildcardGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) +// for _, selectableGroup := range selectableGroups { +// // create groups with single wildcard profiles +// singleWildcardGroups = append(singleWildcardGroups, createSingleWildcardGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - // create groups with xcode managed profiles - xcodeManagedGroups = append(xcodeManagedGroups, createXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) +// // create groups with xcode managed profiles +// xcodeManagedGroups = append(xcodeManagedGroups, createXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - // create groups with NOT xcode managed profiles - notXcodeManagedGroups = append(notXcodeManagedGroups, createNotXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) +// // create groups with NOT xcode managed profiles +// notXcodeManagedGroups = append(notXcodeManagedGroups, createNotXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - // if there are remaining profiles we create a not exact group by using the first matching profile for every bundle id - remainingGroups = append(remainingGroups, createRemainingGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - } +// // if there are remaining profiles we create a not exact group by using the first matching profile for every bundle id +// remainingGroups = append(remainingGroups, createRemainingGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) +// } - codeSignGroups := []IosCodeSignGroup{} - codeSignGroups = append(codeSignGroups, notXcodeManagedGroups...) - codeSignGroups = append(codeSignGroups, xcodeManagedGroups...) - codeSignGroups = append(codeSignGroups, singleWildcardGroups...) - codeSignGroups = append(codeSignGroups, remainingGroups...) +// codeSignGroups := []IosCodeSignGroup{} +// codeSignGroups = append(codeSignGroups, notXcodeManagedGroups...) +// codeSignGroups = append(codeSignGroups, xcodeManagedGroups...) +// codeSignGroups = append(codeSignGroups, singleWildcardGroups...) +// codeSignGroups = append(codeSignGroups, remainingGroups...) - return codeSignGroups -} +// return codeSignGroups +// } +*/ diff --git a/exportoptionsgenerator/export/mac.go b/exportoptionsgenerator/export/mac.go deleted file mode 100644 index e3fcd42d..00000000 --- a/exportoptionsgenerator/export/mac.go +++ /dev/null @@ -1,73 +0,0 @@ -package export - -import ( - "github.com/bitrise-io/go-xcode/certificateutil" - "github.com/bitrise-io/go-xcode/exportoptions" - "github.com/bitrise-io/go-xcode/profileutil" -) - -// MacCodeSignGroup ... -type MacCodeSignGroup struct { - certificate certificateutil.CertificateInfoModel - installerCertificate *certificateutil.CertificateInfoModel - bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel -} - -// Certificate ... -func (signGroup *MacCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { - return signGroup.certificate -} - -// InstallerCertificate ... -func (signGroup *MacCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { - return signGroup.installerCertificate -} - -// BundleIDProfileMap ... -func (signGroup *MacCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { - return signGroup.bundleIDProfileMap -} - -// NewMacGroup ... -func NewMacGroup(certificate certificateutil.CertificateInfoModel, installerCertificate *certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *MacCodeSignGroup { - return &MacCodeSignGroup{ - certificate: certificate, - installerCertificate: installerCertificate, - bundleIDProfileMap: bundleIDProfileMap, - } -} - -// CreateMacCodeSignGroup ... -func CreateMacCodeSignGroup(selectableGroups []SelectableCodeSignGroup, installedInstallerCertificates []certificateutil.CertificateInfoModel, exportMethod exportoptions.Method) []MacCodeSignGroup { - macosCodeSignGroups := []MacCodeSignGroup{} - - iosCodesignGroups := CreateIosCodeSignGroups(selectableGroups) - - for _, group := range iosCodesignGroups { - if exportMethod.IsAppStore() { - installerCertificates := []certificateutil.CertificateInfoModel{} - - for _, installerCertificate := range installedInstallerCertificates { - if installerCertificate.TeamID == group.certificate.TeamID { - installerCertificates = append(installerCertificates, installerCertificate) - } - } - - if len(installerCertificates) > 0 { - installerCertificate := installerCertificates[0] - macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ - certificate: group.certificate, - installerCertificate: &installerCertificate, - bundleIDProfileMap: group.bundleIDProfileMap, - }) - } - } else { - macosCodeSignGroups = append(macosCodeSignGroups, MacCodeSignGroup{ - certificate: group.certificate, - bundleIDProfileMap: group.bundleIDProfileMap, - }) - } - } - - return macosCodeSignGroups -} From f00632d11e6e3e461aa13ced752dad1f77c41f5c Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:58:11 +0100 Subject: [PATCH 3/9] Use v2 logger --- .../codesign_group_provider.go | 10 +- exportoptionsgenerator/export/export_test.go | 53 ++++ exportoptionsgenerator/export/filter.go | 28 +- exportoptionsgenerator/export/ios.go | 285 ------------------ 4 files changed, 71 insertions(+), 305 deletions(-) diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 2ee2ad0b..07e1af8d 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -65,7 +65,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate if len(bundleIDEntitlementsMap) > 0 { g.logger.Warnf("Filtering CodeSignInfo groups for target capabilities") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(convertToV1PlistData(bundleIDEntitlementsMap))) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(g.logger, convertToV1PlistData(bundleIDEntitlementsMap))) g.logger.Debugf("\nGroups after filtering for target capabilities:") for _, group := range codeSignGroups { @@ -75,7 +75,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Warnf("Filtering CodeSignInfo groups for export method") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateExportMethodSelectableCodeSignGroupFilter(exportMethod)) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateExportMethodSelectableCodeSignGroupFilter(g.logger, exportMethod)) g.logger.Debugf("\nGroups after filtering for export method:") for _, group := range codeSignGroups { @@ -85,7 +85,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate if teamID != "" { g.logger.Warnf("ExportDevelopmentTeam specified: %s, filtering CodeSignInfo groups...", teamID) - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateTeamSelectableCodeSignGroupFilter(teamID)) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateTeamSelectableCodeSignGroupFilter(g.logger, teamID)) g.logger.Debugf("\nGroups after filtering for team ID:") for _, group := range codeSignGroups { @@ -98,7 +98,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate "only NOT Xcode managed profiles are allowed to sign when exporting the archive.\n" + "Removing Xcode managed CodeSignInfo groups") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateNotXcodeManagedSelectableCodeSignGroupFilter()) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateNotXcodeManagedSelectableCodeSignGroupFilter(g.logger)) g.logger.Debugf("\nGroups after filtering for NOT Xcode managed profiles:") for _, group := range codeSignGroups { @@ -109,7 +109,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate if teamID == "" && defaultProfile != nil { g.logger.Debugf("\ndefault profile: %v\n", defaultProfile) filteredCodeSignGroups := export.FilterSelectableCodeSignGroups(codeSignGroups, - export.CreateExcludeProfileNameSelectableCodeSignGroupFilter(defaultProfile.Name)) + export.CreateExcludeProfileNameSelectableCodeSignGroupFilter(g.logger, defaultProfile.Name)) if len(filteredCodeSignGroups) > 0 { codeSignGroups = filteredCodeSignGroups diff --git a/exportoptionsgenerator/export/export_test.go b/exportoptionsgenerator/export/export_test.go index 507918cd..743a38b8 100644 --- a/exportoptionsgenerator/export/export_test.go +++ b/exportoptionsgenerator/export/export_test.go @@ -3,6 +3,7 @@ package export_test import ( "testing" + "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" @@ -11,6 +12,7 @@ import ( ) func TestCreateSelectableCodeSignGroups(t *testing.T) { + logger := log.NewLogger() certDev := certificateutil.CertificateInfoModel{ CommonName: "iPhone Distribution: Bitrise Test (ABCD1234)", TeamID: "ABCD1234", @@ -29,6 +31,7 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { certificates []certificateutil.CertificateInfoModel profiles []profileutil.ProvisioningProfileInfoModel bundleIDs []string + filters []export.SelectableCodeSignGroupFilter want []export.SelectableCodeSignGroup }{ { @@ -52,10 +55,60 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { }, }, }, + { + name: "filter by team ID, no match", + certificates: []certificateutil.CertificateInfoModel{ + certDev, + }, + profiles: []profileutil.ProvisioningProfileInfoModel{ + profileDev, + }, + bundleIDs: []string{"io.bitrise.testapp"}, + filters: []export.SelectableCodeSignGroupFilter{ + export.CreateTeamSelectableCodeSignGroupFilter(logger, "WRONGID"), + }, + want: []export.SelectableCodeSignGroup{}, + }, + { + name: "filter by team ID, match", + certificates: []certificateutil.CertificateInfoModel{ + certDev, + }, + profiles: []profileutil.ProvisioningProfileInfoModel{ + profileDev, + }, + bundleIDs: []string{"io.bitrise.testapp"}, + filters: []export.SelectableCodeSignGroupFilter{ + export.CreateTeamSelectableCodeSignGroupFilter(logger, "ABCD1234"), + }, + want: []export.SelectableCodeSignGroup{ + { + Certificate: certDev, + BundleIDProfilesMap: map[string][]profileutil.ProvisioningProfileInfoModel{ + "io.bitrise.testapp": {profileDev}, + }, + }, + }, + }, + { + name: "filter out app store distribution", + certificates: []certificateutil.CertificateInfoModel{ + certDev, + }, + profiles: []profileutil.ProvisioningProfileInfoModel{ + profileDev, + }, + bundleIDs: []string{"io.bitrise.testapp"}, + filters: []export.SelectableCodeSignGroupFilter{ + export.CreateExportMethodSelectableCodeSignGroupFilter(logger, exportoptions.MethodAdHoc), + }, + want: []export.SelectableCodeSignGroup{}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := export.CreateSelectableCodeSignGroups(tt.certificates, tt.profiles, tt.bundleIDs) + got = export.FilterSelectableCodeSignGroups(got, tt.filters...) require.Equal(t, tt.want, got) }) } diff --git a/exportoptionsgenerator/export/filter.go b/exportoptionsgenerator/export/filter.go index deac64d6..9d83eb79 100644 --- a/exportoptionsgenerator/export/filter.go +++ b/exportoptionsgenerator/export/filter.go @@ -1,7 +1,7 @@ package export import ( - "github.com/bitrise-io/go-utils/log" + "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/plistutil" "github.com/bitrise-io/go-xcode/profileutil" @@ -33,9 +33,9 @@ func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFunc } // CreateEntitlementsSelectableCodeSignGroupFilter ... -func CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlementsMap map[string]plistutil.PlistData) SelectableCodeSignGroupFilter { +func CreateEntitlementsSelectableCodeSignGroupFilter(logger log.Logger, bundleIDEntitlementsMap map[string]plistutil.PlistData) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Entitlements filter - removes profile if has missing capabilities") + logger.Debugf("Entitlements filter - removes profile if has missing capabilities") filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} @@ -66,9 +66,9 @@ func CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlementsMap map } // CreateExportMethodSelectableCodeSignGroupFilter ... -func CreateExportMethodSelectableCodeSignGroupFilter(exportMethod exportoptions.Method) SelectableCodeSignGroupFilter { +func CreateExportMethodSelectableCodeSignGroupFilter(logger log.Logger, exportMethod exportoptions.Method) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Export method filter - removes profile if distribution type is not: %s", exportMethod) + logger.Debugf("Export method filter - removes profile if distribution type is not: %s", exportMethod) filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} @@ -98,18 +98,18 @@ func CreateExportMethodSelectableCodeSignGroupFilter(exportMethod exportoptions. } // CreateTeamSelectableCodeSignGroupFilter ... -func CreateTeamSelectableCodeSignGroupFilter(teamID string) SelectableCodeSignGroupFilter { +func CreateTeamSelectableCodeSignGroupFilter(logger log.Logger, teamID string) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Development Team filter - restrict group if team is not: %s", teamID) + logger.Debugf("Development Team filter - restrict group if team is not: %s", teamID) return group.Certificate.TeamID == teamID } } // CreateNotXcodeManagedSelectableCodeSignGroupFilter ... -func CreateNotXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { +func CreateNotXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Xcode managed filter - removes profile if xcode managed") + logger.Debugf("Xcode managed filter - removes profile if xcode managed") filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} @@ -138,11 +138,10 @@ func CreateNotXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGrou } } -/* // CreateXcodeManagedSelectableCodeSignGroupFilter ... -func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { +func CreateXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Xcode managed filter - removes profile if not xcode managed") + logger.Debugf("Xcode managed filter - removes profile if not xcode managed") filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} @@ -170,12 +169,11 @@ func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFi return false } } -*/ // CreateExcludeProfileNameSelectableCodeSignGroupFilter ... -func CreateExcludeProfileNameSelectableCodeSignGroupFilter(name string) SelectableCodeSignGroupFilter { +func CreateExcludeProfileNameSelectableCodeSignGroupFilter(logger log.Logger, name string) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - log.Debugf("Profile name filter - removes profile with name: %s", name) + logger.Debugf("Profile name filter - removes profile with name: %s", name) filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} diff --git a/exportoptionsgenerator/export/ios.go b/exportoptionsgenerator/export/ios.go index 754be5bf..5b9cabd8 100644 --- a/exportoptionsgenerator/export/ios.go +++ b/exportoptionsgenerator/export/ios.go @@ -33,288 +33,3 @@ func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfi bundleIDProfileMap: bundleIDProfileMap, } } - -/* -func createSingleWildcardGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { - groups := []IosCodeSignGroup{} - - certificate := group.Certificate - bundleIDProfilesMap := group.BundleIDProfilesMap - - bundleIDs := []string{} - profiles := []profileutil.ProvisioningProfileInfoModel{} - for bundleID, matchingProfiles := range bundleIDProfilesMap { - bundleIDs = append(bundleIDs, bundleID) - profiles = append(profiles, matchingProfiles...) - } - - for _, profile := range profiles { - if alreadyUsedProfileUUIDMap[profile.UUID] { - continue - } - - matchesForAllBundleID := true - for _, bundleID := range bundleIDs { - if !glob.Glob(profile.BundleID, bundleID) { - matchesForAllBundleID = false - break - } - } - if matchesForAllBundleID { - bundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} - for _, bundleID := range bundleIDs { - bundleIDProfileMap[bundleID] = profile - } - - group := IosCodeSignGroup{ - certificate: certificate, - bundleIDProfileMap: bundleIDProfileMap, - } - groups = append(groups, group) - - alreadyUsedProfileUUIDMap[profile.UUID] = true - } - } - return groups -} - -func createXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { - groups := []IosCodeSignGroup{} - - certificate := group.Certificate - bundleIDProfilesMap := group.BundleIDProfilesMap - - bundleIDs := []string{} - profiles := []profileutil.ProvisioningProfileInfoModel{} - for bundleID, matchingProfiles := range bundleIDProfilesMap { - bundleIDs = append(bundleIDs, bundleID) - profiles = append(profiles, matchingProfiles...) - } - - // collect xcode managed profiles - xcodeManagedProfiles := []profileutil.ProvisioningProfileInfoModel{} - for _, profile := range profiles { - if !alreadyUsedProfileUUIDMap[profile.UUID] && profile.IsXcodeManaged() { - xcodeManagedProfiles = append(xcodeManagedProfiles, profile) - } - } - sort.Sort(ByBundleIDLength(xcodeManagedProfiles)) - - // map profiles to bundle ids + remove the already used profiles - bundleIDMannagedProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} - for _, bundleID := range bundleIDs { - for _, profile := range xcodeManagedProfiles { - if !glob.Glob(profile.BundleID, bundleID) { - continue - } - - matchingProfiles := bundleIDMannagedProfilesMap[bundleID] - if matchingProfiles == nil { - matchingProfiles = []profileutil.ProvisioningProfileInfoModel{} - } - matchingProfiles = append(matchingProfiles, profile) - bundleIDMannagedProfilesMap[bundleID] = matchingProfiles - } - } - - if len(bundleIDMannagedProfilesMap) == len(bundleIDs) { - // if only one profile can sign a bundle id, remove it from bundleIDMannagedProfilesMap - alreadyUsedManagedProfileMap := map[string]bool{} - for _, profiles := range bundleIDMannagedProfilesMap { - if len(profiles) == 1 { - profile := profiles[0] - alreadyUsedManagedProfileMap[profile.UUID] = true - } - } - - bundleIDMannagedProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} - for bundleID, profiles := range bundleIDMannagedProfilesMap { - if len(profiles) == 1 { - bundleIDMannagedProfileMap[bundleID] = profiles[0] - } else { - remainingProfiles := []profileutil.ProvisioningProfileInfoModel{} - for _, profile := range profiles { - if !alreadyUsedManagedProfileMap[profile.UUID] { - remainingProfiles = append(remainingProfiles, profile) - } - } - if len(remainingProfiles) == 1 { - bundleIDMannagedProfileMap[bundleID] = remainingProfiles[0] - } - } - } - - // create code sign group - if len(bundleIDMannagedProfileMap) == len(bundleIDs) { - for _, profile := range bundleIDMannagedProfileMap { - alreadyUsedProfileUUIDMap[profile.UUID] = true - } - - group := IosCodeSignGroup{ - certificate: certificate, - bundleIDProfileMap: bundleIDMannagedProfileMap, - } - groups = append(groups, group) - } - } - - return groups -} - -func createNotXcodeManagedGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { - groups := []IosCodeSignGroup{} - - certificate := group.Certificate - bundleIDProfilesMap := group.BundleIDProfilesMap - - bundleIDs := []string{} - profiles := []profileutil.ProvisioningProfileInfoModel{} - for bundleID, matchingProfiles := range bundleIDProfilesMap { - bundleIDs = append(bundleIDs, bundleID) - profiles = append(profiles, matchingProfiles...) - } - - // collect xcode managed profiles - notXcodeManagedProfiles := []profileutil.ProvisioningProfileInfoModel{} - for _, profile := range profiles { - if !alreadyUsedProfileUUIDMap[profile.UUID] && !profile.IsXcodeManaged() { - notXcodeManagedProfiles = append(notXcodeManagedProfiles, profile) - } - } - sort.Sort(ByBundleIDLength(notXcodeManagedProfiles)) - - // map profiles to bundle ids + remove the already used profiles - bundleIDNotMannagedProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} - for _, bundleID := range bundleIDs { - for _, profile := range notXcodeManagedProfiles { - if !glob.Glob(profile.BundleID, bundleID) { - continue - } - - matchingProfiles := bundleIDNotMannagedProfilesMap[bundleID] - if matchingProfiles == nil { - matchingProfiles = []profileutil.ProvisioningProfileInfoModel{} - } - matchingProfiles = append(matchingProfiles, profile) - bundleIDNotMannagedProfilesMap[bundleID] = matchingProfiles - } - } - - if len(bundleIDNotMannagedProfilesMap) == len(bundleIDs) { - // if only one profile can sign a bundle id, remove it from bundleIDNotMannagedProfilesMap - alreadyUsedNotManagedProfileMap := map[string]bool{} - for _, profiles := range bundleIDNotMannagedProfilesMap { - if len(profiles) == 1 { - profile := profiles[0] - alreadyUsedNotManagedProfileMap[profile.UUID] = true - } - } - - bundleIDNotMannagedProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} - for bundleID, profiles := range bundleIDNotMannagedProfilesMap { - if len(profiles) == 1 { - bundleIDNotMannagedProfileMap[bundleID] = profiles[0] - } else { - remainingProfiles := []profileutil.ProvisioningProfileInfoModel{} - for _, profile := range profiles { - if !alreadyUsedNotManagedProfileMap[profile.UUID] { - remainingProfiles = append(remainingProfiles, profile) - } - } - if len(remainingProfiles) == 1 { - bundleIDNotMannagedProfileMap[bundleID] = remainingProfiles[0] - } - } - } - - // create code sign group - if len(bundleIDNotMannagedProfileMap) == len(bundleIDs) { - for _, profile := range bundleIDNotMannagedProfileMap { - alreadyUsedProfileUUIDMap[profile.UUID] = true - } - - codeSignGroup := IosCodeSignGroup{ - certificate: certificate, - bundleIDProfileMap: bundleIDNotMannagedProfileMap, - } - groups = append(groups, codeSignGroup) - } - } - - return groups -} - -func createRemainingGroups(group SelectableCodeSignGroup, alreadyUsedProfileUUIDMap map[string]bool) []IosCodeSignGroup { - groups := []IosCodeSignGroup{} - - certificate := group.Certificate - bundleIDProfilesMap := group.BundleIDProfilesMap - - bundleIDs := []string{} - profiles := []profileutil.ProvisioningProfileInfoModel{} - for bundleID, matchingProfiles := range bundleIDProfilesMap { - bundleIDs = append(bundleIDs, bundleID) - profiles = append(profiles, matchingProfiles...) - } - - if len(alreadyUsedProfileUUIDMap) != len(profiles) { - bundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} - for _, bundleID := range bundleIDs { - for _, profile := range profiles { - if alreadyUsedProfileUUIDMap[profile.UUID] { - continue - } - - if !glob.Glob(profile.BundleID, bundleID) { - continue - } - - bundleIDProfileMap[bundleID] = profile - break - } - } - - if len(bundleIDProfileMap) == len(bundleIDs) { - group := IosCodeSignGroup{ - certificate: certificate, - bundleIDProfileMap: bundleIDProfileMap, - } - groups = append(groups, group) - } - } - - return groups -} - -// // CreateIosCodeSignGroups ... -// func CreateIosCodeSignGroups(selectableGroups []SelectableCodeSignGroup) []IosCodeSignGroup { -// alreadyUsedProfileUUIDMap := map[string]bool{} - -// singleWildcardGroups := []IosCodeSignGroup{} -// xcodeManagedGroups := []IosCodeSignGroup{} -// notXcodeManagedGroups := []IosCodeSignGroup{} -// remainingGroups := []IosCodeSignGroup{} - -// for _, selectableGroup := range selectableGroups { -// // create groups with single wildcard profiles -// singleWildcardGroups = append(singleWildcardGroups, createSingleWildcardGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - -// // create groups with xcode managed profiles -// xcodeManagedGroups = append(xcodeManagedGroups, createXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - -// // create groups with NOT xcode managed profiles -// notXcodeManagedGroups = append(notXcodeManagedGroups, createNotXcodeManagedGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) - -// // if there are remaining profiles we create a not exact group by using the first matching profile for every bundle id -// remainingGroups = append(remainingGroups, createRemainingGroups(selectableGroup, alreadyUsedProfileUUIDMap)...) -// } - -// codeSignGroups := []IosCodeSignGroup{} -// codeSignGroups = append(codeSignGroups, notXcodeManagedGroups...) -// codeSignGroups = append(codeSignGroups, xcodeManagedGroups...) -// codeSignGroups = append(codeSignGroups, singleWildcardGroups...) -// codeSignGroups = append(codeSignGroups, remainingGroups...) - -// return codeSignGroups -// } -*/ From 43a50442ae631c413ebe6034d4d384dda5243beb Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:59:56 +0100 Subject: [PATCH 4/9] Move export to internal --- exportoptionsgenerator/codesign_group_provider.go | 2 +- exportoptionsgenerator/exportoptionsgenerator.go | 2 +- exportoptionsgenerator/{ => internal}/export/codesing_group.go | 0 exportoptionsgenerator/{ => internal}/export/export.go | 0 exportoptionsgenerator/{ => internal}/export/export_test.go | 2 +- exportoptionsgenerator/{ => internal}/export/filter.go | 0 exportoptionsgenerator/{ => internal}/export/ios.go | 0 7 files changed, 3 insertions(+), 3 deletions(-) rename exportoptionsgenerator/{ => internal}/export/codesing_group.go (100%) rename exportoptionsgenerator/{ => internal}/export/export.go (100%) rename exportoptionsgenerator/{ => internal}/export/export_test.go (97%) rename exportoptionsgenerator/{ => internal}/export/filter.go (100%) rename exportoptionsgenerator/{ => internal}/export/ios.go (100%) diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 07e1af8d..0ad93394 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -5,7 +5,7 @@ import ( "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" "github.com/bitrise-io/go-xcode/v2/plistutil" ) diff --git a/exportoptionsgenerator/exportoptionsgenerator.go b/exportoptionsgenerator/exportoptionsgenerator.go index 13a3c34b..95c5de00 100644 --- a/exportoptionsgenerator/exportoptionsgenerator.go +++ b/exportoptionsgenerator/exportoptionsgenerator.go @@ -7,7 +7,7 @@ import ( "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" "github.com/bitrise-io/go-xcode/v2/plistutil" "github.com/bitrise-io/go-xcode/v2/xcodeversion" ) diff --git a/exportoptionsgenerator/export/codesing_group.go b/exportoptionsgenerator/internal/export/codesing_group.go similarity index 100% rename from exportoptionsgenerator/export/codesing_group.go rename to exportoptionsgenerator/internal/export/codesing_group.go diff --git a/exportoptionsgenerator/export/export.go b/exportoptionsgenerator/internal/export/export.go similarity index 100% rename from exportoptionsgenerator/export/export.go rename to exportoptionsgenerator/internal/export/export.go diff --git a/exportoptionsgenerator/export/export_test.go b/exportoptionsgenerator/internal/export/export_test.go similarity index 97% rename from exportoptionsgenerator/export/export_test.go rename to exportoptionsgenerator/internal/export/export_test.go index 743a38b8..1b852d8b 100644 --- a/exportoptionsgenerator/export/export_test.go +++ b/exportoptionsgenerator/internal/export/export_test.go @@ -7,7 +7,7 @@ import ( "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/export" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" "github.com/stretchr/testify/require" ) diff --git a/exportoptionsgenerator/export/filter.go b/exportoptionsgenerator/internal/export/filter.go similarity index 100% rename from exportoptionsgenerator/export/filter.go rename to exportoptionsgenerator/internal/export/filter.go diff --git a/exportoptionsgenerator/export/ios.go b/exportoptionsgenerator/internal/export/ios.go similarity index 100% rename from exportoptionsgenerator/export/ios.go rename to exportoptionsgenerator/internal/export/ios.go From 9ece977f5d66cff1f8e8569cb277f1ac27f06e2e Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Mon, 16 Feb 2026 19:23:06 +0100 Subject: [PATCH 5/9] Added codesigngroup printer, removed extraneous log usages --- .../codesign_group_provider.go | 30 +++++---- .../internal/export/codesigngroup_printer.go | 44 ++++++++++++ .../export/codesigngroup_printer_test.go | 67 +++++++++++++++++++ .../internal/export/export.go | 28 -------- .../internal/export/export_test.go | 22 ++---- .../internal/export/filter.go | 43 ++++-------- 6 files changed, 147 insertions(+), 87 deletions(-) create mode 100644 exportoptionsgenerator/internal/export/codesigngroup_printer.go create mode 100644 exportoptionsgenerator/internal/export/codesigngroup_printer_test.go diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 0ad93394..6362213e 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -15,12 +15,16 @@ type CodeSignGroupProvider interface { } type codeSignGroupProvider struct { - logger log.Logger + logger log.Logger + printer *export.CodeSignGroupPrinter } // NewCodeSignGroupProvider ... func NewCodeSignGroupProvider(logger log.Logger) CodeSignGroupProvider { - return &codeSignGroupProvider{logger: logger} + return &codeSignGroupProvider{ + logger: logger, + printer: export.NewCodeSignGroupPrinter(logger), + } } // DetermineCodesignGroup .... @@ -59,37 +63,37 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Debugf("\nGroups:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } if len(bundleIDEntitlementsMap) > 0 { g.logger.Warnf("Filtering CodeSignInfo groups for target capabilities") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(g.logger, convertToV1PlistData(bundleIDEntitlementsMap))) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(convertToV1PlistData(bundleIDEntitlementsMap))) g.logger.Debugf("\nGroups after filtering for target capabilities:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } } g.logger.Warnf("Filtering CodeSignInfo groups for export method") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateExportMethodSelectableCodeSignGroupFilter(g.logger, exportMethod)) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateExportMethodSelectableCodeSignGroupFilter(exportMethod)) g.logger.Debugf("\nGroups after filtering for export method:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } if teamID != "" { g.logger.Warnf("ExportDevelopmentTeam specified: %s, filtering CodeSignInfo groups...", teamID) - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateTeamSelectableCodeSignGroupFilter(g.logger, teamID)) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateTeamSelectableCodeSignGroupFilter(teamID)) g.logger.Debugf("\nGroups after filtering for team ID:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } } @@ -98,24 +102,24 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate "only NOT Xcode managed profiles are allowed to sign when exporting the archive.\n" + "Removing Xcode managed CodeSignInfo groups") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateNotXcodeManagedSelectableCodeSignGroupFilter(g.logger)) + codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateNotXcodeManagedSelectableCodeSignGroupFilter()) g.logger.Debugf("\nGroups after filtering for NOT Xcode managed profiles:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } } if teamID == "" && defaultProfile != nil { g.logger.Debugf("\ndefault profile: %v\n", defaultProfile) filteredCodeSignGroups := export.FilterSelectableCodeSignGroups(codeSignGroups, - export.CreateExcludeProfileNameSelectableCodeSignGroupFilter(g.logger, defaultProfile.Name)) + export.CreateExcludeProfileNameSelectableCodeSignGroupFilter(defaultProfile.Name)) if len(filteredCodeSignGroups) > 0 { codeSignGroups = filteredCodeSignGroups g.logger.Debugf("\nGroups after removing default profile:") for _, group := range codeSignGroups { - g.logger.Debugf(group.String()) + g.logger.Debugf("%s", g.printer.ToDebugString(group)) } } } diff --git a/exportoptionsgenerator/internal/export/codesigngroup_printer.go b/exportoptionsgenerator/internal/export/codesigngroup_printer.go new file mode 100644 index 00000000..4f72826b --- /dev/null +++ b/exportoptionsgenerator/internal/export/codesigngroup_printer.go @@ -0,0 +1,44 @@ +package export + +import ( + "encoding/json" + "fmt" + + "github.com/bitrise-io/go-utils/v2/log" +) + +type CodeSignGroupPrinter struct { + logger log.Logger +} + +// NewCodeSignGroupPrinter ... +func NewCodeSignGroupPrinter(logger log.Logger) *CodeSignGroupPrinter { + return &CodeSignGroupPrinter{ + logger: logger, + } +} + +// ToDebugString ... +func (printer CodeSignGroupPrinter) ToDebugString(group SelectableCodeSignGroup) string { + printable := map[string]any{} + printable["team"] = fmt.Sprintf("%s (%s)", group.Certificate.TeamName, group.Certificate.TeamID) + printable["certificate"] = fmt.Sprintf("%s (%s)", group.Certificate.CommonName, group.Certificate.Serial) + + bundleIDProfiles := map[string][]string{} + for bundleID, profileInfos := range group.BundleIDProfilesMap { + printableProfiles := []string{} + for _, profileInfo := range profileInfos { + printableProfiles = append(printableProfiles, fmt.Sprintf("%s (%s)", profileInfo.Name, profileInfo.UUID)) + } + bundleIDProfiles[bundleID] = printableProfiles + } + printable["bundle_id_profiles"] = bundleIDProfiles + + data, err := json.MarshalIndent(printable, "", "\t") + if err != nil { + printer.logger.Errorf("Failed to marshal: %v, error: %s", printable, err) + return "" + } + + return string(data) +} diff --git a/exportoptionsgenerator/internal/export/codesigngroup_printer_test.go b/exportoptionsgenerator/internal/export/codesigngroup_printer_test.go new file mode 100644 index 00000000..2334ca39 --- /dev/null +++ b/exportoptionsgenerator/internal/export/codesigngroup_printer_test.go @@ -0,0 +1,67 @@ +package export_test + +import ( + "testing" + + "github.com/bitrise-io/go-utils/v2/log" + "github.com/bitrise-io/go-xcode/certificateutil" + "github.com/bitrise-io/go-xcode/profileutil" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" + "github.com/stretchr/testify/require" +) + +func TestCodeSignGroupPrinter_ToDebugString(t *testing.T) { + tests := []struct { + name string + group export.SelectableCodeSignGroup + want string + }{ + { + name: "empty group", + group: export.SelectableCodeSignGroup{ + Certificate: certificateutil.CertificateInfoModel{ + CommonName: "CN", + Serial: "SERIAL", + TeamID: "TEAMID", + }, + BundleIDProfilesMap: map[string][]profileutil.ProvisioningProfileInfoModel{ + "com.example.app": { + { + Name: "Profile 1", + UUID: "UUID1", + }, + { + Name: "Profile 2", + UUID: "UUID2", + }, + }, + "com.example.appext": {{ + Name: "Profile 3", + UUID: "UUID3", + }}, + }, + }, + want: `{ + "bundle_id_profiles": { + "com.example.app": [ + "Profile 1 (UUID1)", + "Profile 2 (UUID2)" + ], + "com.example.appext": [ + "Profile 3 (UUID3)" + ] + }, + "certificate": "CN (SERIAL)", + "team": " (TEAMID)" +}`, + }, + } + logger := log.NewLogger() + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + printer := export.NewCodeSignGroupPrinter(logger) + got := printer.ToDebugString(tt.group) + require.JSONEq(t, tt.want, got) + }) + } +} diff --git a/exportoptionsgenerator/internal/export/export.go b/exportoptionsgenerator/internal/export/export.go index 199885c0..4aa424e7 100644 --- a/exportoptionsgenerator/internal/export/export.go +++ b/exportoptionsgenerator/internal/export/export.go @@ -1,11 +1,8 @@ package export import ( - "encoding/json" - "fmt" "sort" - "github.com/bitrise-io/go-utils/log" "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/profileutil" "github.com/ryanuber/go-glob" @@ -17,31 +14,6 @@ type SelectableCodeSignGroup struct { BundleIDProfilesMap map[string][]profileutil.ProvisioningProfileInfoModel } -// String ... -func (group SelectableCodeSignGroup) String() string { - printable := map[string]interface{}{} - printable["team"] = fmt.Sprintf("%s (%s)", group.Certificate.TeamName, group.Certificate.TeamID) - printable["certificate"] = fmt.Sprintf("%s (%s)", group.Certificate.CommonName, group.Certificate.Serial) - - bundleIDProfiles := map[string][]string{} - for bundleID, profileInfos := range group.BundleIDProfilesMap { - printableProfiles := []string{} - for _, profileInfo := range profileInfos { - printableProfiles = append(printableProfiles, fmt.Sprintf("%s (%s)", profileInfo.Name, profileInfo.UUID)) - } - bundleIDProfiles[bundleID] = printableProfiles - } - printable["bundle_id_profiles"] = bundleIDProfiles - - data, err := json.MarshalIndent(printable, "", "\t") - if err != nil { - log.Errorf("Failed to marshal: %v, error: %s", printable, err) - return "" - } - - return string(data) -} - func containsCertificate(installedCertificates []certificateutil.CertificateInfoModel, certificate certificateutil.CertificateInfoModel) bool { for _, cert := range installedCertificates { if cert.Serial == certificate.Serial { diff --git a/exportoptionsgenerator/internal/export/export_test.go b/exportoptionsgenerator/internal/export/export_test.go index 1b852d8b..7d5a8fa1 100644 --- a/exportoptionsgenerator/internal/export/export_test.go +++ b/exportoptionsgenerator/internal/export/export_test.go @@ -3,7 +3,6 @@ package export_test import ( "testing" - "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" @@ -12,7 +11,6 @@ import ( ) func TestCreateSelectableCodeSignGroups(t *testing.T) { - logger := log.NewLogger() certDev := certificateutil.CertificateInfoModel{ CommonName: "iPhone Distribution: Bitrise Test (ABCD1234)", TeamID: "ABCD1234", @@ -31,7 +29,7 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { certificates []certificateutil.CertificateInfoModel profiles []profileutil.ProvisioningProfileInfoModel bundleIDs []string - filters []export.SelectableCodeSignGroupFilter + filter export.SelectableCodeSignGroupFilter want []export.SelectableCodeSignGroup }{ { @@ -64,10 +62,8 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filters: []export.SelectableCodeSignGroupFilter{ - export.CreateTeamSelectableCodeSignGroupFilter(logger, "WRONGID"), - }, - want: []export.SelectableCodeSignGroup{}, + filter: export.CreateTeamSelectableCodeSignGroupFilter("WRONGID"), + want: []export.SelectableCodeSignGroup{}, }, { name: "filter by team ID, match", @@ -78,9 +74,7 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filters: []export.SelectableCodeSignGroupFilter{ - export.CreateTeamSelectableCodeSignGroupFilter(logger, "ABCD1234"), - }, + filter: export.CreateTeamSelectableCodeSignGroupFilter("ABCD1234"), want: []export.SelectableCodeSignGroup{ { Certificate: certDev, @@ -99,16 +93,14 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filters: []export.SelectableCodeSignGroupFilter{ - export.CreateExportMethodSelectableCodeSignGroupFilter(logger, exportoptions.MethodAdHoc), - }, - want: []export.SelectableCodeSignGroup{}, + filter: export.CreateExportMethodSelectableCodeSignGroupFilter(exportoptions.MethodAdHoc), + want: []export.SelectableCodeSignGroup{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := export.CreateSelectableCodeSignGroups(tt.certificates, tt.profiles, tt.bundleIDs) - got = export.FilterSelectableCodeSignGroups(got, tt.filters...) + got = export.FilterSelectableCodeSignGroups(got, tt.filter) require.Equal(t, tt.want, got) }) } diff --git a/exportoptionsgenerator/internal/export/filter.go b/exportoptionsgenerator/internal/export/filter.go index 9d83eb79..3283381d 100644 --- a/exportoptionsgenerator/internal/export/filter.go +++ b/exportoptionsgenerator/internal/export/filter.go @@ -1,7 +1,6 @@ package export import ( - "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/plistutil" "github.com/bitrise-io/go-xcode/profileutil" @@ -11,20 +10,14 @@ import ( type SelectableCodeSignGroupFilter func(group *SelectableCodeSignGroup) bool // FilterSelectableCodeSignGroups ... -func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFuncs ...SelectableCodeSignGroupFilter) []SelectableCodeSignGroup { - filteredGroups := []SelectableCodeSignGroup{} +func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFunc SelectableCodeSignGroupFilter) []SelectableCodeSignGroup { + if filterFunc == nil { + return groups + } + filteredGroups := []SelectableCodeSignGroup{} for _, group := range groups { - allowed := true - - for _, filterFunc := range filterFuncs { - if !filterFunc(&group) { - allowed = false - break - } - } - - if allowed { + if filterFunc(&group) { filteredGroups = append(filteredGroups, group) } } @@ -33,10 +26,8 @@ func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFunc } // CreateEntitlementsSelectableCodeSignGroupFilter ... -func CreateEntitlementsSelectableCodeSignGroupFilter(logger log.Logger, bundleIDEntitlementsMap map[string]plistutil.PlistData) SelectableCodeSignGroupFilter { +func CreateEntitlementsSelectableCodeSignGroupFilter(bundleIDEntitlementsMap map[string]plistutil.PlistData) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Entitlements filter - removes profile if has missing capabilities") - filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} for bundleID, profiles := range group.BundleIDProfilesMap { @@ -66,10 +57,8 @@ func CreateEntitlementsSelectableCodeSignGroupFilter(logger log.Logger, bundleID } // CreateExportMethodSelectableCodeSignGroupFilter ... -func CreateExportMethodSelectableCodeSignGroupFilter(logger log.Logger, exportMethod exportoptions.Method) SelectableCodeSignGroupFilter { +func CreateExportMethodSelectableCodeSignGroupFilter(exportMethod exportoptions.Method) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Export method filter - removes profile if distribution type is not: %s", exportMethod) - filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} for bundleID, profiles := range group.BundleIDProfilesMap { @@ -98,19 +87,15 @@ func CreateExportMethodSelectableCodeSignGroupFilter(logger log.Logger, exportMe } // CreateTeamSelectableCodeSignGroupFilter ... -func CreateTeamSelectableCodeSignGroupFilter(logger log.Logger, teamID string) SelectableCodeSignGroupFilter { +func CreateTeamSelectableCodeSignGroupFilter(teamID string) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Development Team filter - restrict group if team is not: %s", teamID) - return group.Certificate.TeamID == teamID } } // CreateNotXcodeManagedSelectableCodeSignGroupFilter ... -func CreateNotXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) SelectableCodeSignGroupFilter { +func CreateNotXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Xcode managed filter - removes profile if xcode managed") - filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} for bundleID, profiles := range group.BundleIDProfilesMap { @@ -139,10 +124,8 @@ func CreateNotXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) Selec } // CreateXcodeManagedSelectableCodeSignGroupFilter ... -func CreateXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) SelectableCodeSignGroupFilter { +func CreateXcodeManagedSelectableCodeSignGroupFilter() SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Xcode managed filter - removes profile if not xcode managed") - filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} for bundleID, profiles := range group.BundleIDProfilesMap { @@ -171,10 +154,8 @@ func CreateXcodeManagedSelectableCodeSignGroupFilter(logger log.Logger) Selectab } // CreateExcludeProfileNameSelectableCodeSignGroupFilter ... -func CreateExcludeProfileNameSelectableCodeSignGroupFilter(logger log.Logger, name string) SelectableCodeSignGroupFilter { +func CreateExcludeProfileNameSelectableCodeSignGroupFilter(name string) SelectableCodeSignGroupFilter { return func(group *SelectableCodeSignGroup) bool { - logger.Debugf("Profile name filter - removes profile with name: %s", name) - filteredBundleIDProfilesMap := map[string][]profileutil.ProvisioningProfileInfoModel{} for bundleID, profiles := range group.BundleIDProfilesMap { From 88af6a03938d6b0732d2b348d02a14e538e9a761 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 17 Feb 2026 11:43:32 +0100 Subject: [PATCH 6/9] Renamed package --- .../codesign_group_provider.go | 52 +++++++------------ .../exportoptionsgenerator.go | 6 +-- .../codesigngroup.go} | 13 +++-- .../{export => codesigngroup}/export_test.go | 28 +++++----- .../{export => codesigngroup}/filter.go | 6 +-- .../internal/{export => codesigngroup}/ios.go | 16 +++--- .../printer.go} | 18 +++++-- .../printer_test.go} | 10 ++-- .../internal/export/codesing_group.go | 13 ----- 9 files changed, 78 insertions(+), 84 deletions(-) rename exportoptionsgenerator/internal/{export/export.go => codesigngroup/codesigngroup.go} (84%) rename exportoptionsgenerator/internal/{export => codesigngroup}/export_test.go (76%) rename exportoptionsgenerator/internal/{export => codesigngroup}/filter.go (96%) rename exportoptionsgenerator/internal/{export => codesigngroup}/ios.go (59%) rename exportoptionsgenerator/internal/{export/codesigngroup_printer.go => codesigngroup/printer.go} (68%) rename exportoptionsgenerator/internal/{export/codesigngroup_printer_test.go => codesigngroup/printer_test.go} (86%) delete mode 100644 exportoptionsgenerator/internal/export/codesing_group.go diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 6362213e..9eb5d573 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -5,30 +5,30 @@ import ( "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" + codesigngroup "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" "github.com/bitrise-io/go-xcode/v2/plistutil" ) // CodeSignGroupProvider ... type CodeSignGroupProvider interface { - DetermineCodesignGroup(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, defaultProfile *profileutil.ProvisioningProfileInfoModel, bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*export.IosCodeSignGroup, error) + DetermineCodesignGroup(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, defaultProfile *profileutil.ProvisioningProfileInfoModel, bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*codesigngroup.Ios, error) } type codeSignGroupProvider struct { logger log.Logger - printer *export.CodeSignGroupPrinter + printer *codesigngroup.CodeSignGroupPrinter } // NewCodeSignGroupProvider ... func NewCodeSignGroupProvider(logger log.Logger) CodeSignGroupProvider { return &codeSignGroupProvider{ logger: logger, - printer: export.NewCodeSignGroupPrinter(logger), + printer: codesigngroup.NewCodeSignGroupPrinter(logger), } } // DetermineCodesignGroup .... -func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, defaultProfile *profileutil.ProvisioningProfileInfoModel, bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*export.IosCodeSignGroup, error) { +func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, defaultProfile *profileutil.ProvisioningProfileInfoModel, bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*codesigngroup.Ios, error) { g.logger.Println() g.logger.Printf("Target Bundle ID - Entitlements map") var bundleIDs []string @@ -56,45 +56,37 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate } g.logger.Printf("Resolving CodeSignGroups...") - codeSignGroups := export.CreateSelectableCodeSignGroups(certificates, profiles, bundleIDs) + codeSignGroups := codesigngroup.BuildFilterableList(certificates, profiles, bundleIDs) if len(codeSignGroups) == 0 { g.logger.Errorf("Failed to find code signing groups for specified export method (%s)", exportMethod) } g.logger.Debugf("\nGroups:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) if len(bundleIDEntitlementsMap) > 0 { g.logger.Warnf("Filtering CodeSignInfo groups for target capabilities") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateEntitlementsSelectableCodeSignGroupFilter(convertToV1PlistData(bundleIDEntitlementsMap))) + codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateEntitlementsSelectableCodeSignGroupFilter(convertToV1PlistData(bundleIDEntitlementsMap))) g.logger.Debugf("\nGroups after filtering for target capabilities:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } g.logger.Warnf("Filtering CodeSignInfo groups for export method") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateExportMethodSelectableCodeSignGroupFilter(exportMethod)) + codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateExportMethodSelectableCodeSignGroupFilter(exportMethod)) g.logger.Debugf("\nGroups after filtering for export method:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) if teamID != "" { g.logger.Warnf("ExportDevelopmentTeam specified: %s, filtering CodeSignInfo groups...", teamID) - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateTeamSelectableCodeSignGroupFilter(teamID)) + codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateTeamSelectableCodeSignGroupFilter(teamID)) g.logger.Debugf("\nGroups after filtering for team ID:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } if !xcodeManaged { @@ -102,29 +94,25 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate "only NOT Xcode managed profiles are allowed to sign when exporting the archive.\n" + "Removing Xcode managed CodeSignInfo groups") - codeSignGroups = export.FilterSelectableCodeSignGroups(codeSignGroups, export.CreateNotXcodeManagedSelectableCodeSignGroupFilter()) + codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateNotXcodeManagedSelectableCodeSignGroupFilter()) g.logger.Debugf("\nGroups after filtering for NOT Xcode managed profiles:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } if teamID == "" && defaultProfile != nil { g.logger.Debugf("\ndefault profile: %v\n", defaultProfile) - filteredCodeSignGroups := export.FilterSelectableCodeSignGroups(codeSignGroups, - export.CreateExcludeProfileNameSelectableCodeSignGroupFilter(defaultProfile.Name)) + filteredCodeSignGroups := codesigngroup.Filter(codeSignGroups, + codesigngroup.CreateExcludeProfileNameSelectableCodeSignGroupFilter(defaultProfile.Name)) if len(filteredCodeSignGroups) > 0 { codeSignGroups = filteredCodeSignGroups g.logger.Debugf("\nGroups after removing default profile:") - for _, group := range codeSignGroups { - g.logger.Debugf("%s", g.printer.ToDebugString(group)) - } + g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } } - var iosCodeSignGroups []export.IosCodeSignGroup + var iosCodeSignGroups []codesigngroup.Ios for _, selectable := range codeSignGroups { bundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{} @@ -136,7 +124,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate } } - iosCodeSignGroups = append(iosCodeSignGroups, *export.NewIOSGroup(selectable.Certificate, bundleIDProfileMap)) + iosCodeSignGroups = append(iosCodeSignGroups, *codesigngroup.NewIOSGroup(selectable.Certificate, bundleIDProfileMap)) } g.logger.Debugf("\nFiltered groups:") diff --git a/exportoptionsgenerator/exportoptionsgenerator.go b/exportoptionsgenerator/exportoptionsgenerator.go index a18dc1f3..d90339e9 100644 --- a/exportoptionsgenerator/exportoptionsgenerator.go +++ b/exportoptionsgenerator/exportoptionsgenerator.go @@ -7,7 +7,7 @@ import ( "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" + codesigngroup "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" "github.com/bitrise-io/go-xcode/v2/plistutil" "github.com/bitrise-io/go-xcode/v2/xcodeversion" ) @@ -128,7 +128,7 @@ func (g ExportOptionsGenerator) GenerateApplicationExportOptions( // determineCodesignGroup finds the best codesign group (certificate + profiles) // based on the installed Provisioning Profiles and Codesign Certificates. -func (g ExportOptionsGenerator) determineCodesignGroup(bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*export.IosCodeSignGroup, error) { +func (g ExportOptionsGenerator) determineCodesignGroup(bundleIDEntitlementsMap map[string]plistutil.PlistData, exportMethod exportoptions.Method, teamID string, xcodeManaged bool) (*codesigngroup.Ios, error) { certs, err := g.certificateProvider.ListCodesignIdentities() if err != nil { return nil, fmt.Errorf("failed to get installed certificates: %w", err) @@ -268,7 +268,7 @@ func addTestFlightInternalTestingOnly(exportOpts exportoptions.ExportOptions, te return exportOpts } -func addManualSigningFields(exportOpts exportoptions.ExportOptions, codeSignGroup *export.IosCodeSignGroup, archivedWithXcodeManagedProfiles bool, logger log.Logger) exportoptions.ExportOptions { +func addManualSigningFields(exportOpts exportoptions.ExportOptions, codeSignGroup *codesigngroup.Ios, archivedWithXcodeManagedProfiles bool, logger log.Logger) exportoptions.ExportOptions { exportCodeSignStyle := "" exportProfileMapping := map[string]string{} diff --git a/exportoptionsgenerator/internal/export/export.go b/exportoptionsgenerator/internal/codesigngroup/codesigngroup.go similarity index 84% rename from exportoptionsgenerator/internal/export/export.go rename to exportoptionsgenerator/internal/codesigngroup/codesigngroup.go index 4aa424e7..26b8fd61 100644 --- a/exportoptionsgenerator/internal/export/export.go +++ b/exportoptionsgenerator/internal/codesigngroup/codesigngroup.go @@ -1,4 +1,4 @@ -package export +package codesigngroup import ( "sort" @@ -8,6 +8,13 @@ import ( "github.com/ryanuber/go-glob" ) +// CodeSignGroup ... +type CodeSignGroup interface { + Certificate() certificateutil.CertificateInfoModel + InstallerCertificate() *certificateutil.CertificateInfoModel + BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel +} + // SelectableCodeSignGroup ... type SelectableCodeSignGroup struct { Certificate certificateutil.CertificateInfoModel @@ -23,8 +30,8 @@ func containsCertificate(installedCertificates []certificateutil.CertificateInfo return false } -// CreateSelectableCodeSignGroups ... -func CreateSelectableCodeSignGroups(installedCertificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { +// BuildFilterableList ... +func BuildFilterableList(installedCertificates []certificateutil.CertificateInfoModel, profiles []profileutil.ProvisioningProfileInfoModel, bundleIDs []string) []SelectableCodeSignGroup { groups := []SelectableCodeSignGroup{} serialToProfiles := map[string][]profileutil.ProvisioningProfileInfoModel{} diff --git a/exportoptionsgenerator/internal/export/export_test.go b/exportoptionsgenerator/internal/codesigngroup/export_test.go similarity index 76% rename from exportoptionsgenerator/internal/export/export_test.go rename to exportoptionsgenerator/internal/codesigngroup/export_test.go index 7d5a8fa1..e4afa387 100644 --- a/exportoptionsgenerator/internal/export/export_test.go +++ b/exportoptionsgenerator/internal/codesigngroup/export_test.go @@ -1,4 +1,4 @@ -package export_test +package codesigngroup_test import ( "testing" @@ -6,7 +6,7 @@ import ( "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" "github.com/stretchr/testify/require" ) @@ -29,22 +29,22 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { certificates []certificateutil.CertificateInfoModel profiles []profileutil.ProvisioningProfileInfoModel bundleIDs []string - filter export.SelectableCodeSignGroupFilter - want []export.SelectableCodeSignGroup + filter codesigngroup.SelectableCodeSignGroupFilter + want []codesigngroup.SelectableCodeSignGroup }{ { name: "empty inputs", certificates: []certificateutil.CertificateInfoModel{}, profiles: []profileutil.ProvisioningProfileInfoModel{}, bundleIDs: []string{}, - want: []export.SelectableCodeSignGroup{}, + want: []codesigngroup.SelectableCodeSignGroup{}, }, { name: "single matching profile and certificate", certificates: []certificateutil.CertificateInfoModel{certDev}, profiles: []profileutil.ProvisioningProfileInfoModel{profileDev}, bundleIDs: []string{"io.bitrise.testapp"}, - want: []export.SelectableCodeSignGroup{ + want: []codesigngroup.SelectableCodeSignGroup{ { Certificate: certDev, BundleIDProfilesMap: map[string][]profileutil.ProvisioningProfileInfoModel{ @@ -62,8 +62,8 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filter: export.CreateTeamSelectableCodeSignGroupFilter("WRONGID"), - want: []export.SelectableCodeSignGroup{}, + filter: codesigngroup.CreateTeamSelectableCodeSignGroupFilter("WRONGID"), + want: []codesigngroup.SelectableCodeSignGroup{}, }, { name: "filter by team ID, match", @@ -74,8 +74,8 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filter: export.CreateTeamSelectableCodeSignGroupFilter("ABCD1234"), - want: []export.SelectableCodeSignGroup{ + filter: codesigngroup.CreateTeamSelectableCodeSignGroupFilter("ABCD1234"), + want: []codesigngroup.SelectableCodeSignGroup{ { Certificate: certDev, BundleIDProfilesMap: map[string][]profileutil.ProvisioningProfileInfoModel{ @@ -93,14 +93,14 @@ func TestCreateSelectableCodeSignGroups(t *testing.T) { profileDev, }, bundleIDs: []string{"io.bitrise.testapp"}, - filter: export.CreateExportMethodSelectableCodeSignGroupFilter(exportoptions.MethodAdHoc), - want: []export.SelectableCodeSignGroup{}, + filter: codesigngroup.CreateExportMethodSelectableCodeSignGroupFilter(exportoptions.MethodAdHoc), + want: []codesigngroup.SelectableCodeSignGroup{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := export.CreateSelectableCodeSignGroups(tt.certificates, tt.profiles, tt.bundleIDs) - got = export.FilterSelectableCodeSignGroups(got, tt.filter) + got := codesigngroup.BuildFilterableList(tt.certificates, tt.profiles, tt.bundleIDs) + got = codesigngroup.Filter(got, tt.filter) require.Equal(t, tt.want, got) }) } diff --git a/exportoptionsgenerator/internal/export/filter.go b/exportoptionsgenerator/internal/codesigngroup/filter.go similarity index 96% rename from exportoptionsgenerator/internal/export/filter.go rename to exportoptionsgenerator/internal/codesigngroup/filter.go index 3283381d..bdd9bb14 100644 --- a/exportoptionsgenerator/internal/export/filter.go +++ b/exportoptionsgenerator/internal/codesigngroup/filter.go @@ -1,4 +1,4 @@ -package export +package codesigngroup import ( "github.com/bitrise-io/go-xcode/exportoptions" @@ -9,8 +9,8 @@ import ( // SelectableCodeSignGroupFilter ... type SelectableCodeSignGroupFilter func(group *SelectableCodeSignGroup) bool -// FilterSelectableCodeSignGroups ... -func FilterSelectableCodeSignGroups(groups []SelectableCodeSignGroup, filterFunc SelectableCodeSignGroupFilter) []SelectableCodeSignGroup { +// Filter ... +func Filter(groups []SelectableCodeSignGroup, filterFunc SelectableCodeSignGroupFilter) []SelectableCodeSignGroup { if filterFunc == nil { return groups } diff --git a/exportoptionsgenerator/internal/export/ios.go b/exportoptionsgenerator/internal/codesigngroup/ios.go similarity index 59% rename from exportoptionsgenerator/internal/export/ios.go rename to exportoptionsgenerator/internal/codesigngroup/ios.go index 5b9cabd8..3c4fefbf 100644 --- a/exportoptionsgenerator/internal/export/ios.go +++ b/exportoptionsgenerator/internal/codesigngroup/ios.go @@ -1,34 +1,34 @@ -package export +package codesigngroup import ( "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/profileutil" ) -// IosCodeSignGroup ... -type IosCodeSignGroup struct { +// Ios ... +type Ios struct { certificate certificateutil.CertificateInfoModel bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel } // Certificate ... -func (signGroup *IosCodeSignGroup) Certificate() certificateutil.CertificateInfoModel { +func (signGroup *Ios) Certificate() certificateutil.CertificateInfoModel { return signGroup.certificate } // InstallerCertificate ... -func (signGroup *IosCodeSignGroup) InstallerCertificate() *certificateutil.CertificateInfoModel { +func (signGroup *Ios) InstallerCertificate() *certificateutil.CertificateInfoModel { return nil } // BundleIDProfileMap ... -func (signGroup *IosCodeSignGroup) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { +func (signGroup *Ios) BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel { return signGroup.bundleIDProfileMap } // NewIOSGroup ... -func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *IosCodeSignGroup { - return &IosCodeSignGroup{ +func NewIOSGroup(certificate certificateutil.CertificateInfoModel, bundleIDProfileMap map[string]profileutil.ProvisioningProfileInfoModel) *Ios { + return &Ios{ certificate: certificate, bundleIDProfileMap: bundleIDProfileMap, } diff --git a/exportoptionsgenerator/internal/export/codesigngroup_printer.go b/exportoptionsgenerator/internal/codesigngroup/printer.go similarity index 68% rename from exportoptionsgenerator/internal/export/codesigngroup_printer.go rename to exportoptionsgenerator/internal/codesigngroup/printer.go index 4f72826b..2808f481 100644 --- a/exportoptionsgenerator/internal/export/codesigngroup_printer.go +++ b/exportoptionsgenerator/internal/codesigngroup/printer.go @@ -1,12 +1,14 @@ -package export +package codesigngroup import ( "encoding/json" "fmt" + "strings" "github.com/bitrise-io/go-utils/v2/log" ) +// CodeSignGroupPrinter ... type CodeSignGroupPrinter struct { logger log.Logger } @@ -18,8 +20,18 @@ func NewCodeSignGroupPrinter(logger log.Logger) *CodeSignGroupPrinter { } } +// ListToDebugString ... +func (printer *CodeSignGroupPrinter) ListToDebugString(groups []SelectableCodeSignGroup) string { + var builder strings.Builder + for _, group := range groups { + builder.WriteString(printer.ToDebugString(group) + "\n") + } + + return builder.String() +} + // ToDebugString ... -func (printer CodeSignGroupPrinter) ToDebugString(group SelectableCodeSignGroup) string { +func (printer *CodeSignGroupPrinter) ToDebugString(group SelectableCodeSignGroup) string { printable := map[string]any{} printable["team"] = fmt.Sprintf("%s (%s)", group.Certificate.TeamName, group.Certificate.TeamID) printable["certificate"] = fmt.Sprintf("%s (%s)", group.Certificate.CommonName, group.Certificate.Serial) @@ -36,7 +48,7 @@ func (printer CodeSignGroupPrinter) ToDebugString(group SelectableCodeSignGroup) data, err := json.MarshalIndent(printable, "", "\t") if err != nil { - printer.logger.Errorf("Failed to marshal: %v, error: %s", printable, err) + printer.logger.Errorf("Failed to marshal (%v): %s", printable, err) return "" } diff --git a/exportoptionsgenerator/internal/export/codesigngroup_printer_test.go b/exportoptionsgenerator/internal/codesigngroup/printer_test.go similarity index 86% rename from exportoptionsgenerator/internal/export/codesigngroup_printer_test.go rename to exportoptionsgenerator/internal/codesigngroup/printer_test.go index 2334ca39..dcb67c1f 100644 --- a/exportoptionsgenerator/internal/export/codesigngroup_printer_test.go +++ b/exportoptionsgenerator/internal/codesigngroup/printer_test.go @@ -1,4 +1,4 @@ -package export_test +package codesigngroup_test import ( "testing" @@ -6,19 +6,19 @@ import ( "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/certificateutil" "github.com/bitrise-io/go-xcode/profileutil" - "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/export" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" "github.com/stretchr/testify/require" ) func TestCodeSignGroupPrinter_ToDebugString(t *testing.T) { tests := []struct { name string - group export.SelectableCodeSignGroup + group codesigngroup.SelectableCodeSignGroup want string }{ { name: "empty group", - group: export.SelectableCodeSignGroup{ + group: codesigngroup.SelectableCodeSignGroup{ Certificate: certificateutil.CertificateInfoModel{ CommonName: "CN", Serial: "SERIAL", @@ -59,7 +59,7 @@ func TestCodeSignGroupPrinter_ToDebugString(t *testing.T) { logger := log.NewLogger() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - printer := export.NewCodeSignGroupPrinter(logger) + printer := codesigngroup.NewCodeSignGroupPrinter(logger) got := printer.ToDebugString(tt.group) require.JSONEq(t, tt.want, got) }) diff --git a/exportoptionsgenerator/internal/export/codesing_group.go b/exportoptionsgenerator/internal/export/codesing_group.go deleted file mode 100644 index 50316fb5..00000000 --- a/exportoptionsgenerator/internal/export/codesing_group.go +++ /dev/null @@ -1,13 +0,0 @@ -package export - -import ( - "github.com/bitrise-io/go-xcode/certificateutil" - "github.com/bitrise-io/go-xcode/profileutil" -) - -// CodeSignGroup ... -type CodeSignGroup interface { - Certificate() certificateutil.CertificateInfoModel - InstallerCertificate() *certificateutil.CertificateInfoModel - BundleIDProfileMap() map[string]profileutil.ProvisioningProfileInfoModel -} From 9179ae5ec4f3d0ba02bcf87751412dd83fe85454 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 17 Feb 2026 11:49:13 +0100 Subject: [PATCH 7/9] renamed file --- exportoptionsgenerator/exportoptionsgenerator.go | 2 +- .../codesigngroup/{export_test.go => codesigngroup_test.go} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename exportoptionsgenerator/internal/codesigngroup/{export_test.go => codesigngroup_test.go} (100%) diff --git a/exportoptionsgenerator/exportoptionsgenerator.go b/exportoptionsgenerator/exportoptionsgenerator.go index d90339e9..e17f70c2 100644 --- a/exportoptionsgenerator/exportoptionsgenerator.go +++ b/exportoptionsgenerator/exportoptionsgenerator.go @@ -7,7 +7,7 @@ import ( "github.com/bitrise-io/go-utils/v2/log" "github.com/bitrise-io/go-xcode/exportoptions" "github.com/bitrise-io/go-xcode/profileutil" - codesigngroup "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" + "github.com/bitrise-io/go-xcode/v2/exportoptionsgenerator/internal/codesigngroup" "github.com/bitrise-io/go-xcode/v2/plistutil" "github.com/bitrise-io/go-xcode/v2/xcodeversion" ) diff --git a/exportoptionsgenerator/internal/codesigngroup/export_test.go b/exportoptionsgenerator/internal/codesigngroup/codesigngroup_test.go similarity index 100% rename from exportoptionsgenerator/internal/codesigngroup/export_test.go rename to exportoptionsgenerator/internal/codesigngroup/codesigngroup_test.go From 07faf32bcec4290804841c15d8ea0f54e70abe32 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 17 Feb 2026 11:56:05 +0100 Subject: [PATCH 8/9] Renamed printer --- exportoptionsgenerator/codesign_group_provider.go | 12 +++++------- .../internal/codesigngroup/printer.go | 14 +++++++------- .../internal/codesigngroup/printer_test.go | 4 ++-- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 9eb5d573..088005b5 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -16,14 +16,14 @@ type CodeSignGroupProvider interface { type codeSignGroupProvider struct { logger log.Logger - printer *codesigngroup.CodeSignGroupPrinter + printer *codesigngroup.Printer } // NewCodeSignGroupProvider ... func NewCodeSignGroupProvider(logger log.Logger) CodeSignGroupProvider { return &codeSignGroupProvider{ logger: logger, - printer: codesigngroup.NewCodeSignGroupPrinter(logger), + printer: codesigngroup.NewPrinter(logger), } } @@ -42,9 +42,6 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Printf("%s: %s", bundleID, entitlementKeys) } - g.logger.Println() - g.logger.Printf("Resolving CodeSignGroups...") - g.logger.Debugf("Installed certificates:") for _, certInfo := range certificates { g.logger.Debugf(certInfo.String()) @@ -55,7 +52,8 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Debugf(profileInfo.String(certificates...)) } - g.logger.Printf("Resolving CodeSignGroups...") + g.logger.Println() + g.logger.Printf("Resolving code signing groups...") codeSignGroups := codesigngroup.BuildFilterableList(certificates, profiles, bundleIDs) if len(codeSignGroups) == 0 { g.logger.Errorf("Failed to find code signing groups for specified export method (%s)", exportMethod) @@ -136,7 +134,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate } if len(iosCodeSignGroups) < 1 { - g.logger.Errorf("Failed to find Codesign Groups") + g.logger.Errorf("Failed to find code signing groups") return nil, nil } diff --git a/exportoptionsgenerator/internal/codesigngroup/printer.go b/exportoptionsgenerator/internal/codesigngroup/printer.go index 2808f481..58ffa6da 100644 --- a/exportoptionsgenerator/internal/codesigngroup/printer.go +++ b/exportoptionsgenerator/internal/codesigngroup/printer.go @@ -8,20 +8,20 @@ import ( "github.com/bitrise-io/go-utils/v2/log" ) -// CodeSignGroupPrinter ... -type CodeSignGroupPrinter struct { +// Printer ... +type Printer struct { logger log.Logger } -// NewCodeSignGroupPrinter ... -func NewCodeSignGroupPrinter(logger log.Logger) *CodeSignGroupPrinter { - return &CodeSignGroupPrinter{ +// NewPrinter ... +func NewPrinter(logger log.Logger) *Printer { + return &Printer{ logger: logger, } } // ListToDebugString ... -func (printer *CodeSignGroupPrinter) ListToDebugString(groups []SelectableCodeSignGroup) string { +func (printer *Printer) ListToDebugString(groups []SelectableCodeSignGroup) string { var builder strings.Builder for _, group := range groups { builder.WriteString(printer.ToDebugString(group) + "\n") @@ -31,7 +31,7 @@ func (printer *CodeSignGroupPrinter) ListToDebugString(groups []SelectableCodeSi } // ToDebugString ... -func (printer *CodeSignGroupPrinter) ToDebugString(group SelectableCodeSignGroup) string { +func (printer *Printer) ToDebugString(group SelectableCodeSignGroup) string { printable := map[string]any{} printable["team"] = fmt.Sprintf("%s (%s)", group.Certificate.TeamName, group.Certificate.TeamID) printable["certificate"] = fmt.Sprintf("%s (%s)", group.Certificate.CommonName, group.Certificate.Serial) diff --git a/exportoptionsgenerator/internal/codesigngroup/printer_test.go b/exportoptionsgenerator/internal/codesigngroup/printer_test.go index dcb67c1f..0e152cc1 100644 --- a/exportoptionsgenerator/internal/codesigngroup/printer_test.go +++ b/exportoptionsgenerator/internal/codesigngroup/printer_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" ) -func TestCodeSignGroupPrinter_ToDebugString(t *testing.T) { +func TestPrinter_ToDebugString(t *testing.T) { tests := []struct { name string group codesigngroup.SelectableCodeSignGroup @@ -59,7 +59,7 @@ func TestCodeSignGroupPrinter_ToDebugString(t *testing.T) { logger := log.NewLogger() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - printer := codesigngroup.NewCodeSignGroupPrinter(logger) + printer := codesigngroup.NewPrinter(logger) got := printer.ToDebugString(tt.group) require.JSONEq(t, tt.want, got) }) From e4670ba6002c99a71561cab3ad47a971d93c6287 Mon Sep 17 00:00:00 2001 From: LaszloP <7979773+lpusok@users.noreply.github.com> Date: Tue, 17 Feb 2026 12:21:31 +0100 Subject: [PATCH 9/9] log impros --- .../codesign_group_provider.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/exportoptionsgenerator/codesign_group_provider.go b/exportoptionsgenerator/codesign_group_provider.go index 088005b5..2ef05ee5 100644 --- a/exportoptionsgenerator/codesign_group_provider.go +++ b/exportoptionsgenerator/codesign_group_provider.go @@ -63,7 +63,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) if len(bundleIDEntitlementsMap) > 0 { - g.logger.Warnf("Filtering CodeSignInfo groups for target capabilities") + g.logger.Printf("Filtering code signing groups for target capabilities") codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateEntitlementsSelectableCodeSignGroupFilter(convertToV1PlistData(bundleIDEntitlementsMap))) @@ -71,7 +71,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } - g.logger.Warnf("Filtering CodeSignInfo groups for export method") + g.logger.Printf("Filtering code signing groups for export method %s", exportMethod) codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateExportMethodSelectableCodeSignGroupFilter(exportMethod)) @@ -79,7 +79,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) if teamID != "" { - g.logger.Warnf("ExportDevelopmentTeam specified: %s, filtering CodeSignInfo groups...", teamID) + g.logger.Printf("Development team specified: %s, filtering groups...", teamID) codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateTeamSelectableCodeSignGroupFilter(teamID)) @@ -88,13 +88,13 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate } if !xcodeManaged { - g.logger.Warnf("App was signed with NON Xcode managed profile when archiving,\n" + - "only NOT Xcode managed profiles are allowed to sign when exporting the archive.\n" + - "Removing Xcode managed CodeSignInfo groups") + g.logger.Printf("App was signed with NON Xcode managed profile when archiving,\n" + + "only NON Xcode managed profiles are allowed to sign when exporting the archive.\n" + + "Removing Xcode managed code signing groups") codeSignGroups = codesigngroup.Filter(codeSignGroups, codesigngroup.CreateNotXcodeManagedSelectableCodeSignGroupFilter()) - g.logger.Debugf("\nGroups after filtering for NOT Xcode managed profiles:") + g.logger.Debugf("\nGroups after filtering for NON Xcode managed profiles:") g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } @@ -104,7 +104,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate codesigngroup.CreateExcludeProfileNameSelectableCodeSignGroupFilter(defaultProfile.Name)) if len(filteredCodeSignGroups) > 0 { codeSignGroups = filteredCodeSignGroups - + g.logger.Printf("Removed default profile '%s' from code signing groups", defaultProfile.Name) g.logger.Debugf("\nGroups after removing default profile:") g.logger.Debugf("%s", g.printer.ListToDebugString(codeSignGroups)) } @@ -139,7 +139,7 @@ func (g codeSignGroupProvider) DetermineCodesignGroup(certificates []certificate } if len(iosCodeSignGroups) > 1 { - g.logger.Warnf("Multiple code signing groups found! Using the first code signing group") + g.logger.Warnf("Multiple code signing groups found! Using the first code signing group.") } return &iosCodeSignGroups[0], nil