Skip to content

Commit cf9a44a

Browse files
authored
Fix prototype_build_details_comment action when used outside FAD context (#642)
2 parents 4561a32 + 7ad05fd commit cf9a44a

File tree

3 files changed

+70
-86
lines changed

3 files changed

+70
-86
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ _None_
1414

1515
### Bug Fixes
1616

17-
_None_
17+
- Fix an issue where `prototype_build_details_comment` added some unexpected metadata rows in the comment table if we didn't use `firebase_app_distribution` (e.g. for Prototype Builds uploaded to S3 and not using FAD) [#642]
1818

1919
### Internal Changes
2020

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,15 @@ def self.from_lane_context
102102
# @return [Hash<String, String>] A hash of all the metadata, consolidated from both the explicit and the implicit ones
103103
#
104104
def self.generate_metadata_hash(params:, release_info:)
105+
# Add explicit metadata provided by the caller
105106
metadata = params[:metadata]&.transform_keys(&:to_s) || {}
106107

107108
# Add Firebase-specific metadata if available
108-
metadata['Build Number'] ||= "<code>#{release_info&.build_version}</code>"
109-
metadata['Version'] ||= "<code>#{release_info&.display_version}</code>"
110-
metadata[release_info&.os == 'ios' ? 'Bundle ID' : 'Application ID'] ||= "<code>#{release_info&.bundle_id}</code>"
109+
unless release_info.nil?
110+
metadata['Build Number'] ||= "<code>#{release_info.build_version}</code>"
111+
metadata['Version'] ||= "<code>#{release_info.display_version}</code>"
112+
metadata[release_info.os == 'ios' ? 'Bundle ID' : 'Application ID'] ||= "<code>#{release_info.bundle_id}</code>"
113+
end
111114

112115
# Add git metadata
113116
metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash]

spec/prototype_build_details_comment_action_spec.rb

Lines changed: 63 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -111,27 +111,65 @@
111111
end
112112
end
113113

114-
describe 'app_icon' do
114+
describe 'app_icon handling' do
115115
context 'when providing an URL' do
116116
it 'includes the icon in the intro text' do
117-
comment = run_described_fastlane_action(
118-
app_display_name: 'My Cool App',
119-
app_icon: 'https://localhost/foo.png',
120-
download_url: 'https://localhost/foo.apk'
121-
)
122-
expect(comment).to include "<img align='top' src='https://localhost/foo.png' width='20px' alt='App Icon' />📲 "
117+
comment = run_described_fastlane_action(base_params.merge(app_icon: valid_app_icon_url))
118+
expect(comment).to include "<img align='top' src='#{valid_app_icon_url}' width='20px' alt='App Icon' />📲 "
123119
end
124120
end
125121

126122
context 'when providing an emoji code' do
127123
it 'includes the icon in the intro text' do
128-
comment = run_described_fastlane_action(
129-
app_display_name: 'My Cool App',
130-
app_icon: ':jetpack:',
131-
download_url: 'https://localhost/foo.apk'
132-
)
124+
comment = run_described_fastlane_action(base_params.merge(app_icon: ':jetpack:'))
133125
expect(comment).to include "<img align='top' src='https://raw.githubusercontent.com/buildkite/emojis/main/img-buildkite-64/jetpack.png' width='20px' alt='App Icon' />📲 "
134126
end
127+
128+
it 'handles emoji codes with special characters' do
129+
comment = run_described_fastlane_action(base_params.merge(app_icon: ':plus-one:'))
130+
expect(comment).to include 'plus-one.png'
131+
end
132+
end
133+
134+
context 'when no icon is provided' do
135+
context 'when using Firebase App Distribution' do
136+
let(:firebase_release_info) do
137+
{
138+
displayVersion: '28.7',
139+
buildVersion: '1287003',
140+
testingUri: 'https://appdistribution.firebase.google.com/testerapps/1:123456:ios:abcdef/releases/xyz',
141+
firebaseConsoleUri: 'https://console.firebase.google.com/project/apps-test/appdistribution/app/ios:com.example.myapp/releases/xyz'
142+
}
143+
end
144+
145+
before do
146+
stub_const('Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE', :firebase_app_distro_release)
147+
allow(Fastlane::Actions).to receive(:lane_context).and_return({ firebase_app_distro_release: firebase_release_info })
148+
end
149+
150+
it 'uses the firebase icon' do
151+
comment = run_described_fastlane_action(app_display_name: 'My App')
152+
expect(comment).to include 'firebase.png'
153+
end
154+
end
155+
156+
context 'when using a Firebase download URL' do
157+
it 'uses the firebase icon' do
158+
comment = run_described_fastlane_action(
159+
app_display_name: 'My App',
160+
download_url: 'https://appdistribution.firebase.google.com/testerapps/1:123456:ios:abcdef/releases/xyz'
161+
)
162+
expect(comment).to include 'firebase.png'
163+
end
164+
end
165+
166+
context 'when using a non-Firebase download URL' do
167+
it 'does not include any icon' do
168+
comment = run_described_fastlane_action(base_params.merge(app_icon: nil))
169+
expect(comment).not_to include 'firebase.png'
170+
expect(comment).to match(/^<p>📲 You can test/)
171+
end
172+
end
135173
end
136174
end
137175

