Skip to content

Commit

Permalink
Merge pull request #450 from nimblehq/feature/330-fix-signing
Browse files Browse the repository at this point in the history
[#330] Modify signing automatically when generating a project
  • Loading branch information
vnntsu authored Apr 28, 2023
2 parents 9544585 + 67d66ba commit e99d0dc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 45 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/test_upload_build_to_test_flight.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ name: Test Upload Build to TestFlight
### API_KEY_ID
### ISSUER_ID
### APPSTORE_CONNECT_API_KEY
### TEAM_ID

on:
pull_request
Expand Down Expand Up @@ -51,12 +52,13 @@ jobs:
MATCH_REPO: ${{ secrets.MATCH_REPO }}
API_KEY_ID: ${{ secrets.API_KEY_ID }}
ISSUER_ID: ${{ secrets.ISSUER_ID }}
TEAM_ID: ${{ secrets.TEAM_ID }}

- name: Set Up Test Project for App Store
run: bundle exec fastlane setUpTestProject

- name: Update Provision Profile
run: bundle exec fastlane updateProvisionSettings
run: bundle exec fastlane syncAppStoreCodeSigning
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASS }}

Expand Down
35 changes: 32 additions & 3 deletions fastlane/Constants/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ extension Constant {
enum Environment: String {

case staging = "Staging"
case production = ""
case production = "Production"

var productName: String { "\(Constant.projectName) \(rawValue)".trimmed }

var scheme: String { "\(Constant.projectName) \(rawValue)".trimmed }
var scheme: String {
switch self {
case .staging: return "\(Constant.projectName) \(rawValue)".trimmed
case .production: return Constant.projectName
}
}

var bundleId: String {
switch self {
Expand Down Expand Up @@ -116,13 +121,37 @@ extension Constant {

enum BuildType: String {

case development
case adHoc = "ad-hoc"
case appStore = "app-store"

var value: String { return rawValue }


var match: String {
switch self {
case .development: return "development"
case .adHoc: return "adhoc"
case .appStore: return "appstore"
}
}

var configuration: String {
switch self {
case .development: return "Debug"
case .adHoc, .appStore: return "Release"
}
}

var codeSignIdentity: String {
switch self {
case .development: return "iPhone Developer"
case .adHoc, . appStore: return "iPhone Distribution"
}
}

var method: String {
switch self {
case .development: return "Development"
case .adHoc: return "AdHoc"
case .appStore: return "AppStore"
}
Expand Down
38 changes: 16 additions & 22 deletions fastlane/Fastfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,43 @@ class Fastfile: LaneFile {

// MARK: - Code signing

func syncDevelopmentCodeSigningLane() {
func syncDevelopmentStagingCodeSigningLane() {
desc("Sync the Development match signing for the Staging build")
Match.syncCodeSigning(
type: .development,
appIdentifier: [Constant.stagingBundleId]
environment: .staging
)
}

func syncDevelopmentProductionCodeSigningLane() {
desc("Sync the Development match signing for the Production build")
Match.syncCodeSigning(
type: .development,
environment: .production
)
}

func syncAdHocStagingCodeSigningLane() {
desc("Sync the Ad Hoc match signing for the Staging build")
Match.syncCodeSigning(
type: .adHoc,
appIdentifier: [Constant.stagingBundleId]
environment: .staging
)
}

func syncAdHocProductionCodeSigningLane() {
desc("Sync the Ad Hoc match signing for the Production build")
Match.syncCodeSigning(
type: .adHoc,
appIdentifier: [Constant.productionBundleId]
environment: .production
)
}

func syncAppStoreCodeSigningLane() {
desc("Sync the App Store match signing for the Production build")
Match.syncCodeSigning(
type: .appStore,
appIdentifier: [Constant.productionBundleId]
environment: .production
)
}

Expand Down Expand Up @@ -80,7 +88,7 @@ class Fastfile: LaneFile {
}

func buildProductionAndUploadToFirebaseLane() {
desc("Build Staging app and upload to Firebase")
desc("Build Production app and upload to Firebase")

setAppVersion()
bumpBuild()
Expand Down Expand Up @@ -145,20 +153,6 @@ class Fastfile: LaneFile {
)
}

func updateProvisionSettingsLane() {
desc("Update Provision Profile")
syncAppStoreCodeSigningLane()
updateCodeSigningSettings(
path: Constant.projectPath,
useAutomaticSigning: .userDefined(false),
teamId: .userDefined(EnvironmentParser.string(key: "sigh_\(Constant.productionBundleId)_appstore_team-id")),
codeSignIdentity: .userDefined("iPhone Distribution"),
profileName: .userDefined(EnvironmentParser.string(
key: "sigh_\(Constant.productionBundleId)_appstore_profile-name"
))
)
}

func setUpTestProjectLane() {
desc("Disable Exempt Encryption")
Test.disableExemptEncryption()
Expand All @@ -176,8 +170,8 @@ class Fastfile: LaneFile {
teamId: .userDefined(Constant.teamId)
)

Match.syncCodeSigning(type: .development, appIdentifier: [], isForce: true)
Match.syncCodeSigning(type: .adHoc, appIdentifier: [], isForce: true)
Match.syncCodeSigning(type: .development, environment: .staging, isForce: true)
Match.syncCodeSigning(type: .adHoc, environment: .staging, isForce: true)
}

// MARK: - Utilities
Expand Down
2 changes: 1 addition & 1 deletion fastlane/Helpers/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum Build {
exportMethod: .userDefined(type.value),
exportOptions: .userDefined([
"provisioningProfiles": [
environment.bundleId: "match \(type.method) \(environment.bundleId)"
environment.bundleId: Match.createProfileName(type: type, environment: environment)
]
]),
buildPath: .userDefined(Constant.buildPath),
Expand Down
42 changes: 26 additions & 16 deletions fastlane/Helpers/Match.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

enum Match {

static func syncCodeSigning(type: MatchType, appIdentifier: [String], isForce: Bool = false) {
static func syncCodeSigning(type: Constant.BuildType, environment: Constant.Environment, isForce: Bool = false) {
if isCi() {
Keychain.create()
match(
type: type.value,
type: type.match,
readonly: .userDefined(!isForce),
appIdentifier: appIdentifier,
appIdentifier: [environment.bundleId],
username: .userDefined(Constant.userName),
teamId: .userDefined(Constant.teamId),
gitUrl: Constant.matchURL,
Expand All @@ -24,26 +24,36 @@ enum Match {
)
} else {
match(
type: type.value,
type: type.match,
readonly: .userDefined(!isForce),
appIdentifier: appIdentifier,
appIdentifier: [environment.bundleId],
username: .userDefined(Constant.userName),
teamId: .userDefined(Constant.teamId),
gitUrl: Constant.matchURL,
force: .userDefined(isForce)
)
}
updateCodeSigning(type: type, environment: environment)
}
}

extension Match {

enum MatchType: String {

case development
case adHoc = "adhoc"
case appStore = "appstore"

var value: String { return rawValue }

static func updateCodeSigning(type: Constant.BuildType, environment: Constant.Environment) {
// Update Code signing from automatic to manual
updateCodeSigningSettings(
path: Constant.projectPath,
useAutomaticSigning: .userDefined(false),
teamId: .userDefined(Constant.teamId),
targets: .userDefined([Constant.projectName]),
buildConfigurations: .userDefined([Self.createBuildConfiguration(type: type, environment: environment)]),
codeSignIdentity: .userDefined(type.codeSignIdentity),
profileName: .userDefined(Self.createProfileName(type: type, environment: environment))
)
}

static func createBuildConfiguration(type: Constant.BuildType, environment: Constant.Environment) -> String {
"\(type.configuration) \(environment.rawValue)"
}

static func createProfileName(type: Constant.BuildType, environment: Constant.Environment) -> String {
"match \(type.method) \(environment.bundleId)"
}
}
4 changes: 2 additions & 2 deletions set_up_test_testflight.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
echo "import('./Tests/Fastfile')" | cat - fastlane/Fastfile | tee fastlane/Fastfile &> /dev/null

readonly CONSTANT_TEAM_ID="<#teamId#>"
readonly CONSTANT_API_KEY_ID="<#API_KEY_ID#>"
readonly CONSTANT_ISSUER_ID="<#ISSUER_ID#>"
readonly CONSTANT_MATCH_REPO="[email protected]:{organization}\/{repo}.git"

readonly WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
MATCH_REPO_ESCAPED=$(echo "${MATCH_REPO//\//\\\/}")

LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_TEAM_ID/$TEAM_ID/g" {} +
LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_API_KEY_ID/$API_KEY_ID/g" {} +
LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_ISSUER_ID/$ISSUER_ID/g" {} +
LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_MATCH_REPO/$MATCH_REPO_ESCAPED/g" {} +

0 comments on commit e99d0dc

Please sign in to comment.