From efc3e66e9287e30c4c4f310c5b40e4cb6732367b Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 20:20:55 +0100 Subject: [PATCH 01/23] Add `prototype_build_details_comment` action --- .../prototype_build_details_comment_action.rb | 104 ++++++++++++++++++ ...otype_build_details_comment_action_spec.rb | 94 ++++++++++++++++ 2 files changed, 198 insertions(+) create mode 100644 lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb create mode 100644 spec/prototype_build_details_comment_action_spec.rb diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb new file mode 100644 index 000000000..f78a9a961 --- /dev/null +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -0,0 +1,104 @@ +module Fastlane + module Actions + class PrototypeBuildDetailsCommentAction < Action + def self.run(params) + appcenter_org_name = params[:appcenter_org_name] + appcenter_app_name = params[:appcenter_app_name] + appcenter_release_id = params[:appcenter_release_id] + commit = params[:commit] || other_action.last_git_commit[:abbreviated_commit_hash] + + metadata = params[:metadata] # e.g. {'Build Config':… , 'Version': …, 'Short Version': …} + + install_url = "https://install.appcenter.ms/orgs/#{appcenter_org_name}/apps/#{appcenter_app_name}/releases/#{appcenter_release_id}" + qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" + + metadata_rows = metadata.map do |key, value| + "#{key}#{value}" + end.join("\n") + + <<~COMMENT_BODY +

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding #{appcenter_app_name} build from App Center.

+ + + + + + #{metadata_rows} + + +
App#{appcenter_app_name}
App Center BuildBuild \##{appcenter_release_id}
Commit#{commit}
+ #{params[:footnote]} + COMMENT_BODY + end + + ##################################################### + # @!group Documentation + ##################################################### + + def self.description + 'Generates the nicely-formatted string providing all the details of a prototype build, ready to be used as a PR comment (e.g. via `comment_on_pr`).' + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new( + key: :appcenter_org_name, + env_name: 'APPCENTER_OWNER_NAME', # Same as the one used by the `appcenter_upload` action + description: 'The name of the organization in App Center', + type: String + ), + FastlaneCore::ConfigItem.new( + key: :appcenter_app_name, + env_name: 'APPCENTER_APP_NAME', # Same as the one used by the `appcenter_upload` action + description: 'The name of the app in App Center', + type: String + ), + FastlaneCore::ConfigItem.new( + key: :appcenter_release_id, + env_name: 'FL_PROTOTYPE_BUILD_APPCENTER_RELEASE_ID', + description: 'The release ID/Number in App Center', + type: Integer + ), + FastlaneCore::ConfigItem.new( + key: :metadata, + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_METADATA', + description: 'All additional metadata (as key/value pairs) you want to include in the HTML table of the comment', + type: Hash, + optional: true, + default_value: {} + ), + FastlaneCore::ConfigItem.new( + key: :footnote, + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_FOOTNOTE', + description: 'Optional footnote to add below the HTML table of the comment', + type: String, + default_value: 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + ), + FastlaneCore::ConfigItem.new( + key: :commit, + env_name: 'BUILDKITE_COMMIT', + description: 'The commit this prototype build was build from; usually not passed explicitly, but derived from the environment variable instead', + type: String, + optional: true + ), + ] + end + + def self.return_type + :string + end + + def self.return_value + 'The HTML comment containing all the relevant info about a Prototype build published to App Center' + end + + def self.authors + ['Automattic'] + end + + def self.is_supported?(platform) + true + end + end + end +end diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb new file mode 100644 index 000000000..97252286e --- /dev/null +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -0,0 +1,94 @@ +require_relative './spec_helper' + +describe Fastlane::Actions::PrototypeBuildDetailsCommentAction do + before do + ENV['APPCENTER_OWNER_NAME'] = 'My-Org' + ENV['BUILDKITE_COMMIT'] = 'a1b2c3f' + end + + it 'generates the proper AppCenter link and QR code given an org, app name and release ID' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include "Build #1337" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' + end + + it 'includes the commit as part of the default rows' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include 'Commita1b2c3f' + end + + it 'correctly includes additional metadata when some are provided' do + metadata = { + 'Version:Short': '28.1', + 'Version:Long': '281003', + 'Build Config': 'Prototype' + } + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337, + metadata: metadata + ) + expect(comment).to include "" + expect(comment).to include 'Version:Short28.1' + expect(comment).to include 'Version:Long281003' + expect(comment).to include 'Build ConfigPrototype' + end + + it 'includes the default footnote by default' do + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + end + + it 'includes the provided footnote if any' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337, + footnote: 'Note that Google Sign-In in not available in those builds' + ) + expect(comment).to include 'Note that Google Sign-In in not available in those builds' + end + + it 'generates a fully formatted HTML comment with all the information provided' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108', + Flavor: 'Celray', + Panel: false + } + + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'BestApp', + appcenter_release_id: 8888, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