@@ -301,6 +339,17 @@
301339
expect(comment).to include "<td><b>Direct Download</b></td><td><a href='https://example.com/myapp.apk'><code>myapp.apk</code></a></td>"
302340
end
303341

342+
it 'does not include rows for FAD metadata' do
343+
comment = run_described_fastlane_action(
344+
app_display_name: 'My App',
345+
download_url: 'https://example.com/myapp.apk'
346+
)
347+
expect(comment).not_to include %r{<td>.*Build Number.*</td>}
348+
expect(comment).not_to include %r{<td>.*Version.*</td>}
349+
expect(comment).not_to include %r{<td>.*Bundle ID.*</td>}
350+
expect(comment).not_to include %r{<td>.*Application ID.*</td>}
351+
end
352+
304353
it 'does not include any default footnote if no explicit footnote is provided' do
305354
comment = run_described_fastlane_action(
306355
app_display_name: 'My App',
@@ -346,15 +395,12 @@
346395
<p><img align='top' src='https://raw.githubusercontent.com/buildkite/emojis/main/img-buildkite-64/jetpack.png' width='20px' alt='App Icon' />📲 You can test the changes from this Pull Request in <b>The Best App</b> by scanning the QR code below to install the corresponding build.</p>
347396
<table>
348397
<tr>
349-
<td rowspan='9' width='260px'><img src='https://api.qrserver.com/v1/create-qr-code/?size=500x500&qzone=4&data=https%3A%2F%2Fexample.com%2Fbestapp.apk' width='250' height='250' /></td>
398+
<td rowspan='6' width='260px'><img src='https://api.qrserver.com/v1/create-qr-code/?size=500x500&qzone=4&data=https%3A%2F%2Fexample.com%2Fbestapp.apk' width='250' height='250' /></td>
350399
<td><b>App Name</b></td><td>The Best App</td>
351400
</tr>
352401
<tr><td><b>Version Name</b></td><td>28.2</td></tr>
353402
<tr><td><b>Version Code</b></td><td>1280200108</td></tr>
354403
<tr><td><b>Flavor</b></td><td>Debug</td></tr>
355-
<tr><td><b>Build Number</b></td><td><code></code></td></tr>
356-
<tr><td><b>Version</b></td><td><code></code></td></tr>
357-
<tr><td><b>Application ID</b></td><td><code></code></td></tr>
358404
<tr><td><b>Commit</b></td><td>a1b2c3f</td></tr>
359405
<tr><td><b>Direct Download</b></td><td><a href='https://example.com/bestapp.apk'><code>bestapp.apk</code></a></td></tr>
360406
</table>
@@ -379,14 +425,11 @@
379425
<details><summary>📲 You can test the changes from this Pull Request in <b>The Best App</b> by scanning the QR code below to install the corresponding build.</summary>
380426
<table>
381427
<tr>
382-
<td rowspan='8' width='260px'><img src='https://api.qrserver.com/v1/create-qr-code/?size=500x500&qzone=4&data=https%3A%2F%2Fexample.com%2Fbestapp.apk' width='250' height='250' /></td>
428+
<td rowspan='5' width='260px'><img src='https://api.qrserver.com/v1/create-qr-code/?size=500x500&qzone=4&data=https%3A%2F%2Fexample.com%2Fbestapp.apk' width='250' height='250' /></td>
383429
<td><b>App Name</b></td><td>The Best App</td>
384430
</tr>
385431
<tr><td><b>Version Name</b></td><td>28.2</td></tr>
386432
<tr><td><b>Version Code</b></td><td>1280200108</td></tr>
387-
<tr><td><b>Build Number</b></td><td><code></code></td></tr>
388-
<tr><td><b>Version</b></td><td><code></code></td></tr>
389-
<tr><td><b>Application ID</b></td><td><code></code></td></tr>
390433
<tr><td><b>Commit</b></td><td>a1b2c3f</td></tr>
391434
<tr><td><b>Direct Download</b></td><td><a href='https://example.com/bestapp.apk'><code>bestapp.apk</code></a></td></tr>
392435
</table>
@@ -395,66 +438,4 @@
395438
EXPECTED_COMMENT
396439
end
397440
end
398-
399-
describe 'app_icon handling' do
400-
context 'when providing an URL' do
401-
it 'includes the icon in the intro text' do
402-
comment = run_described_fastlane_action(base_params.merge(app_icon: valid_app_icon_url))
403-
expect(comment).to include "<img align='top' src='#{valid_app_icon_url}' width='20px' alt='App Icon' />📲 "
404-
end
405-
end
406-
407-
context 'when providing an emoji code' do
408-
it 'includes the icon in the intro text' do
409-
comment = run_described_fastlane_action(base_params.merge(app_icon: ':jetpack:'))
410-
expect(comment).to include "<img align='top' src='https://raw.githubusercontent.com/buildkite/emojis/main/img-buildkite-64/jetpack.png' width='20px' alt='App Icon' />📲 "
411-
end
412-
413-
it 'handles emoji codes with special characters' do
414-
comment = run_described_fastlane_action(base_params.merge(app_icon: ':plus-one:'))
415-
expect(comment).to include 'plus-one.png'
416-
end
417-
end
418-
419-
context 'when no icon is provided' do
420-
context 'when using Firebase App Distribution' do
421-
let(:firebase_release_info) do
422-
{
423-
displayVersion: '28.7',
424-
buildVersion: '1287003',
425-
testingUri: 'https://appdistribution.firebase.google.com/testerapps/1:123456:ios:abcdef/releases/xyz',
426-
firebaseConsoleUri: 'https://console.firebase.google.com/project/apps-test/appdistribution/app/ios:com.example.myapp/releases/xyz'
427-
}
428-
end
429-
430-
before do
431-
stub_const('Fastlane::Actions::SharedValues::FIREBASE_APP_DISTRO_RELEASE', :firebase_app_distro_release)
432-
allow(Fastlane::Actions).to receive(:lane_context).and_return({ firebase_app_distro_release: firebase_release_info })
433-
end
434-
435-
it 'uses the firebase icon' do
436-
comment = run_described_fastlane_action(app_display_name: 'My App')
437-
expect(comment).to include 'firebase.png'
438-
end
439-
end
440-
441-
context 'when using a Firebase download URL' do
442-
it 'uses the firebase icon' do
443-
comment = run_described_fastlane_action(
444-
app_display_name: 'My App',
445-
download_url: 'https://appdistribution.firebase.google.com/testerapps/1:123456:ios:abcdef/releases/xyz'
446-
)
447-
expect(comment).to include 'firebase.png'
448-
end
449-
end
450-
451-
context 'when using a non-Firebase download URL' do
452-
it 'does not include any icon' do
453-
comment = run_described_fastlane_action(base_params.merge(app_icon: nil))
454-
expect(comment).not_to include 'firebase.png'
455-
expect(comment).to match(/^<p>📲 You can test/)
456-
end
457-
end
458-
end
459-
end
460441
end

0 commit comments

Comments
 (0)