forked from bitrise-io/go-xcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RA-3066] Add XCArchive and IPA artifact meta parsing logic (bitrise-…
…io#241) * Add XCArchive and IPA artifact meta parsing logic * Remove vendor folder and update mockery mock * Create named error for MacOS project not supported error * Add missing godoc * Fix nil pointer issue * Fix review items * Revert formatting * Revert formatting vol.2.
- Loading branch information
1 parent
f876b48
commit b47f848
Showing
6 changed files
with
288 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package metaparser | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/bitrise-io/go-xcode/v2/artifacts" | ||
"github.com/bitrise-io/go-xcode/v2/zip" | ||
) | ||
|
||
// ParseIPAData ... | ||
func (m *Parser) ParseIPAData(pth string) (*ArtifactMetadata, error) { | ||
appInfo, provisioningInfo, err := m.readIPADeploymentMeta(pth) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to parse deployment info for %s: %w", pth, err) | ||
} | ||
|
||
fileSize, err := m.fileManager.FileSizeInBytes(pth) | ||
if err != nil { | ||
m.logger.Warnf("Failed to get apk size, error: %s", err) | ||
} | ||
|
||
return &ArtifactMetadata{ | ||
AppInfo: appInfo, | ||
FileSizeBytes: fileSize, | ||
ProvisioningInfo: provisioningInfo, | ||
}, nil | ||
} | ||
|
||
func (m *Parser) readIPADeploymentMeta(ipaPth string) (Info, ProvisionInfo, error) { | ||
reader, err := zip.NewDefaultReader(ipaPth, m.logger) | ||
if err != nil { | ||
return Info{}, ProvisionInfo{}, err | ||
} | ||
defer func() { | ||
if err := reader.Close(); err != nil { | ||
m.logger.Warnf("%s", err) | ||
} | ||
}() | ||
|
||
ipaReader := artifacts.NewIPAReader(reader) | ||
infoPlist, err := ipaReader.AppInfoPlist() | ||
if err != nil { | ||
return Info{}, ProvisionInfo{}, fmt.Errorf("failed to unwrap Info.plist from ipa: %w", err) | ||
} | ||
|
||
appTitle, _ := infoPlist.GetString("CFBundleName") | ||
bundleID, _ := infoPlist.GetString("CFBundleIdentifier") | ||
version, _ := infoPlist.GetString("CFBundleShortVersionString") | ||
buildNumber, _ := infoPlist.GetString("CFBundleVersion") | ||
minOSVersion, _ := infoPlist.GetString("MinimumOSVersion") | ||
deviceFamilyList, _ := infoPlist.GetUInt64Array("UIDeviceFamily") | ||
|
||
appInfo := Info{ | ||
AppTitle: appTitle, | ||
BundleID: bundleID, | ||
Version: version, | ||
BuildNumber: buildNumber, | ||
MinOSVersion: minOSVersion, | ||
DeviceFamilyList: deviceFamilyList, | ||
} | ||
|
||
provisioningProfileInfo, err := ipaReader.ProvisioningProfileInfo() | ||
if err != nil { | ||
return Info{}, ProvisionInfo{}, fmt.Errorf("failed to read profile info from ipa: %w", err) | ||
} | ||
|
||
provisioningInfo := ProvisionInfo{ | ||
CreationDate: provisioningProfileInfo.CreationDate, | ||
ExpireDate: provisioningProfileInfo.ExpirationDate, | ||
DeviceUDIDList: provisioningProfileInfo.ProvisionedDevices, | ||
TeamName: provisioningProfileInfo.TeamName, | ||
ProfileName: provisioningProfileInfo.Name, | ||
ProvisionsAllDevices: provisioningProfileInfo.ProvisionsAllDevices, | ||
IPAExportMethod: provisioningProfileInfo.ExportType, | ||
} | ||
|
||
return appInfo, provisioningInfo, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package metaparser | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/bitrise-io/go-utils/v2/fileutil" | ||
"github.com/bitrise-io/go-utils/v2/log" | ||
"github.com/bitrise-io/go-xcode/exportoptions" | ||
) | ||
|
||
// ArtifactMetadata ... | ||
type ArtifactMetadata struct { | ||
AppInfo Info `json:"app_info"` | ||
FileSizeBytes int64 `json:"file_size_bytes"` | ||
ProvisioningInfo ProvisionInfo `json:"provisioning_info,omitempty"` | ||
Scheme string `json:"scheme,omitempty"` | ||
} | ||
|
||
// Info ... | ||
type Info struct { | ||
AppTitle string `json:"app_title"` | ||
BundleID string `json:"bundle_id"` | ||
Version string `json:"version"` | ||
BuildNumber string `json:"build_number"` | ||
MinOSVersion string `json:"min_OS_version"` | ||
DeviceFamilyList []uint64 `json:"device_family_list"` | ||
} | ||
|
||
// ProvisionInfo ... | ||
type ProvisionInfo struct { | ||
CreationDate time.Time `json:"creation_date"` | ||
ExpireDate time.Time `json:"expire_date"` | ||
DeviceUDIDList []string `json:"device_UDID_list"` | ||
TeamName string `json:"team_name"` | ||
ProfileName string `json:"profile_name"` | ||
ProvisionsAllDevices bool `json:"provisions_all_devices"` | ||
IPAExportMethod exportoptions.Method `json:"ipa_export_method"` | ||
} | ||
|
||
// Parser ... | ||
type Parser struct { | ||
logger log.Logger | ||
fileManager fileutil.FileManager | ||
} | ||
|
||
// New ... | ||
func New(logger log.Logger, fileManager fileutil.FileManager) *Parser { | ||
return &Parser{ | ||
logger: logger, | ||
fileManager: fileManager, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package metaparser | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/bitrise-io/go-xcode/v2/artifacts" | ||
"github.com/bitrise-io/go-xcode/v2/zip" | ||
) | ||
|
||
// MacOSProjectIsNotSupported ... | ||
var MacOSProjectIsNotSupported = errors.New("macOS project is not supported") | ||
|
||
// ParseXCArchiveData ... | ||
func (m *Parser) ParseXCArchiveData(pth string) (*ArtifactMetadata, error) { | ||
|
||
appInfo, scheme, err := m.readXCArchiveDeploymentMeta(pth) | ||
if err != nil { | ||
return &ArtifactMetadata{ | ||
AppInfo: appInfo, | ||
Scheme: scheme, | ||
}, fmt.Errorf("failed to parse deployment info for %s: %w", pth, err) | ||
} | ||
|
||
fileSize, err := m.fileManager.FileSizeInBytes(pth) | ||
if err != nil { | ||
m.logger.Warnf("Failed to get apk size, error: %s", err) | ||
} | ||
|
||
return &ArtifactMetadata{ | ||
AppInfo: appInfo, | ||
FileSizeBytes: fileSize, | ||
Scheme: scheme, | ||
}, nil | ||
} | ||
|
||
func (m *Parser) readXCArchiveDeploymentMeta(pth string) (Info, string, error) { | ||
reader, err := zip.NewDefaultReader(pth, m.logger) | ||
if err != nil { | ||
return Info{}, "", err | ||
} | ||
defer func() { | ||
if err := reader.Close(); err != nil { | ||
m.logger.Warnf("%s", err) | ||
} | ||
}() | ||
|
||
xcarchiveReader := artifacts.NewXCArchiveReader(reader) | ||
isMacos := xcarchiveReader.IsMacOS() | ||
if isMacos { | ||
return Info{}, "", MacOSProjectIsNotSupported | ||
} | ||
archiveInfoPlist, err := xcarchiveReader.InfoPlist() | ||
if err != nil { | ||
return Info{}, "", fmt.Errorf("failed to unwrap Info.plist from xcarchive: %w", err) | ||
} | ||
|
||
iosXCArchiveReader := artifacts.NewIOSXCArchiveReader(reader) | ||
appInfoPlist, err := iosXCArchiveReader.AppInfoPlist() | ||
if err != nil { | ||
return Info{}, "", fmt.Errorf("failed to unwrap application Info.plist from xcarchive: %w", err) | ||
} | ||
|
||
appTitle, _ := appInfoPlist.GetString("CFBundleName") | ||
bundleID, _ := appInfoPlist.GetString("CFBundleIdentifier") | ||
version, _ := appInfoPlist.GetString("CFBundleShortVersionString") | ||
buildNumber, _ := appInfoPlist.GetString("CFBundleVersion") | ||
minOSVersion, _ := appInfoPlist.GetString("MinimumOSVersion") | ||
deviceFamilyList, _ := appInfoPlist.GetUInt64Array("UIDeviceFamily") | ||
scheme, _ := archiveInfoPlist.GetString("SchemeName") | ||
|
||
appInfo := Info{ | ||
AppTitle: appTitle, | ||
BundleID: bundleID, | ||
Version: version, | ||
BuildNumber: buildNumber, | ||
MinOSVersion: minOSVersion, | ||
DeviceFamilyList: deviceFamilyList, | ||
} | ||
|
||
return appInfo, scheme, nil | ||
} |
Oops, something went wrong.