Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 22 additions & 22 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,12 @@ func filterLatestProfiles(profiles []profileutil.ProvisioningProfileInfoModel) [
return filteredProfiles
}

func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) ([]export.IosCodeSignGroup, error) {
func collectIpaExportCodeSignGroups(tool Tool, archive xcarchive.IosArchive, installedCertificates []certificateutil.CertificateInfoModel, installedProfiles []profileutil.ProvisioningProfileInfoModel) ([]export.IosCodeSignGroup, error) {
iosCodeSignGroups := []export.IosCodeSignGroup{}

codeSignGroups, err := collectIpaExportSelectableCodeSignGroups(archive, installedCertificates, installedProfiles)
if err != nil {
return nil, printXcodeScanFinishedWithError("Failed to collect valid code sign settings: %s", err)
return nil, ArchiveError{tool, "failed to collect valid code sign settings: " + err.Error()}
}

if len(codeSignGroups) == 0 {
Expand All @@ -157,7 +157,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
log.Errorf("- which has installed Codesign Identity in your Keychain")
log.Errorf("- which can provision your application target's bundle ids")
log.Errorf("- which has the project defined Capabilities set")
return nil, printXcodeScanFinishedWithError("Failed to find code sign files")
return nil, ArchiveError{tool, "failed to find code sign files"}
}

exportMethods := []string{"development", "app-store", "ad-hoc", "enterprise"}
Expand All @@ -166,7 +166,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
fmt.Println()
selectedExportMethod, err := goinp.SelectFromStringsWithDefault("Select the ipa export method", 1, exportMethods)
if err != nil {
return nil, printXcodeScanFinishedWithError("Failed to select ipa export method: %s", err)
return nil, ArchiveError{tool, "failed to select ipa export method: " + err.Error()}
}
log.Debugf("selected export method: %v", selectedExportMethod)

Expand Down Expand Up @@ -226,7 +226,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
question := fmt.Sprintf("Select the Codesign Indentity for %s ipa export", selectedExportMethod)
selectedCertificateOption, err = goinp.SelectFromStringsWithDefault(question, 1, certificateOptions)
if err != nil {
return nil, printXcodeScanFinishedWithError("Failed to select Codesign Indentity: %s", err)
return nil, ArchiveError{tool, fmt.Sprintf("failed to select Codesign Indentity: %s", err)}
}
}

Expand All @@ -239,7 +239,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
}
}
if selectedCertificate == nil {
return nil, printXcodeScanFinishedWithError("Failed to find selected Codesign Indentity")
return nil, ArchiveError{tool, "failed to find selected Codesign Indentity"}
}

// Select Profiles
Expand All @@ -252,7 +252,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
}
}
if len(bundleIDProfilesMap) == 0 {
return nil, printXcodeScanFinishedWithError("Failed to find Provisioning Profiles for Code Sign Identity")
return nil, ArchiveError{tool, "failed to find Provisioning Profiles for Code Sign Identity"}
}

selectedBundleIDProfileMap := map[string]profileutil.ProvisioningProfileInfoModel{}
Expand All @@ -276,7 +276,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
question := fmt.Sprintf("Select the Provisioning Profile to sign target with bundle ID: %s", bundleID)
selectedProfileOption, err = goinp.SelectFromStringsWithDefault(question, 1, profileOptions)
if err != nil {
return nil, printXcodeScanFinishedWithError("Failed to select Provisioning Profile: %s", err)
return nil, ArchiveError{tool, fmt.Sprintf("failed to select Provisioning Profile: %s", err)}
}
}

Expand All @@ -288,7 +288,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
}
}
if len(selectedBundleIDProfileMap) != len(bundleIDProfilesMap) {
return nil, printXcodeScanFinishedWithError("Failed to find Provisioning Profiles for ipa export")
return nil, ArchiveError{tool, fmt.Sprintf("failed to find Provisioning Profiles for ipa export")}
}

