Skip to content

Commit

Permalink
Add CreateGithubRelease swift script file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tawa committed Mar 8, 2023
1 parent 573aca9 commit 6f01771
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public struct AppVersionUpdateFilteredProvider: AppVersionUpdateProviderProtocol

return appVersionUpdateProvider
.appVersionsPublisher()
// .compactMap { appVersions in
// let results = appVersions.results.filter({ appVersionInfo in
// guard let appVersion = appVersionStringParser.appVersion(from: appVersionInfo.version)
// else { return false }
// return currentAppVersion.isOlderThan(version: appVersion)
// })
//
// return AppVersions(results: results)
// }
.compactMap { appVersions in
let results = appVersions.results.filter({ appVersionInfo in
guard let appVersion = appVersionStringParser.appVersion(from: appVersionInfo.version)
else { return false }
return currentAppVersion.isOlderThan(version: appVersion)
})

return AppVersions(results: results)
}
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import AppVersionProviderContract
import Combine
import Foundation

struct GithubAsset: Decodable {
struct GitHubAsset: Decodable {
let url: URL

enum CodingKeys: String, CodingKey {
case url = "browser_download_url"
}
}

struct GithubVersion: Decodable {
struct GitHubVersion: Decodable {
let url: URL
let tagName: String
let body: String
let assets: [GithubAsset]
let assets: [GitHubAsset]

enum CodingKeys: String, CodingKey {
case url
Expand All @@ -25,7 +25,7 @@ struct GithubVersion: Decodable {
}


public struct GithubVersionUpdateProvider: AppVersionUpdateProviderProtocol {
public struct GitHubVersionUpdateProvider: AppVersionUpdateProviderProtocol {

public init() {

Expand All @@ -40,9 +40,9 @@ public struct GithubVersionUpdateProvider: AppVersionUpdateProviderProtocol {

return URLSession.shared.dataTaskPublisher(for: url)
.tryMap(\.data)
.decode(type: [GithubVersion].self, decoder: JSONDecoder())
.decode(type: [GitHubVersion].self, decoder: JSONDecoder())
.map({ $0.filter { !$0.assets.isEmpty } })
.map({ $0.map { githubVersion in AppVersionInfo(version: githubVersion.tagName, releaseNotes: githubVersion.body) }})
.map({ $0.map { gitHubVersion in AppVersionInfo(version: gitHubVersion.tagName, releaseNotes: gitHubVersion.body) }})
.map({ AppVersions(results: $0) })
.eraseToAnyPublisher()
}
Expand Down
6 changes: 4 additions & 2 deletions Phoenix.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@
B0575B2BA782D723A9A8ECFC /* GenerateFeatureDataStoreContract */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = GenerateFeatureDataStoreContract; sourceTree = "<group>"; };
B2071ECA29B66BBD003E509E /* ci_post_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_post_xcodebuild.sh; sourceTree = "<group>"; };
B2071ECB29B66C5E003E509E /* ci_pre_xcodebuild.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = ci_pre_xcodebuild.sh; sourceTree = "<group>"; };
B2071ECC29B69BA4003E509E /* EnableGithubReleaseTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnableGithubReleaseTarget.swift; sourceTree = "<group>"; };
B2071ECC29B69BA4003E509E /* EnableGitHubReleaseTarget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnableGitHubReleaseTarget.swift; sourceTree = "<group>"; };
B216D3A02926EDC6005EDBB5 /* RelationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RelationView.swift; sourceTree = "<group>"; };
B21BF48C28EAD6E7007AAA0B /* CompositionRoot+AppVersion.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "CompositionRoot+AppVersion.swift"; sourceTree = "<group>"; };
B233DB6828EB5BC000243D58 /* PhoenixUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PhoenixUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
B233DB6A28EB5BC000243D58 /* PhoenixUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoenixUITests.swift; sourceTree = "<group>"; };
B26383E928D7773D00C9380E /* PhoenixRelease.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = PhoenixRelease.entitlements; sourceTree = "<group>"; };
B290498629B87D580088E65F /* CreateGitHubRelease.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateGitHubRelease.swift; sourceTree = "<group>"; };
B298E7FE29B3D1970008794A /* ProjectValidatorCommand */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ProjectValidatorCommand; sourceTree = BUILT_PRODUCTS_DIR; };
B298E80029B3D1970008794A /* CommandLineTool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommandLineTool.swift; sourceTree = "<group>"; };
B29BE1032943D37C00675860 /* ViewModel+Selection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewModel+Selection.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -610,7 +611,8 @@
B2F4B1BA29B49635008DBAB1 /* ci_post_clone.sh */,
B2071ECA29B66BBD003E509E /* ci_post_xcodebuild.sh */,
B2071ECB29B66C5E003E509E /* ci_pre_xcodebuild.sh */,
B2071ECC29B69BA4003E509E /* EnableGithubReleaseTarget.swift */,
B2071ECC29B69BA4003E509E /* EnableGitHubReleaseTarget.swift */,
B290498629B87D580088E65F /* CreateGitHubRelease.swift */,
);
path = ci_scripts;
sourceTree = "<group>";
Expand Down
14 changes: 7 additions & 7 deletions Phoenix/CompositionRoot/CompositionRoot+AppVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ extension Container {
}

private static let remoteAppVersionUpdateProvider = Factory<AppVersionUpdateProviderProtocol>(Container.shared) {
if Container.isGithubRelease {
return GithubVersionUpdateProvider()
if Container.isGitHubRelease {
return GitHubVersionUpdateProvider()
} else {
return AppStoreVersionUpdateProvider()
}
}

static let updateButton = Factory<AnyView>(Container.shared) {
if Container.isGithubRelease {
return AnyView(githubUpdateButton())
if Container.isGitHubRelease {
return AnyView(gitHubUpdateButton())
} else {
return AnyView(appStoreUpdateButton())
}
}

private static let githubUpdateButton = Factory(Container.shared) {
GithubUpdateView()
private static let gitHubUpdateButton = Factory(Container.shared) {
GitHubUpdateView()
}

private static let appStoreUpdateButton = Factory(Container.shared) {
Expand All @@ -61,7 +61,7 @@ extension Bundle: CurrentAppVersionStringProviderProtocol {
}
}

struct GithubUpdateView: View {
struct GitHubUpdateView: View {
@State var isShowingUpdate: Bool = false

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Factory
import Foundation

extension Container {
static let isGithubRelease: Bool = {
static let isGitHubRelease: Bool = {
ProcessInfo.processInfo.environment["release_destination"] == "github"
}()
}
25 changes: 25 additions & 0 deletions ci_scripts/CreateGitHubRelease.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env swift
import Foundation

class CreateGitHubRelease {
static func main() {
print("Create GitHub Release Script")
guard CommandLine.argc == 3
else {
print("Wrong number of parameters")
exit(1)
}

let arguments = CommandLine.arguments

let tag = arguments[1]
let buildPath = arguments[2]
let token = arguments[3]

print("Received Tag: \(tag)")
print("Received build path: \(buildPath)")
print("Received Token: \(token.isEmpty ? "YES": "NO")")
}
}

CreateGitHubRelease.main()
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import Foundation
import RegexBuilder

// Phoenix.xcodeproj/xcshareddata/xcschemes/Phoenix.xcscheme

class EnableGithubReleaseTarget {
class EnableGitHubReleaseTarget {
static func main() {
guard CommandLine.argc == 2 else { exit(1) }
guard CommandLine.argc == 2
else {
print("Wrong number of parameters")
exit(1)
}

let arguments = CommandLine.arguments

Expand Down Expand Up @@ -76,4 +78,4 @@ class EnableGithubReleaseTarget {
}
}

EnableGithubReleaseTarget.main()
EnableGitHubReleaseTarget.main()
3 changes: 0 additions & 3 deletions ci_scripts/ci_post_clone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# ci_pre_xcodebuild.sh
# Phoenix
#
# Created by Tawa Nicolas on 05.03.23.
#

if [[ $CI_WORKFLOW == "PR Unit Tests" ]];
then
Expand Down
5 changes: 1 addition & 4 deletions ci_scripts/ci_post_xcodebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

# ci_post_xcodebuild.sh
# Phoenix
#
# Created by Tawa Nicolas on 06.03.23.
#

if [[ $CI_WORKFLOW == "GitHub Release" ]];
then

"ci_scripts/CreateGitHubRelease.swift" "$CI_TAG" "$CI_ARCHIVE_PATH" "$GITHUB_TOKEN"
fi
4 changes: 1 addition & 3 deletions ci_scripts/ci_pre_xcodebuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

# ci_pre_xcodebuild.sh
# Phoenix
#
# Created by Tawa Nicolas on 06.03.23.
#

if [[ $CI_WORKFLOW == "GitHub Release" ]];
then
# Replace entitlements to disable Sandbox for the GitHub Release
cp -fr Phoenix/Phoenix.entitlements Phoenix/PhoenixRelease.entitlements
"ci_scripts/EnableGitHubReleaseTarget.swift" "Phoenix.xcodeproj/xcshareddata/xcschemes/Phoenix.xcscheme"
fi

0 comments on commit 6f01771

Please sign in to comment.