Skip to content

Commit

Permalink
[#546] Support adding new devices directly from Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
markgravity committed Mar 13, 2024
1 parent 11790f1 commit 48e388f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
67 changes: 67 additions & 0 deletions .github/project_workflows/add_device_profile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Test Add device and regenerate profiles with fastlane match

# SECRETS needed:
### SSH_PRIVATE_KEY for the match Repo
### MATCH_PASSWORD
### APPSTORE_CONNECT_API_KEY
### API_KEY_ID
### ISSUER_ID

on:
pull_request:
workflow_dispatch:
inputs:
devices:
description: 'JSON of devices. `{"Luka iPhone 6": "1234567890123456789012345678901234567890","Felix iPad Air 2": "abcdefghijklmnopqrstvuwxyzabcdefghijklmn"}`'
required: true
type: string
platform:
description: 'The platform'
required: true
default: 'ios'
type: choice
options:
- ios
- mac

jobs:
create_files:
name: Create certificates and profiles
runs-on: macOS-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Cache Pods
uses: actions/cache@v3
id: cocoapodCache
with:
path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
${{ runner.os }}-pods-
- name: Bundle install
run: bundle install

- name: Add device and regenerate profiles with match
run: bundle exec fastlane addDevicesGenerateProfiles
env:
MATCH_PASSWORD: ${{ secrets.MATCH_PASS }}
DEVICES: ${{ inputs.devices }}
APPSTORE_CONNECT_API_KEY: ${{ secrets.APPSTORE_CONNECT_API_KEY }}
API_KEY_ID: ${{ secrets.API_KEY_ID }}
ISSUER_ID: ${{ secrets.ISSUER_ID }}
PLATFORM: ${{ inputs.platform }}

- name: Clean up keychain
if: ${{ always() }}
run: bundle exec fastlane remove_keychain
continue-on-error: true
20 changes: 14 additions & 6 deletions fastlane/Constants/Constant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,20 @@ enum Constant {
static let appleProductionTeamId = "<#teamId#>"
static let keychainName = "{PROJECT_NAME}_keychain"
static let matchURL = "[email protected]:{organization}/{repo}.git"
static let apiKey: [String: Any] = [
"key_id" : Secret.appStoreKeyIdKey,
"issuer_id": Secret.appStoreIssuerIdKey,
"key": Secret.appstoreConnectAPIKey,
"in_house": false
]
static let apiKey: [String: Any] = {
var key = Secret.appstoreConnectAPIKey
if let data = Data(base64Encoded: Secret.appstoreConnectAPIKey),
let decodedKey = String(data: data, encoding: .utf8) {
key = decodedKey
}

return [
"key_id" : Secret.appStoreKeyIdKey,
"issuer_id": Secret.appStoreIssuerIdKey,
"key": key,
"in_house": false
]
}()

// MARK: - Path

Expand Down
4 changes: 4 additions & 0 deletions fastlane/Constants/Secret.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ enum Secret {
static let appStoreIssuerIdKey = EnvironmentParser.string(key: "ISSUER_ID")

static let bumpAppStoreBuildNumber = EnvironmentParser.bool(key: "BUMP_APP_STORE_BUILD_NUMBER")

static let devices = EnvironmentParser.string(key: "DEVICES")

static let platform = EnvironmentParser.string(key: "PLATFORM")
}
18 changes: 18 additions & 0 deletions fastlane/Fastfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,24 @@ class Fastfile: LaneFile {
Match.syncCodeSigning(type: .adHoc, environment: .staging, isForce: true)
}

func addDevicesGenerateProfilesLane() {
desc("Add device and regenerate profiles with match")

guard let data = Secret.devices.data(using: .utf8),
let devices = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else {
return
}
registerDevices(
devices: .userDefined(devices),
apiKey: .userDefined(Constant.apiKey),
teamId: .userDefined(Constant.appleStagingTeamId),
platform: Secret.platform
)

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

// MARK: - Utilities

func cleanUpOutputLane() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "lane testLane"
argument = "lane addDevicesGenerateProfilesLane"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
Expand Down

0 comments on commit 48e388f

Please sign in to comment.