iosCodeSignGroup := export.IosCodeSignGroup{
Expand Down Expand Up @@ -320,7 +320,7 @@ func collectIpaExportCodeSignGroups(archive xcarchive.IosArchive, installedCerti
return iosCodeSignGroups, nil
}

func collectIpaExportCertificate(archiveCertificate certificateutil.CertificateInfoModel, installedCertificates []certificateutil.CertificateInfoModel) (certificateutil.CertificateInfoModel, error) {
func collectIpaExportCertificate(tool Tool, archiveCertificate certificateutil.CertificateInfoModel, installedCertificates []certificateutil.CertificateInfoModel) (certificateutil.CertificateInfoModel, error) {
fmt.Println()
fmt.Println()
question := fmt.Sprintf(`The Xcode archive used codesigning files of team: %s - %s
Expand All @@ -342,7 +342,7 @@ Would you like to use this team to sign your project?`, archiveCertificate.TeamI
fmt.Println()
selectedTeam, err = goinp.SelectFromStringsWithDefault("Select the Development team to sign your project", 1, teams)
if err != nil {
return certificateutil.CertificateInfoModel{}, printXcodeScanFinishedWithError("Failed to select Codesign Indentity: %s", err)
return certificateutil.CertificateInfoModel{}, ArchiveError{tool, fmt.Sprintf("failed to select Codesign Indentity: %s", err)}
}
} else {
selectedTeam = fmt.Sprintf("%s - %s", archiveCertificate.TeamID, archiveCertificate.TeamName)
Expand All @@ -367,7 +367,7 @@ Would you like to use this team to sign your project?`, archiveCertificate.TeamI
Please select a development certificate:`, archiveCertificate.CommonName, archiveCertificate.Serial)
selectedCertificateOption, err := goinp.SelectFromStringsWithDefault(question, 1, certificateOptions)
if err != nil {
return certificateutil.CertificateInfoModel{}, printXcodeScanFinishedWithError("Failed to select Codesign Indentity: %s", err)
return certificateutil.CertificateInfoModel{}, ArchiveError{tool, fmt.Sprintf("failed to select Codesign Indentity: %s", err)}
}

for _, certInfo := range developmentCertificates {
Expand All @@ -393,7 +393,7 @@ Please select a development certificate:`, archiveCertificate.CommonName, archiv
Please select a distribution certificate:`, archiveCertificate.CommonName, archiveCertificate.Serial)
selectedCertificateOption, err := goinp.SelectFromStringsWithDefault(question, 1, certificateOptions)
if err != nil {
return certificateutil.CertificateInfoModel{}, printXcodeScanFinishedWithError("Failed to select Codesign Indentity: %s", err)
return certificateutil.CertificateInfoModel{}, ArchiveError{tool, fmt.Sprintf("failed to select Codesign Indentity: %s", err)}
}

for _, certInfo := range distributionCertificates {
Expand Down Expand Up @@ -538,11 +538,11 @@ func provProfileExportFileName(info profileutil.ProvisioningProfileInfoModel, pa
return info.UUID + "." + safeTitle + extension
}

func exportCodesignFiles(toolName, archivePath, outputDirPath string) error {
func exportCodesignFiles(tool Tool, archivePath, outputDirPath string) error {
// archive code sign settings
installedCertificates, err := certificateutil.InstalledCodesigningCertificateInfos()
if err != nil {
return printFinishedWithError(toolName, "Failed to list installed code signing identities, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to list installed code signing identities, error: %s", err)}
}
installedCertificates = certificateutil.FilterValidCertificateInfos(installedCertificates)

Expand All @@ -563,12 +563,12 @@ func exportCodesignFiles(toolName, archivePath, outputDirPath string) error {

archive, err := xcarchive.NewIosArchive(archivePath)
if err != nil {
return printFinishedWithError(toolName, "Failed to analyze archive, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to analyze archive, error: %s", err)}
}

archiveCodeSignGroup, err := analyzeArchive(archive, installedCertificates)
if err != nil {
return printFinishedWithError(toolName, "Failed to analyze the archive, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to analyze the archive, error: %s", err)}
}

fmt.Println()
Expand All @@ -585,16 +585,16 @@ func exportCodesignFiles(toolName, archivePath, outputDirPath string) error {
profilesToExport := []profileutil.ProvisioningProfileInfoModel{}

if certificatesOnly {
ipaExportCertificate, err := collectIpaExportCertificate(archiveCodeSignGroup.Certificate, installedCertificates)
ipaExportCertificate, err := collectIpaExportCertificate(tool, archiveCodeSignGroup.Certificate, installedCertificates)
if err != nil {
return err
}

certificatesToExport = append(certificatesToExport, archiveCodeSignGroup.Certificate, ipaExportCertificate)
} else {
ipaExportCodeSignGroups, err := collectIpaExportCodeSignGroups(archive, installedCertificates, installedProfiles)
ipaExportCodeSignGroups, err := collectIpaExportCodeSignGroups(tool, archive, installedCertificates, installedProfiles)
if err != nil {
return printFinishedWithError(toolName, "Failed to collect ipa export code sign groups, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to collect ipa export code sign groups, error: %s", err)}
}

codeSignGroups := append(ipaExportCodeSignGroups, archiveCodeSignGroup)
Expand All @@ -605,11 +605,11 @@ func exportCodesignFiles(toolName, archivePath, outputDirPath string) error {
}

if err := collectAndExportIdentities(certificatesToExport, outputDirPath); err != nil {
return printFinishedWithError(toolName, "Failed to export codesign identities, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to export codesign identities, error: %s", err)}
}

if err := collectAndExportProvisioningProfiles(profilesToExport, outputDirPath); err != nil {
return printFinishedWithError(toolName, "Failed to export provisioning profiles, error: %s", err)
return ArchiveError{tool, fmt.Sprintf("failed to export provisioning profiles, error: %s", err)}
}

fmt.Println()
Expand Down
31 changes: 31 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

import "github.com/bitrise-io/go-utils/colorstring"

// Tool ...
type Tool string

const (
toolXcode Tool = "Xcode"
toolXamarin Tool = "Visual Studio"
)

// ArchiveError ...
type ArchiveError struct {
tool Tool
msg string
}

// Error ...
func (e ArchiveError) Error() string {
return `
------------------------------` + `
First of all ` + colorstring.Red("please make sure that you can Archive your app from "+e.tool+".") + `
codesigndoc only works if you can archive your app from ` + string(e.tool) + `.
If you can, and you get a valid IPA file if you export from ` + string(e.tool) + `,
` + colorstring.Red("please create an issue") + ` on GitHub at: https://github.com/bitrise-tools/codesigndoc/issues
with as many details & logs as you can share!
------------------------------

` + colorstring.Redf("Error: %s", e.msg)
}
14 changes: 0 additions & 14 deletions cmd/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,6 @@ import (
"github.com/bitrise-tools/go-xcode/export"
)

func printFinishedWithError(toolName, format string, args ...interface{}) error {
fmt.Println()
fmt.Println("------------------------------")
fmt.Println("First of all " + colorstring.Red("please make sure that you can Archive your app from "+toolName+"."))
fmt.Println("codesigndoc only works if you can archive your app from " + toolName + ".")
fmt.Println("If you can, and you get a valid IPA file if you export from " + toolName + ",")
fmt.Println(colorstring.Red("please create an issue") + " on GitHub at: https://github.com/bitrise-tools/codesigndoc/issues")
fmt.Println("with as many details & logs as you can share!")
fmt.Println("------------------------------")
fmt.Println()

return fmt.Errorf(colorstring.Red("Error: ")+format, args...)
}

func printFinished(certsOnly bool) {
fmt.Println()
log.Successf("That's all.")
Expand Down
Loading