+ + + + + + + + + + + +
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
Panelfalse
App Center BuildBuild \#8888
Commita1b2c3f
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end +end From 13116a9380685d40fd3a8e8de39c43ad9aec7fb6 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 20:30:15 +0100 Subject: [PATCH 02/23] Add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70e29f095..3e2cf2adf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - Add new `buildkite_annotate` action to add/remove annotations from the current build. [#442] - Add new `buildkite_metadata` action to set/get metadata from the current build. [#442] +- Add new `prototype_build_details_comment` action to make it easier to generate the HTML comment about Prototype Builds in PRs. [#449] ### Bug Fixes From 0af1b8f3fdff4bcf622e71b378bd13ef1810d312 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 20:45:05 +0100 Subject: [PATCH 03/23] Don't wrap arbitrary metadata in `` tags --- .../prototype_build_details_comment_action.rb | 2 +- .../prototype_build_details_comment_action_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index f78a9a961..54ac55c44 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -13,7 +13,7 @@ def self.run(params) qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" metadata_rows = metadata.map do |key, value| - "#{key}#{value}" + "#{key}#{value}" end.join("\n") <<~COMMENT_BODY diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 97252286e..0d74c15c2 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -35,9 +35,9 @@ metadata: metadata ) expect(comment).to include "" - expect(comment).to include 'Version:Short28.1' - expect(comment).to include 'Version:Long281003' - expect(comment).to include 'Build ConfigPrototype' + expect(comment).to include 'Version:Short28.1' + expect(comment).to include 'Version:Long281003' + expect(comment).to include 'Build ConfigPrototype' end it 'includes the default footnote by default' do @@ -81,10 +81,10 @@ AppBestApp - Version:Short28.2 - Version:Long28.2.0.108 - FlavorCelray - Panelfalse + Version:Short28.2 + Version:Long28.2.0.108 + FlavorCelray + Panelfalse App Center BuildBuild \#8888 Commita1b2c3f From 57d2e44b49966948f1c462dc90f9601b86b879ef Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 20:54:17 +0100 Subject: [PATCH 04/23] Add ability to hide the table behind `
` --- .../prototype_build_details_comment_action.rb | 19 +- ...otype_build_details_comment_action_spec.rb | 191 +++++++++++------- 2 files changed, 130 insertions(+), 80 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 54ac55c44..e03c274c0 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -6,18 +6,16 @@ def self.run(params) appcenter_app_name = params[:appcenter_app_name] appcenter_release_id = params[:appcenter_release_id] commit = params[:commit] || other_action.last_git_commit[:abbreviated_commit_hash] - metadata = params[:metadata] # e.g. {'Build Config':… , 'Version': …, 'Short Version': …} install_url = "https://install.appcenter.ms/orgs/#{appcenter_org_name}/apps/#{appcenter_app_name}/releases/#{appcenter_release_id}" qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" - metadata_rows = metadata.map do |key, value| "#{key}#{value}" end.join("\n") - <<~COMMENT_BODY -

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding #{appcenter_app_name} build from App Center.

+ intro = "📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding #{appcenter_app_name} build from App Center." + body = <<~COMMENT_BODY @@ -29,6 +27,12 @@ def self.run(params)
#{params[:footnote]} COMMENT_BODY + + if params[:fold] + "
#{intro}
\n\n#{body}\n" + else + "

#{intro}

\n#{body}" + end end ##################################################### @@ -59,6 +63,13 @@ def self.available_options description: 'The release ID/Number in App Center', type: Integer ), + FastlaneCore::ConfigItem.new( + key: :fold, + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_FOLD', + description: 'If true, will wrap the HTML table inside a
block (hidden by default)', + type: Boolean, + default_value: false + ), FastlaneCore::ConfigItem.new( key: :metadata, env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_METADATA', diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 0d74c15c2..7a4636e82 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -6,89 +6,128 @@ ENV['BUILDKITE_COMMIT'] = 'a1b2c3f' end - it 'generates the proper AppCenter link and QR code given an org, app name and release ID' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include "Build #1337" - expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' - end + describe 'expected info is included' do + it 'generates the proper AppCenter link and QR code given an org, app name and release ID' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include "Build #1337" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' + end - it 'includes the commit as part of the default rows' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include 'Commita1b2c3f' - end + it 'includes the commit as part of the default rows' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include 'Commita1b2c3f' + end - it 'correctly includes additional metadata when some are provided' do - metadata = { - 'Version:Short': '28.1', - 'Version:Long': '281003', - 'Build Config': 'Prototype' - } - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337, - metadata: metadata - ) - expect(comment).to include "" - expect(comment).to include 'Version:Short28.1' - expect(comment).to include 'Version:Long281003' - expect(comment).to include 'Build ConfigPrototype' - end + it 'correctly includes additional metadata when some are provided' do + metadata = { + 'Version:Short': '28.1', + 'Version:Long': '281003', + 'Build Config': 'Prototype' + } + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337, + metadata: metadata + ) + expect(comment).to include "" + expect(comment).to include 'Version:Short28.1' + expect(comment).to include 'Version:Long281003' + expect(comment).to include 'Build ConfigPrototype' + end - it 'includes the default footnote by default' do - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' - end + it 'includes the default footnote by default' do + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337 + ) + expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + end - it 'includes the provided footnote if any' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337, - footnote: 'Note that Google Sign-In in not available in those builds' - ) - expect(comment).to include 'Note that Google Sign-In in not available in those builds' + it 'includes the provided footnote if any' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337, + footnote: 'Note that Google Sign-In in not available in those builds' + ) + expect(comment).to include 'Note that Google Sign-In in not available in those builds' + end end - it 'generates a fully formatted HTML comment with all the information provided' do - metadata = { - 'Version:Short': '28.2', - 'Version:Long': '28.2.0.108', - Flavor: 'Celray', - Panel: false - } + describe 'full comment' do + it 'generates a standard HTML table comment by default, with all the information provided' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108', + Flavor: 'Celray' + } + + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'BestApp', + appcenter_release_id: 8888, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

+ + + + + + + + + + +
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
App Center BuildBuild \#8888
Commita1b2c3f
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end + + it 'generates a HTML table in a spoiler block if fold is true' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108', + Flavor: 'Celray', + Configuration: 'Debug' + } - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'BestApp', - appcenter_release_id: 8888, - metadata: metadata, - footnote: 'Note: Google Sign-In in not available in those builds' - ) + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'BestApp', + appcenter_release_id: 8888, + fold: true, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) - expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

- - - - - - - - - - - -
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
Panelfalse
App Center BuildBuild \#8888
Commita1b2c3f
- Note: Google Sign-In in not available in those builds - EXPECTED_COMMENT + expect(comment).to eq <<~EXPECTED_COMMENT +
📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.
+ + + + + + + + + + + + +
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
App Center BuildBuild \#8888
Commita1b2c3f
+ Note: Google Sign-In in not available in those builds +
+ EXPECTED_COMMENT + end end end From 9946b4a91ba2b0c93ea6e020920fefd884b2fd55 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:13:23 +0100 Subject: [PATCH 05/23] Add ability to provide a direct download link Useful for APK files for example. PS: be mindful that providing a public link accessible without any access control (e.g. from a cloudfront public API or similar) means users outside Automattic might be able to download the APK even if they are not invited to App Center. Up to you to decide if that is ok or not when you choose to use this parameter. --- .../prototype_build_details_comment_action.rb | 21 ++++++++-- ...otype_build_details_comment_action_spec.rb | 42 +++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index e03c274c0..1bda99034 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -2,17 +2,24 @@ module Fastlane module Actions class PrototypeBuildDetailsCommentAction < Action def self.run(params) + # Get Input Parameters appcenter_org_name = params[:appcenter_org_name] appcenter_app_name = params[:appcenter_app_name] appcenter_release_id = params[:appcenter_release_id] commit = params[:commit] || other_action.last_git_commit[:abbreviated_commit_hash] + metadata = params[:metadata] # e.g. {'Build Config':… , 'Version': …, 'Short Version': …} + direct_link = params[:download_url] + unless direct_link.nil? + metadata['Direct Link'] = "#{File.basename(direct_link)}" + end + # Build the comment parts install_url = "https://install.appcenter.ms/orgs/#{appcenter_org_name}/apps/#{appcenter_app_name}/releases/#{appcenter_release_id}" qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" - metadata_rows = metadata.map do |key, value| + metadata_rows = metadata.compact.map do |key, value| "#{key}#{value}" - end.join("\n") + end intro = "📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding #{appcenter_app_name} build from App Center." body = <<~COMMENT_BODY @@ -21,7 +28,7 @@ def self.run(params) App#{appcenter_app_name} - #{metadata_rows} + #{metadata_rows.join("\n")} App Center BuildBuild \##{appcenter_release_id} Commit#{commit} @@ -63,6 +70,14 @@ def self.available_options description: 'The release ID/Number in App Center', type: Integer ), + FastlaneCore::ConfigItem.new( + key: :download_url, + env_name: 'FL_PROTOTYPE_BUILD_DOWNLOAD_URL', + description: 'The URL to download the build directly; e.g. a public link to the `.apk` file; you might use `lane_context[SharedValues::APPCENTER_DOWNLOAD_LINK]` for this for example', + type: String, + optional: true, + default_value: nil + ), FastlaneCore::ConfigItem.new( key: :fold, env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_FOLD', diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 7a4636e82..a9cc76438 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -41,6 +41,16 @@ expect(comment).to include 'Build ConfigPrototype' end + it 'includes the direct link if one is provided' do + comment = run_described_fastlane_action( + appcenter_app_name: 'MyApp', + appcenter_release_id: 1337, + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include "" + expect(comment).to include "Direct Linkmyapp-prototype-build-pr1337-a1b2c3f.apk" + end + it 'includes the default footnote by default' do comment = run_described_fastlane_action( appcenter_org_name: 'BestOrg', @@ -93,6 +103,38 @@ EXPECTED_COMMENT end + it 'generates a HTML table comment including the direct link if provided' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108' + } + + comment = run_described_fastlane_action( + appcenter_org_name: 'BestOrg', + appcenter_app_name: 'BestApp', + appcenter_release_id: 8888, + download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

+ + + + + + + + + + +
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
Direct Linkbestapp-pr1357-a1b2c3f.apk
App Center BuildBuild \#8888
Commita1b2c3f
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end + it 'generates a HTML table in a spoiler block if fold is true' do metadata = { 'Version:Short': '28.2', From 11a277ae196616d2344f86cd912a317430ec7b16 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:18:39 +0100 Subject: [PATCH 06/23] Fix `
` block rendering/syntax --- .../actions/common/prototype_build_details_comment_action.rb | 2 +- spec/prototype_build_details_comment_action_spec.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 1bda99034..128a668e7 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -36,7 +36,7 @@ def self.run(params) COMMENT_BODY if params[:fold] - "
#{intro}
\n\n#{body}\n" + "
#{intro}\n#{body}
\n" else "

#{intro}

\n#{body}" end diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index a9cc76438..54a2d578f 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -153,8 +153,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -
📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.
- +
📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center. @@ -168,7 +167,7 @@
Commita1b2c3f
Note: Google Sign-In in not available in those builds -
+
EXPECTED_COMMENT end end From c7ed840545f3dfa1e29154f897b41eb4c6009f08 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:23:20 +0100 Subject: [PATCH 07/23] Shake up some tests to vary tested cases more --- spec/prototype_build_details_comment_action_spec.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 54a2d578f..5d415c32f 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -114,8 +114,7 @@ appcenter_app_name: 'BestApp', appcenter_release_id: 8888, download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', - metadata: metadata, - footnote: 'Note: Google Sign-In in not available in those builds' + metadata: metadata ) expect(comment).to eq <<~EXPECTED_COMMENT @@ -131,7 +130,7 @@ App Center BuildBuild \#8888 Commita1b2c3f - Note: Google Sign-In in not available in those builds + Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. EXPECTED_COMMENT end @@ -146,7 +145,7 @@ comment = run_described_fastlane_action( appcenter_org_name: 'BestOrg', appcenter_app_name: 'BestApp', - appcenter_release_id: 8888, + appcenter_release_id: 1234, fold: true, metadata: metadata, footnote: 'Note: Google Sign-In in not available in those builds' @@ -156,14 +155,14 @@
📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center. - + - +
AppBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
App Center BuildBuild \#8888
App Center BuildBuild \#1234
Commita1b2c3f
Note: Google Sign-In in not available in those builds From 9a544281b4cdbc4a749e289ae326e7c6374c9e18 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:25:20 +0100 Subject: [PATCH 08/23] Refine table key names --- .../common/prototype_build_details_comment_action.rb | 2 +- spec/prototype_build_details_comment_action_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 128a668e7..fcdbe491f 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -26,7 +26,7 @@ def self.run(params) - + #{metadata_rows.join("\n")} diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 5d415c32f..682ec793c 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -91,7 +91,7 @@
App#{appcenter_app_name}App Name#{appcenter_app_name}
App Center BuildBuild \##{appcenter_release_id}
- + @@ -122,7 +122,7 @@
AppBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
- + @@ -156,7 +156,7 @@
AppBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
- + From 935b1e0630eb1ec50b2e2ed58c49acea8fada07f Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:30:28 +0100 Subject: [PATCH 09/23] Shorten Intro text --- .../common/prototype_build_details_comment_action.rb | 2 +- spec/prototype_build_details_comment_action_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index fcdbe491f..5317d1579 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -21,7 +21,7 @@ def self.run(params) "" end - intro = "📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding #{appcenter_app_name} build from App Center." + intro = "📲 You can test the changes from this Pull Request in #{appcenter_app_name} by scanning the QR code below to install the corresponding build via App Center." body = <<~COMMENT_BODY
AppBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
#{key}#{value}
diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 682ec793c..05d211c0b 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -87,7 +87,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

+

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

@@ -118,7 +118,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center.

+

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

@@ -152,7 +152,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -
📲 You can test the changes from this Pull Request by scanning the QR code below with your phone to install the corresponding BestApp build from App Center. +
📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.
From ff25e36db98d153a0e39126867f5bb264ef4645d Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 1 Feb 2023 21:39:40 +0100 Subject: [PATCH 10/23] Provide additional doc for appcenter_release_id --- .../actions/common/prototype_build_details_comment_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 5317d1579..b52531257 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -67,7 +67,7 @@ def self.available_options FastlaneCore::ConfigItem.new( key: :appcenter_release_id, env_name: 'FL_PROTOTYPE_BUILD_APPCENTER_RELEASE_ID', - description: 'The release ID/Number in App Center', + description: "The release ID/Number in App Center; can be obtained using `lane_context[SharedValues::APPCENTER_BUILD_INFORMATION]['id']`", type: Integer ), FastlaneCore::ConfigItem.new( From 2d5d7fdc90bfe9569ca104ca36b4c2592cf5152a Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 3 Feb 2023 10:22:57 +0100 Subject: [PATCH 11/23] Improve wording on action description Co-authored-by: Gio Lodi --- .../actions/common/prototype_build_details_comment_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index b52531257..f054684ae 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -47,7 +47,7 @@ def self.run(params) ##################################################### def self.description - 'Generates the nicely-formatted string providing all the details of a prototype build, ready to be used as a PR comment (e.g. via `comment_on_pr`).' + 'Generates a string providing all the details of a prototype build, nicely-formatted and ready to be used as a PR comment (e.g. via `comment_on_pr`).' end def self.available_options From d214c330ee3a153b64a72fbf07b252b09e33d870 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 3 Feb 2023 10:30:34 +0100 Subject: [PATCH 12/23] Typo on spec name Co-authored-by: Gio Lodi --- spec/prototype_build_details_comment_action_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 05d211c0b..ac63eb87d 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -7,7 +7,7 @@ end describe 'expected info is included' do - it 'generates the proper AppCenter link and QR code given an org, app name and release ID' do + it 'generates the proper App Center link and QR code given an org, app name and release ID' do comment = run_described_fastlane_action( appcenter_app_name: 'MyApp', appcenter_release_id: 1337 From 4204a4532477907f124a32b01f39cccddcfdece9 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 3 Feb 2023 09:59:34 +0100 Subject: [PATCH 13/23] s/// As suggested in https://github.com/wordpress-mobile/release-toolkit/pull/449\#discussion_r1093903902 --- .../common/prototype_build_details_comment_action.rb | 2 +- spec/prototype_build_details_comment_action_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index f054684ae..dd0238509 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -21,7 +21,7 @@ def self.run(params) "" end - intro = "📲 You can test the changes from this Pull Request in #{appcenter_app_name} by scanning the QR code below to install the corresponding build via App Center." + intro = "📲 You can test the changes from this Pull Request in #{appcenter_app_name} by scanning the QR code below to install the corresponding build via App Center." body = <<~COMMENT_BODY
#{key}#{value}
diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index ac63eb87d..ea9478a24 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -87,7 +87,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

+

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

@@ -118,7 +118,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

+

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

@@ -152,7 +152,7 @@ ) expect(comment).to eq <<~EXPECTED_COMMENT -
📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center. +
📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.
From 911d71bb02533ba7cc618e9f7f1490789d4b6f30 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 3 Feb 2023 10:22:12 +0100 Subject: [PATCH 14/23] s/// As discussed in https://github.com/wordpress-mobile/release-toolkit/pull/449\#discussion_r1095536151 --- .../prototype_build_details_comment_action.rb | 6 +++--- ...totype_build_details_comment_action_spec.rb | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index dd0238509..492346a63 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -11,7 +11,7 @@ def self.run(params) metadata = params[:metadata] # e.g. {'Build Config':… , 'Version': …, 'Short Version': …} direct_link = params[:download_url] unless direct_link.nil? - metadata['Direct Link'] = "#{File.basename(direct_link)}" + metadata['Direct Link'] = "#{File.basename(direct_link)}" end # Build the comment parts @@ -26,11 +26,11 @@ def self.run(params)
- + #{metadata_rows.join("\n")} - +
App Name#{appcenter_app_name}App Name#{appcenter_app_name}
App Center BuildBuild \##{appcenter_release_id}
Commit#{commit}
Commit#{commit}
#{params[:footnote]} COMMENT_BODY diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index ea9478a24..48f023fa7 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -21,7 +21,7 @@ appcenter_app_name: 'MyApp', appcenter_release_id: 1337 ) - expect(comment).to include 'Commita1b2c3f' + expect(comment).to include 'Commita1b2c3f' end it 'correctly includes additional metadata when some are provided' do @@ -48,7 +48,7 @@ download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' ) expect(comment).to include "" - expect(comment).to include "Direct Linkmyapp-prototype-build-pr1337-a1b2c3f.apk" + expect(comment).to include "Direct Linkmyapp-prototype-build-pr1337-a1b2c3f.apk" end it 'includes the default footnote by default' do @@ -91,13 +91,13 @@ - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
App Center BuildBuild \#8888
Commita1b2c3f
Commita1b2c3f
Note: Google Sign-In in not available in those builds EXPECTED_COMMENT @@ -122,13 +122,13 @@ - + - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
Direct Linkbestapp-pr1357-a1b2c3f.apk
Direct Linkbestapp-pr1357-a1b2c3f.apk
App Center BuildBuild \#8888
Commita1b2c3f
Commita1b2c3f
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. EXPECTED_COMMENT @@ -156,14 +156,14 @@ - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
App Center BuildBuild \#1234
Commita1b2c3f
Commita1b2c3f
Note: Google Sign-In in not available in those builds
From 854098f3e5995f3e45eaa5b893ed8c50e906a2aa Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Fri, 3 Feb 2023 10:28:22 +0100 Subject: [PATCH 15/23] Add comment on the Buildkite-specificity of env var used by the `:commit` `ConfigItem` As discussed in https://github.com/wordpress-mobile/release-toolkit/pull/449\#discussion_r1093910965 --- .../actions/common/prototype_build_details_comment_action.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 492346a63..361a2f6eb 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -102,7 +102,8 @@ def self.available_options ), FastlaneCore::ConfigItem.new( key: :commit, - env_name: 'BUILDKITE_COMMIT', + # Buildkite ENV var: https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_COMMIT + env_names: ['BUILDKITE_COMMIT'], # Feel free to add more CI-specific env vars for other CI providers description: 'The commit this prototype build was build from; usually not passed explicitly, but derived from the environment variable instead', type: String, optional: true From e275603aa3a9d51be49ea0c7b441075a3ea25e02 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Tue, 7 Feb 2023 13:47:39 +0100 Subject: [PATCH 16/23] Remove around app name and commit Especially, leaving the commit bare without tag will allow GitHub to automatically transform it into a link to the commit itself --- .../prototype_build_details_comment_action.rb | 4 ++-- .../prototype_build_details_comment_action_spec.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 361a2f6eb..d74f423db 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -26,11 +26,11 @@ def self.run(params) - + #{metadata_rows.join("\n")} - +
App Name#{appcenter_app_name}App Name#{appcenter_app_name}
App Center BuildBuild \##{appcenter_release_id}
Commit#{commit}
Commit#{commit}
#{params[:footnote]} COMMENT_BODY diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 48f023fa7..a819b95c6 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -21,7 +21,7 @@ appcenter_app_name: 'MyApp', appcenter_release_id: 1337 ) - expect(comment).to include 'Commita1b2c3f' + expect(comment).to include 'Commita1b2c3f' end it 'correctly includes additional metadata when some are provided' do @@ -91,13 +91,13 @@ - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
App Center BuildBuild \#8888
Commita1b2c3f
Commita1b2c3f
Note: Google Sign-In in not available in those builds EXPECTED_COMMENT @@ -122,13 +122,13 @@ - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
Direct Linkbestapp-pr1357-a1b2c3f.apk
App Center BuildBuild \#8888
Commita1b2c3f
Commita1b2c3f
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. EXPECTED_COMMENT @@ -156,14 +156,14 @@ - + - +
App NameBestAppApp NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
App Center BuildBuild \#1234
Commita1b2c3f
Commita1b2c3f
Note: Google Sign-In in not available in those builds
From 1d9938313befcce9b07f59ea433afe8609d727ed Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Tue, 7 Feb 2023 20:51:10 +0100 Subject: [PATCH 17/23] Refactor the action to auto-extract most of the info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From values provided in the `lane_context` by the `appcenter_upload` action – if it was used to distribute the Prototype build --- .../prototype_build_details_comment_action.rb | 170 +++++++++++++----- 1 file changed, 122 insertions(+), 48 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index d74f423db..eeb481c09 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -2,37 +2,49 @@ module Fastlane module Actions class PrototypeBuildDetailsCommentAction < Action def self.run(params) - # Get Input Parameters - appcenter_org_name = params[:appcenter_org_name] - appcenter_app_name = params[:appcenter_app_name] - appcenter_release_id = params[:appcenter_release_id] - commit = params[:commit] || other_action.last_git_commit[:abbreviated_commit_hash] - - metadata = params[:metadata] # e.g. {'Build Config':… , 'Version': …, 'Short Version': …} - direct_link = params[:download_url] - unless direct_link.nil? - metadata['Direct Link'] = "#{File.basename(direct_link)}" - end + app_display_name = params[:app_display_name] - # Build the comment parts - install_url = "https://install.appcenter.ms/orgs/#{appcenter_org_name}/apps/#{appcenter_app_name}/releases/#{appcenter_release_id}" - qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" - metadata_rows = metadata.compact.map do |key, value| - "#{key}#{value}" + app_center_org_name = params[:app_center_org_name] + app_center_info = app_center_org_name.nil? ? {} : lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} + app_center_app_name = params[:app_center_app_name] || app_center_info['app_name'] + app_center_app_display_name = app_center_info['app_display_name'] || app_center_app_name + app_center_release_id = params[:app_center_release_id] || app_center_info['id'] + + # Consolidate the list of Metadata to display with some implicit metadata if available + metadata = params[:metadata] || {} + metadata['Build Number'] ||= app_center_info['version'] + metadata['Version'] ||= app_center_info['short_version'] + metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] = app_center_info['bundle_identifier'] + # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need) + metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash] + + # Installation Link(s) -- either download_url param, or App Center Build link, or both + install_url = nil + if params[:download_url] + install_url = params[:download_url] + metadata['Direct Download'] = "#{File.basename(install_url)}" end + if app_center_org_name && app_center_app_name + install_url = "https://install.appcenter.ms/orgs/#{app_center_org_name}/apps/#{app_center_app_name}/releases/#{app_center_release_id}" + metadata['App Center Build'] = "#{app_center_app_display_name} \##{app_center_release_id}" + end + UI.user_error!(NO_INSTALL_URL_ERROR_MESSAGE) if install_url.nil? + qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" - intro = "📲 You can test the changes from this Pull Request in #{appcenter_app_name} by scanning the QR code below to install the corresponding build via App Center." + # Build the comment parts + icon_img_tag = img_tag(params[:app_icon] || app_center_info['app_icon_url'], alt: app_display_name) + metadata_rows = metadata.compact.map { |key, value| "#{key}#{value}" } + intro = "#{icon_img_tag}📲 You can test the changes from this Pull Request in #{app_display_name} by scanning the QR code below to install the corresponding build." + footnote = params[:footnote] || (app_center_info.nil? ? '' : 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.') body = <<~COMMENT_BODY - - + + #{metadata_rows.join("\n")} - -
App Name#{appcenter_app_name}App Name#{icon_img_tag} #{app_display_name}
App Center BuildBuild \##{appcenter_release_id}
Commit#{commit}
- #{params[:footnote]} + #{footnote} COMMENT_BODY if params[:fold] @@ -42,6 +54,28 @@ def self.run(params) end end + ##################################################### + # @!group Helpers + ##################################################### + + NO_INSTALL_URL_ERROR_MESSAGE = <<~NO_URL_ERROR.freeze + No URL provided to download or install the app. + - Either use this action right after using `appcenter_upload` and provide an `app_center_org_name` (so that this action can use the link to the App Center build) + - Or provide an explicit value for the `download_url` parameter + NO_URL_ERROR + + def self.img_tag(url_or_emoji, alt: '') + return nil if url_or_emoji.nil? + + emoji = url_or_emoji.match(/:(.*):/)&.captures&.first + app_icon_url = if emoji + "https://raw.githubusercontent.com/buildkite/emojis/main/img-buildkite-64/#{emoji}.png" + elsif URI(url_or_emoji) + url_or_emoji + end + app_icon_url ? "#{alt}" : '' + end + ##################################################### # @!group Documentation ##################################################### @@ -50,30 +84,75 @@ def self.description 'Generates a string providing all the details of a prototype build, nicely-formatted and ready to be used as a PR comment (e.g. via `comment_on_pr`).' end + def self.details + <<~DESC + Generates a string providing all the details of a prototype build, nicely-formatted as HTML. + The returned string will typically be subsequently used by the `comment_on_pr` action to post that HTML as comment on a PR. + + If you used the `appcenter_upload` lane (to upload the Prototype build to App Center) before calling this action, and pass + a value to the `app_center_org_name` parameter, then many of the parameters and metadata will be automatically extracted + from the `lane_context` provided by `appcenter_upload`, including: + + - The `app_center_app_name`, `app_center_release_id` and installation URL to use for the QR code to point to that release in App Center + - The `app_icon` + - The app's Build Number / versionCode + - The app's Version / versionName + - The app's Bundle ID / Application ID + - A `footnote` mentioning the MC tool for Automatticians to add themselves to App Center + + This means that if you are using App Center to distribute your Prototype Build, the only parameters you *have* to provide + to this action are `app_display_name` and `app_center_org_name`; plus, for `metadata` most of the interesting values will already be pre-filled. + + Any of those implicit default values/metadata can of course be overridden by passing an explicit value to the appropriate parameter(s). + DESC + end + def self.available_options + app_center_auto = '(will be automatically extracted from `lane_context if you used `appcenter_upload` to distribute your Prototype build)' [ FastlaneCore::ConfigItem.new( - key: :appcenter_org_name, - env_name: 'APPCENTER_OWNER_NAME', # Same as the one used by the `appcenter_upload` action - description: 'The name of the organization in App Center', + key: :app_display_name, + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_APP_DISPLAY_NAME', + description: 'The display name to use for the app in the comment message', + optional: false, type: String ), FastlaneCore::ConfigItem.new( - key: :appcenter_app_name, - env_name: 'APPCENTER_APP_NAME', # Same as the one used by the `appcenter_upload` action - description: 'The name of the app in App Center', - type: String + key: :app_center_org_name, + env_name: 'APPCENTER_OWNER_NAME', # Intentionally the same as the one used by the `appcenter_upload` action + description: 'The name of the organization in App Center (if you used `appcenter_upload` to distribute your Prototype build)', + type: String, + optional: true + ), + FastlaneCore::ConfigItem.new( + key: :app_center_app_name, + env_name: 'APPCENTER_APP_NAME', # Intentionally the same as the one used by the `appcenter_upload` action + description: "The name of the app in App Center #{app_center_auto}", + type: String, + optional: true, + default_value_dynamic: true # As it will be extracted from the `lane_context`` if you used `appcenter_upload`` ), FastlaneCore::ConfigItem.new( - key: :appcenter_release_id, - env_name: 'FL_PROTOTYPE_BUILD_APPCENTER_RELEASE_ID', - description: "The release ID/Number in App Center; can be obtained using `lane_context[SharedValues::APPCENTER_BUILD_INFORMATION]['id']`", - type: Integer + key: :app_center_release_id, + env_name: 'APPCENTER_RELEASE_ID', + description: "The release ID/Number in App Center #{app_center_auto}", + type: String, + optional: true, + default_value_dynamic: true # As it will be extracted from the `lane_context`` if you used `appcenter_upload`` + ), + FastlaneCore::ConfigItem.new( + key: :app_icon, + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_APP_ICON', + description: "An `:emojicode:` or URL to use for the icon of the app in the message. #{app_center_auto}", + type: String, + optional: true, + default_value_dynamic: true # As it will be extracted from the `lane_context`` if you used `appcenter_upload`` ), FastlaneCore::ConfigItem.new( key: :download_url, - env_name: 'FL_PROTOTYPE_BUILD_DOWNLOAD_URL', - description: 'The URL to download the build directly; e.g. a public link to the `.apk` file; you might use `lane_context[SharedValues::APPCENTER_DOWNLOAD_LINK]` for this for example', + env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_DOWNLOAD_URL', + description: 'The URL to download the build as a direct download. ' \ + + 'If you uploaded the build to App Center, we recommend leaving this nil (the comment will use the URL to the App Center build for the QR code)', type: String, optional: true, default_value: nil @@ -88,25 +167,20 @@ def self.available_options FastlaneCore::ConfigItem.new( key: :metadata, env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_METADATA', - description: 'All additional metadata (as key/value pairs) you want to include in the HTML table of the comment', + description: 'All additional metadata (as key/value pairs) you want to include in the HTML table of the comment. ' \ + + 'If you are running this action after `appcenter_upload`, some metadata will automatically be added to this list too', type: Hash, optional: true, - default_value: {} + default_value_dynamic: true # As some metadata will be auto-filled if you used `appcenter_upload` ), FastlaneCore::ConfigItem.new( key: :footnote, env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_FOOTNOTE', - description: 'Optional footnote to add below the HTML table of the comment', + description: 'Optional footnote to add below the HTML table of the comment. ' \ + + 'If you are running this action after `appcenter_upload`, a default footnote for Automatticians will be used unless you provide an explicit value', type: String, - default_value: 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' - ), - FastlaneCore::ConfigItem.new( - key: :commit, - # Buildkite ENV var: https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_COMMIT - env_names: ['BUILDKITE_COMMIT'], # Feel free to add more CI-specific env vars for other CI providers - description: 'The commit this prototype build was build from; usually not passed explicitly, but derived from the environment variable instead', - type: String, - optional: true + optional: true, + default_value_dynamic: true # We have a default footnote for the case when you used App Center ), ] end @@ -116,7 +190,7 @@ def self.return_type end def self.return_value - 'The HTML comment containing all the relevant info about a Prototype build published to App Center' + 'The HTML comment containing all the relevant info about a Prototype build and links to install it' end def self.authors From 6e4b3d72c6855d116fd9bb25c5e67a8d4c23645f Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 8 Feb 2023 17:05:16 +0100 Subject: [PATCH 18/23] Fix existing tests --- .../prototype_build_details_comment_action.rb | 8 +- ...otype_build_details_comment_action_spec.rb | 331 +++++++++--------- 2 files changed, 177 insertions(+), 162 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index eeb481c09..b80b201cf 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -5,7 +5,11 @@ def self.run(params) app_display_name = params[:app_display_name] app_center_org_name = params[:app_center_org_name] - app_center_info = app_center_org_name.nil? ? {} : lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} + app_center_info = if app_center_org_name && defined?(SharedValues::APPCENTER_BUILD_INFORMATION) + lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} + else + {} + end app_center_app_name = params[:app_center_app_name] || app_center_info['app_name'] app_center_app_display_name = app_center_info['app_display_name'] || app_center_app_name app_center_release_id = params[:app_center_release_id] || app_center_info['id'] @@ -39,7 +43,7 @@ def self.run(params) body = <<~COMMENT_BODY - + #{metadata_rows.join("\n")} diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index a819b95c6..23b77edaf 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -6,168 +6,179 @@ ENV['BUILDKITE_COMMIT'] = 'a1b2c3f' end - describe 'expected info is included' do - it 'generates the proper App Center link and QR code given an org, app name and release ID' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include "Build #1337" - expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' + context 'when using App Center' do + describe 'expected info is included' do + it 'generates the proper App Center link and QR code given an org, app name and release ID' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_app_name: 'MyApp', + app_center_release_id: '1337' + ) + expect(comment).to include "MyApp #1337" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' + end + + it 'includes the commit as part of the default rows' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_app_name: 'MyApp', + app_center_release_id: '1337' + ) + expect(comment).to include '' + end + + it 'correctly includes additional metadata when some are provided' do + metadata = { + 'Version:Short': '28.1', + 'Version:Long': '281003', + 'Build Config': 'Prototype' + } + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_app_name: 'MyApp', + app_center_release_id: '1337', + metadata: metadata + ) + expect(comment).to include "' + expect(comment).to include '' + expect(comment).to include '' + end + + it 'includes the direct link if one is provided' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_app_name: 'MyApp', + app_center_release_id: '1337', + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include "" + end + + it 'includes the default footnote by default' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'BestOrg', + app_center_app_name: 'MyApp', + app_center_release_id: '1337' + ) + expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + end + + it 'includes the provided footnote if any' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_app_name: 'MyApp', + app_center_release_id: '1337', + footnote: 'Note that Google Sign-In in not available in those builds' + ) + expect(comment).to include 'Note that Google Sign-In in not available in those builds' + end end - it 'includes the commit as part of the default rows' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include '' - end - - it 'correctly includes additional metadata when some are provided' do - metadata = { - 'Version:Short': '28.1', - 'Version:Long': '281003', - 'Build Config': 'Prototype' - } - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337, - metadata: metadata - ) - expect(comment).to include "' - expect(comment).to include '' - expect(comment).to include '' - end - - it 'includes the direct link if one is provided' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337, - download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' - ) - expect(comment).to include "" - end - - it 'includes the default footnote by default' do - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337 - ) - expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' - end - - it 'includes the provided footnote if any' do - comment = run_described_fastlane_action( - appcenter_app_name: 'MyApp', - appcenter_release_id: 1337, - footnote: 'Note that Google Sign-In in not available in those builds' - ) - expect(comment).to include 'Note that Google Sign-In in not available in those builds' - end - end - - describe 'full comment' do - it 'generates a standard HTML table comment by default, with all the information provided' do - metadata = { - 'Version:Short': '28.2', - 'Version:Long': '28.2.0.108', - Flavor: 'Celray' - } - - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'BestApp', - appcenter_release_id: 8888, - metadata: metadata, - footnote: 'Note: Google Sign-In in not available in those builds' - ) - - expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

-
App Name#{icon_img_tag} #{app_display_name}
Commita1b2c3fVersion:Short28.1Version:Long281003Build ConfigPrototypeDirect Downloadmyapp-prototype-build-pr1337-a1b2c3f.apkCommita1b2c3f" - expect(comment).to include 'Version:Short28.1Version:Long281003Build ConfigPrototype" - expect(comment).to include "Direct Linkmyapp-prototype-build-pr1337-a1b2c3f.apk
- - - - - - - - - -
App NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
App Center BuildBuild \#8888
Commita1b2c3f
- Note: Google Sign-In in not available in those builds - EXPECTED_COMMENT - end - - it 'generates a HTML table comment including the direct link if provided' do - metadata = { - 'Version:Short': '28.2', - 'Version:Long': '28.2.0.108' - } - - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'BestApp', - appcenter_release_id: 8888, - download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', - metadata: metadata - ) - - expect(comment).to eq <<~EXPECTED_COMMENT -

📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center.

- - - - - - - - - - -
App NameBestApp
Version:Short28.2
Version:Long28.2.0.108
Direct Linkbestapp-pr1357-a1b2c3f.apk
App Center BuildBuild \#8888
Commita1b2c3f
- Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. - EXPECTED_COMMENT - end - - it 'generates a HTML table in a spoiler block if fold is true' do - metadata = { - 'Version:Short': '28.2', - 'Version:Long': '28.2.0.108', - Flavor: 'Celray', - Configuration: 'Debug' - } - - comment = run_described_fastlane_action( - appcenter_org_name: 'BestOrg', - appcenter_app_name: 'BestApp', - appcenter_release_id: 1234, - fold: true, - metadata: metadata, - footnote: 'Note: Google Sign-In in not available in those builds' - ) - - expect(comment).to eq <<~EXPECTED_COMMENT -
📲 You can test the changes from this Pull Request in BestApp by scanning the QR code below to install the corresponding build via App Center. - - - - - - - - - - - -
App NameBestApp
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
App Center BuildBuild \#1234
Commita1b2c3f
- Note: Google Sign-In in not available in those builds -
- EXPECTED_COMMENT + describe 'full comment' do + it 'generates a standard HTML table comment by default, with all the information provided' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108', + Flavor: 'Celray' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + app_center_app_name: 'BestApp', + app_center_release_id: '8888', + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build.

+ + + + + + + + + + +
App Name The Best App
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
Commita1b2c3f
App Center BuildBestApp \#8888
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end + + it 'generates a HTML table comment including the direct link if provided' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + app_center_app_name: 'BestApp', + app_center_release_id: '8888', + download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', + metadata: metadata + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build.

+ + + + + + + + + + +
App Name The Best App
Version:Short28.2
Version:Long28.2.0.108
Commita1b2c3f
Direct Downloadbestapp-pr1357-a1b2c3f.apk
App Center BuildBestApp \#8888
+ Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. + EXPECTED_COMMENT + end + + it 'generates a HTML table in a spoiler block if fold is true' do + metadata = { + 'Version:Short': '28.2', + 'Version:Long': '28.2.0.108', + Flavor: 'Celray', + Configuration: 'Debug' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + app_center_app_name: 'BestApp', + app_center_release_id: '1234', + fold: true, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +
📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build. + + + + + + + + + + + +
App Name The Best App
Version:Short28.2
Version:Long28.2.0.108
FlavorCelray
ConfigurationDebug
Commita1b2c3f
App Center BuildBestApp \#1234
+ Note: Google Sign-In in not available in those builds +
+ EXPECTED_COMMENT + end end end end From 0940a6b97090ca1c8cc8d99247446d370cc0051a Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 8 Feb 2023 22:53:11 +0100 Subject: [PATCH 19/23] Improving tests, pass 1 There are still more tests that I want to add, and I need to proof-read the ones that I wrote in this commit to ensure I didn't miss cases of adjusting the test content after copy/pasting code from various tests around. --- .../prototype_build_details_comment_action.rb | 6 +- ...otype_build_details_comment_action_spec.rb | 232 +++++++++++++++--- 2 files changed, 201 insertions(+), 37 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index b80b201cf..e8d9623df 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -15,7 +15,7 @@ def self.run(params) app_center_release_id = params[:app_center_release_id] || app_center_info['id'] # Consolidate the list of Metadata to display with some implicit metadata if available - metadata = params[:metadata] || {} + metadata = params[:metadata]&.transform_keys(&:to_s) || {} metadata['Build Number'] ||= app_center_info['version'] metadata['Version'] ||= app_center_info['short_version'] metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] = app_center_info['bundle_identifier'] @@ -39,12 +39,12 @@ def self.run(params) icon_img_tag = img_tag(params[:app_icon] || app_center_info['app_icon_url'], alt: app_display_name) metadata_rows = metadata.compact.map { |key, value| "#{key}#{value}" } intro = "#{icon_img_tag}📲 You can test the changes from this Pull Request in #{app_display_name} by scanning the QR code below to install the corresponding build." - footnote = params[:footnote] || (app_center_info.nil? ? '' : 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.') + footnote = params[:footnote] || (app_center_org_name.nil? ? '' : 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.') body = <<~COMMENT_BODY - + #{metadata_rows.join("\n")}
App Name#{icon_img_tag} #{app_display_name}App Name#{icon_img_tag} #{app_display_name}
diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 23b77edaf..1176b0052 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -2,32 +2,65 @@ describe Fastlane::Actions::PrototypeBuildDetailsCommentAction do before do - ENV['APPCENTER_OWNER_NAME'] = 'My-Org' ENV['BUILDKITE_COMMIT'] = 'a1b2c3f' end - context 'when using App Center' do - describe 'expected info is included' do - it 'generates the proper App Center link and QR code given an org, app name and release ID' do - comment = run_described_fastlane_action( + describe 'cases common to all operating modes' do + it 'includes the app display name as part of the intro text' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include 'You can test the changes from this Pull Request in My Cool App' + end + + it 'includes the commit as part of the default rows' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include 'Commita1b2c3f' + end + + it 'includes the provided footnote if one was provided explicitly' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://localhost/foo.apk', + footnote: 'Note that Google Sign-In in not available in those builds' + ) + expect(comment).to include 'Note that Google Sign-In in not available in those builds' + end + end + + context 'when using App Center with explicit parameters' do + it 'raises an error if neither `app_center_app_name` nor `download_url` is provided' do + expected_message = <<~ERROR + No URL provided to download or install the app. + - Either use this action right after using `appcenter_upload` and provide an `app_center_org_name` (so that this action can use the link to the App Center build) + - Or provide an explicit value for the `download_url` parameter + ERROR + + expect do + run_described_fastlane_action( app_display_name: 'My App', - app_center_app_name: 'MyApp', - app_center_release_id: '1337' + app_center_org_name: 'BestOrg' ) - expect(comment).to include "MyApp #1337" - expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMyApp%2Freleases%2F1337&choe=UTF-8' - end + end.to raise_error(FastlaneCore::Interface::FastlaneError, expected_message) + end - it 'includes the commit as part of the default rows' do + describe 'checking specific content is present' do + it 'generates the proper App Center link and QR code given an org, app name and release ID' do comment = run_described_fastlane_action( app_display_name: 'My App', - app_center_app_name: 'MyApp', + app_center_org_name: 'My-Org', + app_center_app_name: 'My-App', app_center_release_id: '1337' ) - expect(comment).to include 'Commita1b2c3f' + expect(comment).to include "My-App #1337" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App%2Freleases%2F1337&choe=UTF-8' end - it 'correctly includes additional metadata when some are provided' do + it 'includes both explicit and implicit metadata when some are provided by the user' do metadata = { 'Version:Short': '28.1', 'Version:Long': '281003', @@ -35,28 +68,36 @@ } comment = run_described_fastlane_action( app_display_name: 'My App', - app_center_app_name: 'MyApp', + app_center_org_name: 'My-Org', + app_center_app_name: 'My-App', app_center_release_id: '1337', metadata: metadata ) - expect(comment).to include "App Name My App' expect(comment).to include 'Version:Short28.1' expect(comment).to include 'Version:Long281003' expect(comment).to include 'Build ConfigPrototype' + expect(comment).to include 'Commita1b2c3f' + expect(comment).to include "App Center BuildMy-App \#1337" + # Additional inferred metadata rows: App Name, Commit, App Center Build + expect(comment).to include "Direct Downloadmyapp-prototype-build-pr1337-a1b2c3f.apk" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App%2Freleases%2F1337&choe=UTF-8' + # Inferred metadata rows: App Name, Commit, Direct Download, App Center Build + expect(comment).to include "Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' end - - it 'includes the provided footnote if any' do - comment = run_described_fastlane_action( - app_display_name: 'My App', - app_center_app_name: 'MyApp', - app_center_release_id: '1337', - footnote: 'Note that Google Sign-In in not available in those builds' - ) - expect(comment).to include 'Note that Google Sign-In in not available in those builds' - end end - describe 'full comment' do + describe 'validating full comment' do it 'generates a standard HTML table comment by default, with all the information provided' do metadata = { 'Version:Short': '28.2', @@ -99,7 +130,7 @@ - + @@ -131,7 +162,7 @@
App Name The Best AppApp Name The Best App
Version:Short28.2
Version:Long28.2.0.108
- + @@ -166,7 +197,7 @@
App Name The Best AppApp Name The Best App
Version:Short28.2
Version:Long28.2.0.108
- + @@ -181,4 +212,137 @@ end end end + + context 'when using App Center and relying on implicit info from `lane_context`' do + before do + stub_const('Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION', :fake_app_center_build_info) + + lane_ctx = { + app_name: 'My-App-Alpha', + app_display_name: 'My App (Alpha)', + id: '1337', + version: '1287003', + short_version: '28.7', + app_os: 'Android', + bundle_identifier: 'com.stubfactory.myapp', + app_icon_url: 'https://assets.appcenter.ms/My-App-Alpha/1337/icon.png' + }.transform_keys(&:to_s) + + allow(described_class).to receive(:lane_context).and_return({ fake_app_center_build_info: lane_ctx }) + end + + describe 'checking specific content is present' do + it 'generates the proper App Center link and QR code given just an org' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org' + ) + expect(comment).to include "My App (Alpha) #1337" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App-Alpha%2Freleases%2F1337&choe=UTF-8' + end + + it 'includes and prioritize user-provided metadata over implicit ones' do + metadata = { + 'Version': '42.3', + 'Build Number': '4203008', + 'Build Config': 'Prototype' + } + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org', + metadata: metadata + ) + expect(comment).to include '' # explicitly provided, overriding the implicit value + expect(comment).not_to include '' # otherwise implicitly added if it were not overridden + expect(comment).to include '' # explicitly provided, overriding the implicit value + expect(comment).not_to include '' # otherwise implicitly added if it were not overridden + expect(comment).to include '' # an explicit metadata not overriding any implicit one + # Additional inferred metadata rows: App Name, Application ID, Commit, App Center Build + expect(comment).to include "" + # Inferred metadata rows: App Name, Build Number, Version, Application ID, Commit, Direct Download, App Center Build + expect(comment).to include "" + end + + it 'does not include the App Center default footnote if no explicit footnote is provided' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).not_to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + end + + it 'includes the provided footnote if one was provided explicitly' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://localhost/foo.apk', + footnote: 'The link to this APK might stop working after a retention delay of 30 days.' + ) + expect(comment).to include 'The link to this APK might stop working after a retention delay of 30 days.' + end + end + + describe 'validating full comment' # TODO + end end From 2c3c4b0c407ba48b75f6215eb7ee209303be4b44 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 9 Feb 2023 18:13:02 +0100 Subject: [PATCH 20/23] Improving tests, pass 2 --- .../prototype_build_details_comment_action.rb | 6 +- ...otype_build_details_comment_action_spec.rb | 330 +++++++++++++++--- 2 files changed, 282 insertions(+), 54 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index e8d9623df..e65f564ae 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -18,7 +18,7 @@ def self.run(params) metadata = params[:metadata]&.transform_keys(&:to_s) || {} metadata['Build Number'] ||= app_center_info['version'] metadata['Version'] ||= app_center_info['short_version'] - metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] = app_center_info['bundle_identifier'] + metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] ||= app_center_info['bundle_identifier'] # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need) metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash] @@ -39,7 +39,7 @@ def self.run(params) icon_img_tag = img_tag(params[:app_icon] || app_center_info['app_icon_url'], alt: app_display_name) metadata_rows = metadata.compact.map { |key, value| "" } intro = "#{icon_img_tag}📲 You can test the changes from this Pull Request in #{app_display_name} by scanning the QR code below to install the corresponding build." - footnote = params[:footnote] || (app_center_org_name.nil? ? '' : 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.') + footnote = params[:footnote] || (app_center_org_name.nil? ? '' : DEFAULT_APP_CENTER_FOOTNOTE) body = <<~COMMENT_BODY
App Name The Best AppApp Name The Best App
Version:Short28.2
Version:Long28.2.0.108
Version42.3Version28.7Build Number4203008Build Number1287003Build ConfigPrototypeDirect Downloadmyapp-prototype-build-pr1337-a1b2c3f.apkAutomatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + end + + it 'includes the provided footnote if one was provided explicitly' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org', + footnote: 'Note that Google Sign-In in not available in those builds' + ) + expect(comment).to include 'Note that Google Sign-In in not available in those builds' + end + end + + describe 'validating full comment' # TODO + end + + context 'when not using App Center' do + it 'raises an error if no `download_url` is provided' do + expected_message = <<~ERROR + No URL provided to download or install the app. + - Either use this action right after using `appcenter_upload` and provide an `app_center_org_name` (so that this action can use the link to the App Center build) + - Or provide an explicit value for the `download_url` parameter + ERROR + + expect do + run_described_fastlane_action( + app_display_name: 'My App' + ) + end.to raise_error(FastlaneCore::Interface::FastlaneError, expected_message) + end + + describe 'checking specific content is present' do + it 'generates the proper QR code from the download url' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Ffoo.cloudfront.net%2Fsomeuuid%2Fmyapp-prototype-build-pr1337-a1b2c3f.apk&choe=UTF-8' + end + + it 'includes the direct link as metadata' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include "Direct Downloadmyapp-prototype-build-pr1337-a1b2c3f.apk
#{key}#{value}
@@ -68,6 +68,8 @@ def self.run(params) - Or provide an explicit value for the `download_url` parameter NO_URL_ERROR + DEFAULT_APP_CENTER_FOOTNOTE = 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.'.freeze + def self.img_tag(url_or_emoji, alt: '') return nil if url_or_emoji.nil? diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index 1176b0052..d0f2b97e4 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -6,12 +6,64 @@ end describe 'cases common to all operating modes' do - it 'includes the app display name as part of the intro text' do - comment = run_described_fastlane_action( - app_display_name: 'My Cool App', - download_url: 'https://localhost/foo.apk' - ) - expect(comment).to include 'You can test the changes from this Pull Request in My Cool App' + describe 'app_display_name' do + it 'includes the app display name as part of the intro text' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include '📲 You can test the changes from this Pull Request in My Cool App' + end + + it 'includes the app display name as part of implicit metadata' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include '' + end + end + + describe 'app_icon' do + context 'when providing an URL' do + it 'includes the icon in the intro text' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + app_icon: 'https://localhost/foo.png', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include "My Cool App📲 " + end + + it 'includes the icon next to the App Name in metadata' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + app_icon: 'https://localhost/foo.png', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include "" + end + end + + context 'when providing an emoji code' do + it 'includes the icon in the intro text' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + app_icon: ':jetpack:', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include "My Cool App📲 " + end + + it 'includes the icon next to the App Name in metadata' do + comment = run_described_fastlane_action( + app_display_name: 'My Cool App', + app_icon: ':jetpack:', + download_url: 'https://localhost/foo.apk' + ) + expect(comment).to include "" + end + end end it 'includes the commit as part of the default rows' do @@ -23,29 +75,24 @@ end it 'includes the provided footnote if one was provided explicitly' do + custom_footnote = 'Note that Google Sign-In in not available in those builds' comment = run_described_fastlane_action( app_display_name: 'My App', download_url: 'https://localhost/foo.apk', - footnote: 'Note that Google Sign-In in not available in those builds' + footnote: custom_footnote ) - expect(comment).to include 'Note that Google Sign-In in not available in those builds' + expect(comment).to include custom_footnote end end context 'when using App Center with explicit parameters' do it 'raises an error if neither `app_center_app_name` nor `download_url` is provided' do - expected_message = <<~ERROR - No URL provided to download or install the app. - - Either use this action right after using `appcenter_upload` and provide an `app_center_org_name` (so that this action can use the link to the App Center build) - - Or provide an explicit value for the `download_url` parameter - ERROR - expect do run_described_fastlane_action( app_display_name: 'My App', app_center_org_name: 'BestOrg' ) - end.to raise_error(FastlaneCore::Interface::FastlaneError, expected_message) + end.to raise_error(FastlaneCore::Interface::FastlaneError, described_class::NO_INSTALL_URL_ERROR_MESSAGE) end describe 'checking specific content is present' do @@ -60,6 +107,20 @@ expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App%2Freleases%2F1337&choe=UTF-8' end + it 'uses the App Center link for the QR code even if a `download_url` is provided' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org', + app_center_app_name: 'My-App', + app_center_release_id: '1337', + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include "" + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App%2Freleases%2F1337&choe=UTF-8' + # Inferred metadata rows: App Name, Commit, Direct Download, App Center Build + expect(comment).to include "" - expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App%2Freleases%2F1337&choe=UTF-8' - # Inferred metadata rows: App Name, Commit, Direct Download, App Center Build - expect(comment).to include "' # otherwise implicitly added if it were not overridden expect(comment).to include '' # explicitly provided, overriding the implicit value expect(comment).not_to include '' # otherwise implicitly added if it were not overridden - expect(comment).to include '' # an explicit metadata not overriding any implicit one + expect(comment).to include '' # not overriding any implicit one # Additional inferred metadata rows: App Name, Application ID, Commit, App Center Build expect(comment).to include "' + expect(comment).not_to include 'Bundle ID' + end + + it 'uses "Bundle ID" as the name for the `bundle_identifier` value if using iOS', app_os: 'iOS' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org' + ) + expect(comment).to include '' + expect(comment).not_to include 'Application ID' + end + it 'includes the direct link if one is provided' do comment = run_described_fastlane_action( app_display_name: 'My App', @@ -277,35 +354,118 @@ app_display_name: 'My App', app_center_org_name: 'BestOrg' ) - expect(comment).to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + expect(comment).to include described_class::DEFAULT_APP_CENTER_FOOTNOTE end it 'includes the provided footnote if one was provided explicitly' do + custom_footnote = 'Note that Google Sign-In in not available in those builds' comment = run_described_fastlane_action( app_display_name: 'My App', app_center_org_name: 'My-Org', - footnote: 'Note that Google Sign-In in not available in those builds' + footnote: custom_footnote ) - expect(comment).to include 'Note that Google Sign-In in not available in those builds' + expect(comment).to include custom_footnote + expect(comment).not_to include described_class::DEFAULT_APP_CENTER_FOOTNOTE end end - describe 'validating full comment' # TODO + describe 'validating full comment' do + it 'generates a standard HTML table comment by default, with all the information provided' do + metadata = { + Configuration: 'Debug' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

The Best App📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build.

+
App Name My Cool AppApp NameMy Cool App My Cool AppApp NameMy Cool App My Cool AppDirect Downloadmyapp-prototype-build-pr1337-a1b2c3f.apkDirect Downloadmyapp-prototype-build-pr1337-a1b2c3f.apkAutomatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + expect(comment).to include described_class::DEFAULT_APP_CENTER_FOOTNOTE end end @@ -214,21 +261,22 @@ end context 'when using App Center and relying on implicit info from `lane_context`' do - before do - stub_const('Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION', :fake_app_center_build_info) - - lane_ctx = { + let(:fake_lane_context) do |example| + { app_name: 'My-App-Alpha', app_display_name: 'My App (Alpha)', id: '1337', version: '1287003', short_version: '28.7', - app_os: 'Android', + app_os: example.metadata[:app_os] || 'Android', bundle_identifier: 'com.stubfactory.myapp', app_icon_url: 'https://assets.appcenter.ms/My-App-Alpha/1337/icon.png' }.transform_keys(&:to_s) + end - allow(described_class).to receive(:lane_context).and_return({ fake_app_center_build_info: lane_ctx }) + before do + stub_const('Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION', :fake_app_center_build_info) + allow(described_class).to receive(:lane_context).and_return({ fake_app_center_build_info: fake_lane_context }) end describe 'checking specific content is present' do @@ -241,9 +289,20 @@ expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App-Alpha%2Freleases%2F1337&choe=UTF-8' end - it 'includes and prioritize user-provided metadata over implicit ones' do + it 'uses the App Center link for the QR code even if a `download_url` is provided' do + comment = run_described_fastlane_action( + app_display_name: 'My App', + app_center_org_name: 'My-Org', + download_url: 'https://foo.cloudfront.net/someuuid/myapp-prototype-build-pr1337-a1b2c3f.apk' + ) + expect(comment).to include 'https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=https%3A%2F%2Finstall.appcenter.ms%2Forgs%2FMy-Org%2Fapps%2FMy-App-Alpha%2Freleases%2F1337&choe=UTF-8' + # Inferred metadata rows: App Name, Build Number, Version, Application ID, Commit, Direct Download, App Center Build + expect(comment).to include "Version28.7Build Number4203008Build Number1287003Build ConfigPrototypeBuild ConfigPrototypeApplication IDcom.stubfactory.myappBundle IDcom.stubfactory.myapp
+ + + + + + + + + + +
App NameThe Best App The Best App
ConfigurationDebug
Build Number1287003
Version28.7
Application IDcom.stubfactory.myapp
Commita1b2c3f
App Center BuildMy App (Alpha) \#1337
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end + + it 'generates a HTML table comment including the direct link if provided' do + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

The Best App📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build.

+ + + + + + + + + + + +
App NameThe Best App The Best App
Build Number1287003
Version28.7
Application IDcom.stubfactory.myapp
Commita1b2c3f
Direct Downloadbestapp-pr1357-a1b2c3f.apk
App Center BuildMy App (Alpha) \#1337
+ Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed. + EXPECTED_COMMENT + end + + it 'generates a HTML table in a spoiler block if fold is true' do + metadata = { + 'Google Login': 'Disabled' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + app_center_org_name: 'BestOrg', + fold: true, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +
The Best App📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build. + + + + + + + + + + + +
App NameThe Best App The Best App
Google LoginDisabled
Build Number1287003
Version28.7
Application IDcom.stubfactory.myapp
Commita1b2c3f
App Center BuildMy App (Alpha) \#1337
+ Note: Google Sign-In in not available in those builds +
+ EXPECTED_COMMENT + end + end end context 'when not using App Center' do it 'raises an error if no `download_url` is provided' do - expected_message = <<~ERROR - No URL provided to download or install the app. - - Either use this action right after using `appcenter_upload` and provide an `app_center_org_name` (so that this action can use the link to the App Center build) - - Or provide an explicit value for the `download_url` parameter - ERROR - expect do run_described_fastlane_action( app_display_name: 'My App' ) - end.to raise_error(FastlaneCore::Interface::FastlaneError, expected_message) + end.to raise_error(FastlaneCore::Interface::FastlaneError, described_class::NO_INSTALL_URL_ERROR_MESSAGE) end describe 'checking specific content is present' do @@ -330,7 +490,7 @@ app_display_name: 'My App', download_url: 'https://localhost/foo.apk' ) - expect(comment).not_to include 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.' + expect(comment).not_to include described_class::DEFAULT_APP_CENTER_FOOTNOTE end it 'includes the provided footnote if one was provided explicitly' do @@ -343,6 +503,72 @@ end end - describe 'validating full comment' # TODO + describe 'validating full comment' do + it 'generates a standard HTML table comment by default, with all the information provided' do + metadata = { + 'Version Name': '28.2', + 'Version Code': '1280200108', + Flavor: 'Celray' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +

📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build.

+ + + + + + + + + + +
App Name The Best App
Version Name28.2
Version Code1280200108
FlavorCelray
Commita1b2c3f
Direct Downloadbestapp-pr1357-a1b2c3f.apk
+ Note: Google Sign-In in not available in those builds + EXPECTED_COMMENT + end + + it 'generates a HTML table in a spoiler block if fold is true' do + metadata = { + 'Version Name': '28.2', + 'Version Code': '1280200108', + Flavor: 'Celray', + Configuration: 'Debug' + } + + comment = run_described_fastlane_action( + app_display_name: 'The Best App', + download_url: 'https://bestfront.cloudfront.net/feed42/bestapp-pr1357-a1b2c3f.apk', + fold: true, + metadata: metadata, + footnote: 'Note: Google Sign-In in not available in those builds' + ) + + expect(comment).to eq <<~EXPECTED_COMMENT +
📲 You can test the changes from this Pull Request in The Best App by scanning the QR code below to install the corresponding build. + + + + + + + + + + + +
App Name The Best App
Version Name28.2
Version Code1280200108
FlavorCelray
ConfigurationDebug
Commita1b2c3f
Direct Downloadbestapp-pr1357-a1b2c3f.apk
+ Note: Google Sign-In in not available in those builds +
+ EXPECTED_COMMENT + end + end end end From 925505350e6d1e72b0e70025956631cc313c90e3 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 9 Feb 2023 20:28:46 +0100 Subject: [PATCH 21/23] Split code in helpers to reduce complexity --- .../prototype_build_details_comment_action.rb | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index e65f564ae..9b3de765e 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -5,35 +5,17 @@ def self.run(params) app_display_name = params[:app_display_name] app_center_org_name = params[:app_center_org_name] - app_center_info = if app_center_org_name && defined?(SharedValues::APPCENTER_BUILD_INFORMATION) - lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} - else - {} - end + app_center_info = extract_app_center_info(app_center_org_name) app_center_app_name = params[:app_center_app_name] || app_center_info['app_name'] app_center_app_display_name = app_center_info['app_display_name'] || app_center_app_name app_center_release_id = params[:app_center_release_id] || app_center_info['id'] - # Consolidate the list of Metadata to display with some implicit metadata if available - metadata = params[:metadata]&.transform_keys(&:to_s) || {} - metadata['Build Number'] ||= app_center_info['version'] - metadata['Version'] ||= app_center_info['short_version'] - metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] ||= app_center_info['bundle_identifier'] - # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need) - metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash] + # Assemble explicit metadata passed as params with implicit metadata derived from App Center params or lane_context + metadata = consolidate_metadata(params, app_center_info) # Installation Link(s) -- either download_url param, or App Center Build link, or both - install_url = nil - if params[:download_url] - install_url = params[:download_url] - metadata['Direct Download'] = "#{File.basename(install_url)}" - end - if app_center_org_name && app_center_app_name - install_url = "https://install.appcenter.ms/orgs/#{app_center_org_name}/apps/#{app_center_app_name}/releases/#{app_center_release_id}" - metadata['App Center Build'] = "#{app_center_app_display_name} \##{app_center_release_id}" - end - UI.user_error!(NO_INSTALL_URL_ERROR_MESSAGE) if install_url.nil? - qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" + qr_code_url, extra_metadata = build_install_links(params[:download_url], app_center_org_name, app_center_app_name, app_center_app_display_name, app_center_release_id) + metadata.merge!(extra_metadata) # Build the comment parts icon_img_tag = img_tag(params[:app_icon] || app_center_info['app_icon_url'], alt: app_display_name) @@ -70,6 +52,40 @@ def self.run(params) DEFAULT_APP_CENTER_FOOTNOTE = 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.'.freeze + def self.extract_app_center_info(app_center_org_name) + if app_center_org_name && defined?(SharedValues::APPCENTER_BUILD_INFORMATION) + lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} + else + {} + end + end + + def self.build_install_links(download_url, app_center_org_name, app_center_app_name, app_center_app_display_name, app_center_release_id) + install_url = nil + extra_metadata = {} + if download_url + install_url = download_url + extra_metadata['Direct Download'] = "#{File.basename(install_url)}" + end + if app_center_org_name && app_center_app_name + install_url = "https://install.appcenter.ms/orgs/#{app_center_org_name}/apps/#{app_center_app_name}/releases/#{app_center_release_id}" + extra_metadata['App Center Build'] = "#{app_center_app_display_name} \##{app_center_release_id}" + end + UI.user_error!(NO_INSTALL_URL_ERROR_MESSAGE) if install_url.nil? + qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" + [qr_code_url, extra_metadata] + end + + def self.consolidate_metadata(params, app_center_info) + metadata = params[:metadata]&.transform_keys(&:to_s) || {} + metadata['Build Number'] ||= app_center_info['version'] + metadata['Version'] ||= app_center_info['short_version'] + metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] ||= app_center_info['bundle_identifier'] + # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need) + metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash] + metadata + end + def self.img_tag(url_or_emoji, alt: '') return nil if url_or_emoji.nil? From 3f28db7fa560418bdc970c75059260e475d12a91 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Thu, 9 Feb 2023 22:25:53 +0100 Subject: [PATCH 22/23] Refactoring to split code in more separate methods --- .../prototype_build_details_comment_action.rb | 80 +++++++++++++------ ...otype_build_details_comment_action_spec.rb | 2 +- 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 9b3de765e..6b70db3de 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -3,25 +3,17 @@ module Actions class PrototypeBuildDetailsCommentAction < Action def self.run(params) app_display_name = params[:app_display_name] - - app_center_org_name = params[:app_center_org_name] - app_center_info = extract_app_center_info(app_center_org_name) - app_center_app_name = params[:app_center_app_name] || app_center_info['app_name'] - app_center_app_display_name = app_center_info['app_display_name'] || app_center_app_name - app_center_release_id = params[:app_center_release_id] || app_center_info['id'] - - # Assemble explicit metadata passed as params with implicit metadata derived from App Center params or lane_context + app_center_info = AppCenterInfo.from_params(params) metadata = consolidate_metadata(params, app_center_info) - # Installation Link(s) -- either download_url param, or App Center Build link, or both - qr_code_url, extra_metadata = build_install_links(params[:download_url], app_center_org_name, app_center_app_name, app_center_app_display_name, app_center_release_id) + qr_code_url, extra_metadata = build_install_links(app_center_info, params[:download_url]) metadata.merge!(extra_metadata) # Build the comment parts - icon_img_tag = img_tag(params[:app_icon] || app_center_info['app_icon_url'], alt: app_display_name) + icon_img_tag = img_tag(params[:app_icon] || app_center_info.icon, alt: app_display_name) metadata_rows = metadata.compact.map { |key, value| "#{key}#{value}" } intro = "#{icon_img_tag}📲 You can test the changes from this Pull Request in #{app_display_name} by scanning the QR code below to install the corresponding build." - footnote = params[:footnote] || (app_center_org_name.nil? ? '' : DEFAULT_APP_CENTER_FOOTNOTE) + footnote = params[:footnote] || (app_center_info.org_name.nil? ? '' : DEFAULT_APP_CENTER_FOOTNOTE) body = <<~COMMENT_BODY @@ -52,40 +44,80 @@ def self.run(params) DEFAULT_APP_CENTER_FOOTNOTE = 'Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.'.freeze - def self.extract_app_center_info(app_center_org_name) - if app_center_org_name && defined?(SharedValues::APPCENTER_BUILD_INFORMATION) - lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} - else - {} + # A small model struct to consolidate and pack all the values related to App Center + # + AppCenterInfo = Struct.new(:org_name, :app_name, :display_name, :release_id, :icon, :version, :short_version, :os, :bundle_id) do + # A method to construct an AppCenterInfo instance from the action params, and infer the rest from the `lane_context` if available + def self.from_params(params) + org_name = params[:app_center_org_name] + ctx = if org_name && defined?(SharedValues::APPCENTER_BUILD_INFORMATION) + Fastlane::Actions.lane_context[SharedValues::APPCENTER_BUILD_INFORMATION] || {} + else + {} + end + app_name = params[:app_center_app_name] || ctx['app_name'] + new( + org_name, + app_name, + ctx['app_display_name'] || app_name, + params[:app_center_release_id] || ctx['id'], + ctx['app_icon_url'], + ctx['version'], + ctx['short_version'], + ctx['app_os'], + ctx['bundle_identifier'] + ) end end - def self.build_install_links(download_url, app_center_org_name, app_center_app_name, app_center_app_display_name, app_center_release_id) + # Builds the installation link, QR code URL and extra metadata for download links from the available info + # + # @param [AppCenterInfo] app_center_info The struct containing all the values related to App Center info + # @param [String] download_url The `download_url` parameter passed to the action, if one exists + # @return [(String, Hash)] A tuple containing: + # - The URL for the QR Code + # - A Hash of the extra metadata key/value pairs to add to the existing metadata, to enrich them with download/install links + # + def self.build_install_links(app_center_info, download_url) install_url = nil extra_metadata = {} if download_url install_url = download_url extra_metadata['Direct Download'] = "#{File.basename(install_url)}" end - if app_center_org_name && app_center_app_name - install_url = "https://install.appcenter.ms/orgs/#{app_center_org_name}/apps/#{app_center_app_name}/releases/#{app_center_release_id}" - extra_metadata['App Center Build'] = "#{app_center_app_display_name} \##{app_center_release_id}" + if app_center_info.org_name && app_center_info.app_name + install_url = "https://install.appcenter.ms/orgs/#{app_center_info.org_name}/apps/#{app_center_info.app_name}/releases/#{app_center_info.release_id}" + extra_metadata['App Center Build'] = "#{app_center_info.display_name} \##{app_center_info.release_id}" end UI.user_error!(NO_INSTALL_URL_ERROR_MESSAGE) if install_url.nil? qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{CGI.escape(install_url)}&choe=UTF-8" [qr_code_url, extra_metadata] end + # A method to build the Hash of metadata, based on the explicit ones passed by the user as parameter + the implicit ones from `AppCenterInfo` + # + # @param [Hash] params The action's parameters, as received by `self.run` + # @param [AppCenterInfo] app_center_info The model object containing all the values related to App Center information + # @return [Hash] A hash of all the metadata, gathered from both the explicit and the implicit ones + # def self.consolidate_metadata(params, app_center_info) metadata = params[:metadata]&.transform_keys(&:to_s) || {} - metadata['Build Number'] ||= app_center_info['version'] - metadata['Version'] ||= app_center_info['short_version'] - metadata[app_center_info['app_os'] == 'Android' ? 'Application ID' : 'Bundle ID'] ||= app_center_info['bundle_identifier'] + metadata['Build Number'] ||= app_center_info.version + metadata['Version'] ||= app_center_info.short_version + metadata[app_center_info.os == 'Android' ? 'Application ID' : 'Bundle ID'] ||= app_center_info.bundle_id # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need) metadata['Commit'] ||= ENV.fetch('BUILDKITE_COMMIT', nil) || other_action.last_git_commit[:abbreviated_commit_hash] metadata end + # Creates an HTML `` tag for an icon URL or the image URL to represent a given Buildkite emoji + # + # @param [String] url_or_emoji A `String` which can be: + # - Either a valid URI to an image + # - Or a string formatted like `:emojiname:`, using a valid Buildite emoji name as defined in https://github.com/buildkite/emojis + # @param [String] alt The alt text to use for the `` tag + # @return [String] The `` tag with the proper image and alt tag + # def self.img_tag(url_or_emoji, alt: '') return nil if url_or_emoji.nil? diff --git a/spec/prototype_build_details_comment_action_spec.rb b/spec/prototype_build_details_comment_action_spec.rb index d0f2b97e4..9a0a89bd2 100644 --- a/spec/prototype_build_details_comment_action_spec.rb +++ b/spec/prototype_build_details_comment_action_spec.rb @@ -276,7 +276,7 @@ before do stub_const('Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION', :fake_app_center_build_info) - allow(described_class).to receive(:lane_context).and_return({ fake_app_center_build_info: fake_lane_context }) + allow(Fastlane::Actions).to receive(:lane_context).and_return({ fake_app_center_build_info: fake_lane_context }) end describe 'checking specific content is present' do From f1f93ca16d0002073c62e9df6bdb8f47cfb4acd5 Mon Sep 17 00:00:00 2001 From: Olivier Halligon Date: Wed, 15 Feb 2023 22:31:40 +0100 Subject: [PATCH 23/23] Improve description for `app_icon` parameter Co-authored-by: Gio Lodi --- .../actions/common/prototype_build_details_comment_action.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb index 6b70db3de..5326c5507 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/actions/common/prototype_build_details_comment_action.rb @@ -197,7 +197,7 @@ def self.available_options FastlaneCore::ConfigItem.new( key: :app_icon, env_name: 'FL_PROTOTYPE_BUILD_DETAILS_COMMENT_APP_ICON', - description: "An `:emojicode:` or URL to use for the icon of the app in the message. #{app_center_auto}", + description: "The name of an emoji from the https://github.com/buildkite/emojis list or the full image URL to use for the icon of the app in the message. #{app_center_auto}", type: String, optional: true, default_value_dynamic: true # As it will be extracted from the `lane_context`` if you used `appcenter_upload``