-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement sync testflight config command #203
Draft
DechengMa
wants to merge
30
commits into
master
Choose a base branch
from
testflight/sync
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
e972651
Add ./config to gitignore
DechengMa 114d95b
Create TestFlightConfig and Loader with new Filesystem models
DechengMa abefab7
Create SyncResourceComparator for comparing local and server res
DechengMa 53c6436
Create essential pull TestFlight config service func with sync commands
DechengMa c59e0eb
Small model and syntax tweaks on Reader and ListTesterOperation
DechengMa 2066c54
Add testing for sync betagroup and testers comparator
DechengMa c298746
Make SyncStrategy confirm to Equatable
DechengMa 6ebab0c
Syntax fixes for sync command and some other tweak for passing swiftLint
DechengMa ebdbae0
Create Update and Create beta group operations
DechengMa 2a0fe03
Wire up Test Flight push command to the APIs
DechengMa 41ca74d
Make swiftlint pass in PushCommand
DechengMa 2ca5b7a
Add custom Hashable logic to Filesystem.BetaGroup
DechengMa af0b5d8
Some UI Updates in TestFlightPushCommand
DechengMa bec00a4
Merge branch 'master' into testflight/sync
DechengMa a4388f4
Add refresh local after sync completed feature
DechengMa d0c1fad
Merge branch 'master' into testflight/sync
DechengMa 4ef448d
remove TestFlightConfigLoader -> add init to TestFlightConfiguration
DechengMa 5d36cf9
Tweak ResourceComparatorCompareTests
DechengMa 5be708c
BetaGroup && BetaTester struct let -> var, remove tester inviteType
DechengMa 3e4f8fe
Introduce AppSyncActions and update TestFlightPushCommand
DechengMa 92d3dc4
Add support for Creating group and add tester together
DechengMa b69901d
fix swift lint issues
DechengMa c2fe7ff
Make convenience init for BetaGroup and Testers for init sdk model
DechengMa 0e5363c
Optimised pullTestFlightConfigurations for running request in parallel
DechengMa 27f4ebd
Helper Text polishing. Add sync by bundleId feature for pushing
DechengMa 47a4b8f
Optimise invite Tester to group to run in parallel
DechengMa 49a5a8e
Operation optimisation in List and remove BetaTester
DechengMa b8d4f02
Optimise service pullTestFlightConfigurations to use chunk(into: )
DechengMa e5fca76
UI optimisation in Push and Pull command
DechengMa 8e600f1
optimised removeTestersFromGroup to request 5 times per sec
DechengMa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ Temporary Items | |
/Packages | ||
/*.xcodeproj | ||
xcuserdata/ | ||
config/auth.yml | ||
/config |
34 changes: 34 additions & 0 deletions
34
Sources/AppStoreConnectCLI/Commands/TestFlight/Sync/TestFlightPullCommand.swift
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,34 @@ | ||
// Copyright 2020 Itty Bitty Apps Pty Ltd | ||
|
||
import ArgumentParser | ||
import Foundation | ||
import FileSystem | ||
|
||
struct TestFlightPullCommand: CommonParsableCommand { | ||
|
||
static var configuration = CommandConfiguration( | ||
commandName: "pull", | ||
abstract: "Pull down existing TestFlight configuration, refreshing local configuration files." | ||
) | ||
|
||
@OptionGroup() | ||
var common: CommonOptions | ||
|
||
@Option( | ||
default: "./config/apps", | ||
help: "Path to the folder containing the TestFlight configuration." | ||
) var outputPath: String | ||
|
||
func run() throws { | ||
let service = try makeService() | ||
|
||
print("Loading server TestFlight configurations... \n") | ||
let configs = try service.pullTestFlightConfigurations() | ||
print("Loading completed.") | ||
|
||
print("\nRefreshing local configurations...") | ||
try configs.save(in: outputPath) | ||
print("Refreshing completed.") | ||
} | ||
|
||
} |
312 changes: 312 additions & 0 deletions
312
Sources/AppStoreConnectCLI/Commands/TestFlight/Sync/TestFlightPushCommand.swift
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,312 @@ | ||
// Copyright 2020 Itty Bitty Apps Pty Ltd | ||
|
||
import ArgumentParser | ||
import struct FileSystem.TestFlightConfiguration | ||
import struct FileSystem.BetaGroup | ||
import struct FileSystem.BetaTester | ||
import Foundation | ||
import Model | ||
|
||
struct TestFlightPushCommand: CommonParsableCommand { | ||
|
||
static var configuration = CommandConfiguration( | ||
commandName: "push", | ||
abstract: "Push the local configuration to TestFlight." | ||
) | ||
|
||
@OptionGroup() | ||
var common: CommonOptions | ||
|
||
@Option( | ||
default: "./config/apps", | ||
help: "Path to the folder containing the TestFlight configuration." | ||
) | ||
var inputPath: String | ||
|
||
@Option( | ||
parsing: .upToNextOption, | ||
help: "Array of bundle IDs that uniquely identifies the apps that you would like to sync." | ||
) | ||
var bundleIds: [String] | ||
|
||
@Flag(help: "Perform a dry run.") | ||
var dryRun: Bool | ||
|
||
func run() throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the fundamental problem with this command is that you're executing the service requests as you're processing. This should be more functional. Eg:
|
||
let service = try makeService() | ||
|
||
print("Loading local TestFlight configurations...") | ||
let localConfigurations = try [TestFlightConfiguration](from: inputPath, with: bundleIds) | ||
print("Loading completed.") | ||
|
||
print("\nLoading server TestFlight configurations...") | ||
let serverConfigurations = try service.pullTestFlightConfigurations(with: bundleIds) | ||
print("Loading completed.") | ||
|
||
let actions = compare( | ||
serverConfigurations: serverConfigurations, | ||
with: localConfigurations | ||
) | ||
|
||
if dryRun { | ||
render(actions: actions) | ||
} else { | ||
try process(actions: actions, with: service) | ||
|
||
print("\nRefreshing local configurations...") | ||
try service.pullTestFlightConfigurations().save(in: inputPath) | ||
print("Refreshing completed.") | ||
} | ||
} | ||
|
||
func render(actions: [AppSyncActions]) { | ||
print("\n'Dry Run' mode activated, changes will not be applied. ") | ||
|
||
actions.forEach { action in | ||
print("\n\(action.app.name ?? ""): ") | ||
|
||
// 1. app testers | ||
if action.appTestersSyncActions.isNotEmpty { | ||
print("\n- Testers in App: ") | ||
action.appTestersSyncActions.forEach { $0.render(dryRun: dryRun) } | ||
} | ||
|
||
// 2. BetaGroups in App | ||
if action.betaGroupSyncActions.isNotEmpty { | ||
print("\n- BetaGroups in App: ") | ||
action.betaGroupSyncActions.forEach { | ||
$0.render(dryRun: dryRun) | ||
|
||
if case .create(let betagroup) = $0 { | ||
action.testerInGroupsAction | ||
.append( | ||
.init( | ||
betaGroup: betagroup, | ||
testerActions: betagroup.testers.map { | ||
SyncAction<BetaGroup.EmailAddress>.create($0) | ||
} | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
// 3. Testers in BetaGroup | ||
if action.testerInGroupsAction.isNotEmpty { | ||
print("\n- Testers In Beta Group: ") | ||
action.testerInGroupsAction.forEach { | ||
if $0.testerActions.isNotEmpty { | ||
print("\($0.betaGroup.groupName):") | ||
$0.testerActions.forEach { $0.render(dryRun: dryRun) } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func process(actions: [AppSyncActions], with service: AppStoreConnectService) throws { | ||
try actions.forEach { appAction in | ||
print("\n\(appAction.app.name ?? ""): ") | ||
|
||
var appAction = appAction | ||
|
||
// 1. app testers | ||
try processAppTesterActions( | ||
appAction.appTestersSyncActions, | ||
appId: appAction.app.id, | ||
service: service | ||
) | ||
|
||
// 2. beta groups in app | ||
try processBetagroupsActions( | ||
appAction.betaGroupSyncActions, | ||
appId: appAction.app.id, | ||
appAction: &appAction, | ||
service: service | ||
) | ||
|
||
// 3. testers in beta group | ||
if appAction.testerInGroupsAction.isNotEmpty { | ||
print("\n- Testers In Beta Group: ") | ||
try appAction.testerInGroupsAction.forEach { | ||
print("\($0.betaGroup.groupName): ") | ||
try processTestersInBetaGroupActions( | ||
$0.testerActions, | ||
betagroupId: $0.betaGroup.id!, | ||
appTesters: appAction.appTesters, | ||
service: service | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private func compare( | ||
serverConfigurations: [TestFlightConfiguration], | ||
with localConfigurations: [TestFlightConfiguration] | ||
) -> [AppSyncActions] { | ||
return serverConfigurations.compactMap { serverConfiguration in | ||
guard | ||
let localConfiguration = localConfigurations | ||
.first(where: { $0.app.id == serverConfiguration.app.id }) else { | ||
return nil | ||
} | ||
|
||
let appTesterSyncActions = SyncResourceComparator( | ||
localResources: localConfiguration.testers, | ||
serverResources: serverConfiguration.testers | ||
) | ||
.compare() | ||
|
||
let betaGroupSyncActions = SyncResourceComparator( | ||
localResources: localConfiguration.betagroups, | ||
serverResources: serverConfiguration.betagroups | ||
) | ||
.compare() | ||
|
||
let testerInGroupsAction = localConfiguration.betagroups.compactMap { localBetagroup -> BetaTestersInGroupActions? in | ||
guard | ||
let serverBetaGroup = serverConfiguration | ||
.betagroups | ||
.first(where: { $0.id == localBetagroup.id }) else { | ||
return nil | ||
} | ||
|
||
let testerActions = SyncResourceComparator( | ||
localResources: localBetagroup.testers, | ||
serverResources: serverBetaGroup.testers | ||
) | ||
.compare() | ||
|
||
if testerActions.isEmpty { return nil } | ||
|
||
return BetaTestersInGroupActions( | ||
betaGroup: localBetagroup, | ||
testerActions: testerActions | ||
) | ||
} | ||
|
||
guard appTesterSyncActions.isNotEmpty || | ||
betaGroupSyncActions.isNotEmpty || | ||
testerInGroupsAction.isNotEmpty else { | ||
return nil | ||
} | ||
|
||
return AppSyncActions( | ||
app: localConfiguration.app, | ||
appTesters: localConfiguration.testers, | ||
appTestersSyncActions: appTesterSyncActions, | ||
betaGroupSyncActions: betaGroupSyncActions, | ||
testerInGroupsAction: testerInGroupsAction | ||
) | ||
} | ||
} | ||
|
||
func processAppTesterActions( | ||
_ actions: [SyncAction<BetaTester>], | ||
appId: String, | ||
service: AppStoreConnectService | ||
) throws { | ||
let testersToRemoveActionsWithEmails = actions.compactMap { action -> | ||
(action: SyncAction<BetaTester>, email: String)? in | ||
if case .delete(let betaTesters) = action { | ||
return (action, betaTesters.email) | ||
} | ||
return nil | ||
} | ||
|
||
if testersToRemoveActionsWithEmails.isNotEmpty { | ||
print("\n- Testers in App: ") | ||
try service.removeTestersFromApp(testersEmails: testersToRemoveActionsWithEmails.map { $0.email }, appId: appId) | ||
|
||
testersToRemoveActionsWithEmails.map { $0.action }.forEach { $0.render(dryRun: dryRun) } | ||
} | ||
} | ||
|
||
func processBetagroupsActions( | ||
_ actions: [SyncAction<BetaGroup>], | ||
appId: String, | ||
appAction: inout AppSyncActions, | ||
service: AppStoreConnectService | ||
) throws { | ||
if actions.isNotEmpty { | ||
print("\n- BetaGroups in App: ") | ||
|
||
try actions.forEach { action in | ||
switch action { | ||
case .create(let betagroup): | ||
let newCreatedBetaGroup = try service.createBetaGroup( | ||
appId: appId, | ||
groupName: betagroup.groupName, | ||
publicLinkEnabled: betagroup.publicLinkEnabled ?? false, | ||
publicLinkLimit: betagroup.publicLinkLimit | ||
) | ||
action.render(dryRun: dryRun) | ||
|
||
if betagroup.testers.isNotEmpty { | ||
appAction.testerInGroupsAction | ||
.append( | ||
.init( | ||
betaGroup: newCreatedBetaGroup, | ||
testerActions: betagroup.testers.map { | ||
SyncAction<BetaGroup.EmailAddress>.create($0) | ||
} | ||
) | ||
) | ||
} | ||
|
||
case .delete(let betagroup): | ||
try service.deleteBetaGroup(with: betagroup.id!) | ||
action.render(dryRun: dryRun) | ||
case .update(let betagroup): | ||
try service.updateBetaGroup(betaGroup: betagroup) | ||
action.render(dryRun: dryRun) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func processTestersInBetaGroupActions( | ||
_ actions: [SyncAction<BetaGroup.EmailAddress>], | ||
betagroupId: String, | ||
appTesters: [BetaTester], | ||
service: AppStoreConnectService | ||
) throws { | ||
let deletingEmailsWithStrategy: [(email: String, strategy: SyncAction<BetaGroup.EmailAddress>)] = actions | ||
.compactMap { action in | ||
if case .delete(let email) = action { | ||
return (email, action) | ||
} | ||
return nil | ||
} | ||
|
||
if deletingEmailsWithStrategy.isNotEmpty { | ||
try service.removeTestersFromGroup( | ||
emails: deletingEmailsWithStrategy.map { $0.email }, | ||
groupId: betagroupId | ||
) | ||
|
||
deletingEmailsWithStrategy.forEach { $0.strategy.render(dryRun: dryRun) } | ||
} | ||
|
||
let creatingTestersWithStrategy = actions | ||
.compactMap { (strategy: SyncAction<BetaGroup.EmailAddress>) -> | ||
(tester: BetaTester, strategy: SyncAction<BetaGroup.EmailAddress>)? in | ||
if case .create(let email) = strategy, | ||
let betatester = appTesters.first(where: { $0.email == email }) { | ||
return (betatester, strategy) | ||
} | ||
return nil | ||
} | ||
|
||
if creatingTestersWithStrategy.isNotEmpty { | ||
try service.inviteTestersToGroup( | ||
betaTesters: creatingTestersWithStrategy.map { $0.tester }, | ||
groupId: betagroupId | ||
) | ||
|
||
creatingTestersWithStrategy.forEach { $0.strategy.render(dryRun: dryRun) } | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
Sources/AppStoreConnectCLI/Commands/TestFlight/Sync/TestFlightSyncCommand.swift
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,14 @@ | ||
// Copyright 2020 Itty Bitty Apps Pty Ltd | ||
|
||
import ArgumentParser | ||
|
||
struct TestFlightSyncCommand: ParsableCommand { | ||
static var configuration = CommandConfiguration( | ||
commandName: "sync", | ||
abstract: "Sync information about testflight with provided configuration file.", | ||
subcommands: [ | ||
TestFlightPullCommand.self, | ||
TestFlightPushCommand.self, | ||
] | ||
) | ||
} |
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,11 @@ | ||
// Copyright 2020 Itty Bitty Apps Pty Ltd | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
func chunked(into size: Int) -> [[Element]] { | ||
return stride(from: 0, to: count, by: size).map { | ||
Array(self[$0 ..< Swift.min($0 + size, count)]) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to filter the pulled apps by bundleId.