Skip to content

Commit 9efc626

Browse files
committed
fix: address Copilot code review suggestions
- Extract duplicated API key and build config into helper methods in Fastfile - Use plutil for robust Info.plist parsing instead of fragile regex - Set restrictive permissions (600) on API key file for improved security - Reduce code duplication across lanes
1 parent fc22ce7 commit 9efc626

File tree

2 files changed

+37
-52
lines changed

2 files changed

+37
-52
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ jobs:
3838
- name: Check version and create tag if needed
3939
id: check
4040
run: |
41-
# Get current version from Info.plist
42-
CURRENT_VERSION=$(grep -A1 "CFBundleShortVersionString" V2er/Info.plist | tail -1 | sed 's/.*<string>\(.*\)<\/string>/\1/' | xargs)
43-
CURRENT_BUILD=$(grep -A1 "CFBundleVersion" V2er/Info.plist | tail -1 | sed 's/.*<string>\(.*\)<\/string>/\1/' | xargs)
41+
# Get current version from Info.plist using plutil for robust XML parsing
42+
CURRENT_VERSION=$(/usr/bin/plutil -extract CFBundleShortVersionString xml1 -o - V2er/Info.plist | grep '<string>' | sed 's/.*<string>\(.*\)<\/string>.*/\1/' | xargs)
43+
CURRENT_BUILD=$(/usr/bin/plutil -extract CFBundleVersion xml1 -o - V2er/Info.plist | grep '<string>' | sed 's/.*<string>\(.*\)<\/string>.*/\1/' | xargs)
4444
4545
echo "Current version: $CURRENT_VERSION (build $CURRENT_BUILD)"
4646
@@ -125,6 +125,7 @@ jobs:
125125
run: |
126126
mkdir -p ~/.appstoreconnect/private_keys
127127
echo "$APP_STORE_CONNECT_API_KEY_BASE64" | base64 --decode > ~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
128+
chmod 600 ~/.appstoreconnect/private_keys/AuthKey_${APP_STORE_CONNECT_KEY_ID}.p8
128129
129130
# Set environment variables for Fastlane
130131
echo "APP_STORE_CONNECT_API_KEY_KEY_ID=$APP_STORE_CONNECT_KEY_ID" >> $GITHUB_ENV

fastlane/Fastfile

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,18 @@
33
default_platform(:ios)
44

55
platform :ios do
6-
desc "Sync certificates and provisioning profiles"
7-
lane :sync_certificates do
8-
match(
9-
type: "appstore",
10-
readonly: is_ci,
11-
app_identifier: "v2er.app",
12-
git_url: ENV["MATCH_GIT_URL"] || "git@github.com:graycreate/certificates-v2er-iOS.git"
13-
)
14-
end
15-
16-
desc "Build and upload to TestFlight"
17-
lane :beta do
18-
# Ensure we have the latest certificates
19-
sync_certificates
20-
21-
# Get App Store Connect API key from environment
22-
api_key = app_store_connect_api_key(
6+
# Helper method to get App Store Connect API key
7+
private_lane :get_api_key do
8+
app_store_connect_api_key(
239
key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"],
2410
issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"],
2511
key_filepath: ENV["APP_STORE_CONNECT_API_KEY_KEY"],
2612
in_house: false
2713
)
14+
end
2815

29-
# Build the app
16+
# Helper method for building the app
17+
private_lane :build_ipa do
3018
build_app(
3119
scheme: "V2er",
3220
export_method: "app-store",
@@ -39,6 +27,28 @@ platform :ios do
3927
output_directory: "./build",
4028
output_name: "V2er.ipa"
4129
)
30+
end
31+
32+
desc "Sync certificates and provisioning profiles"
33+
lane :sync_certificates do
34+
match(
35+
type: "appstore",
36+
readonly: is_ci,
37+
app_identifier: "v2er.app",
38+
git_url: ENV["MATCH_GIT_URL"] || "git@github.com:graycreate/certificates-v2er-iOS.git"
39+
)
40+
end
41+
42+
desc "Build and upload to TestFlight"
43+
lane :beta do
44+
# Ensure we have the latest certificates
45+
sync_certificates
46+
47+
# Get App Store Connect API key
48+
api_key = get_api_key
49+
50+
# Build the app
51+
build_ipa
4252

4353
# Upload to TestFlight
4454
upload_to_testflight(
@@ -64,27 +74,11 @@ platform :ios do
6474
# Ensure we have the latest certificates
6575
sync_certificates
6676

67-
# Get App Store Connect API key from environment
68-
api_key = app_store_connect_api_key(
69-
key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"],
70-
issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"],
71-
key_filepath: ENV["APP_STORE_CONNECT_API_KEY_KEY"],
72-
in_house: false
73-
)
77+
# Get App Store Connect API key
78+
api_key = get_api_key
7479

7580
# Build the app
76-
build_app(
77-
scheme: "V2er",
78-
export_method: "app-store",
79-
export_options: {
80-
provisioningProfiles: {
81-
"v2er.app" => "match AppStore v2er.app"
82-
}
83-
},
84-
clean: true,
85-
output_directory: "./build",
86-
output_name: "V2er.ipa"
87-
)
81+
build_ipa
8882

8983
# Upload to App Store Connect
9084
upload_to_app_store(
@@ -98,12 +92,7 @@ platform :ios do
9892

9993
desc "Create a new version on App Store Connect"
10094
lane :create_app_version do |options|
101-
api_key = app_store_connect_api_key(
102-
key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"],
103-
issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"],
104-
key_filepath: ENV["APP_STORE_CONNECT_API_KEY_KEY"],
105-
in_house: false
106-
)
95+
api_key = get_api_key
10796

10897
deliver(
10998
api_key: api_key,
@@ -116,12 +105,7 @@ platform :ios do
116105

117106
desc "Download metadata from App Store Connect"
118107
lane :download_metadata do
119-
api_key = app_store_connect_api_key(
120-
key_id: ENV["APP_STORE_CONNECT_API_KEY_KEY_ID"],
121-
issuer_id: ENV["APP_STORE_CONNECT_API_KEY_ISSUER_ID"],
122-
key_filepath: ENV["APP_STORE_CONNECT_API_KEY_KEY"],
123-
in_house: false
124-
)
108+
api_key = get_api_key
125109

126110
download_dsyms(api_key: api_key)
127111

0 commit comments

Comments
 (0)