Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gem 'nokogiri'

### Fastlane Plugins

gem 'fastlane-plugin-firebase_app_distribution', '~> 0.10'
gem 'fastlane-plugin-sentry'
gem 'fastlane-plugin-wpmreleasetoolkit', '~> 13.8'
# gem 'fastlane-plugin-wpmreleasetoolkit', path: '../../release-toolkit'
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ GEM
xcodeproj (>= 1.13.0, < 2.0.0)
xcpretty (~> 0.4.1)
xcpretty-travis-formatter (>= 0.0.3, < 2.0.0)
fastlane-plugin-firebase_app_distribution (0.10.1)
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
google-apis-firebaseappdistribution_v1alpha (~> 0.2.0)
fastlane-plugin-sentry (1.29.0)
os (~> 1.1, >= 1.1.4)
fastlane-plugin-wpmreleasetoolkit (13.8.1)
Expand Down Expand Up @@ -204,6 +207,10 @@ GEM
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
rexml
google-apis-firebaseappdistribution_v1 (0.3.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-firebaseappdistribution_v1alpha (0.2.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-iamcredentials_v1 (0.17.0)
google-apis-core (>= 0.11.0, < 2.a)
google-apis-playcustomapp_v1 (0.13.0)
Expand Down Expand Up @@ -358,6 +365,7 @@ PLATFORMS
DEPENDENCIES
danger-dangermattic (~> 1.2)
fastlane (~> 2)
fastlane-plugin-firebase_app_distribution (~> 0.10)
fastlane-plugin-sentry
fastlane-plugin-wpmreleasetoolkit (~> 13.8)
nokogiri
Expand Down
13 changes: 10 additions & 3 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ APP_SPECIFIC_VALUES = {
package_name: 'org.wordpress.android',
bundle_name_prefix: 'wpandroid',
screenshots_test_class: 'org.wordpress.android.ui.screenshots.WPScreenshotTest',
screenshot_config_file: 'wordpress-config.json'
screenshot_config_file: 'wordpress-config.json',
firebase: {
app_id: '1:124902176124:android:4f9776805ebf421d1620f9',
testers_group: 'wordpress-android---prototype-builds'
}
},
jetpack: {
display_name: 'Jetpack',
Expand All @@ -21,15 +25,18 @@ APP_SPECIFIC_VALUES = {
package_name: 'com.jetpack.android',
bundle_name_prefix: 'jpandroid',
screenshots_test_class: 'org.wordpress.android.ui.screenshots.JPScreenshotTest',
screenshot_config_file: 'jetpack-config.json'
screenshot_config_file: 'jetpack-config.json',
firebase: {
app_id: '1:124902176124:android:97a4443a7dbfb7cc1620f9',
testers_group: 'jetpack-android---prototype-builds'
}
}
}.freeze

UPLOAD_TO_PLAY_STORE_JSON_KEY = File.join(Dir.home, '.configure', 'wordpress-android', 'secrets', 'google-upload-credentials.json')

PROTOTYPE_BUILD_FLAVOR = 'Jalapeno'
PROTOTYPE_BUILD_TYPE = 'Debug'
PROTOTYPE_BUILD_DOMAIN = 'https://cdn.a8c-ci.services'

PROJECT_ROOT_FOLDER = File.dirname(File.expand_path(__dir__))
FASTLANE_FOLDER = File.join(PROJECT_ROOT_FOLDER, 'fastlane')
Expand Down
111 changes: 77 additions & 34 deletions fastlane/lanes/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,14 @@
#####################################################################################
# build_and_upload_wordpress_prototype_build
# -----------------------------------------------------------------------------------
# Build a WordPress Prototype Build and make it available for download
# Build a WordPress Prototype Build and upload it to Firebase App Distribution
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_wordpress_prototype_build
#####################################################################################
desc 'Build a WordPress Prototype Build and make it available for download'
desc 'Build a WordPress Prototype Build and upload it to Firebase App Distribution'
lane :build_and_upload_wordpress_prototype_build do
UI.user_error!("'BUILDKITE_ARTIFACTS_S3_BUCKET' must be defined as an environment variable.") unless ENV['BUILDKITE_ARTIFACTS_S3_BUCKET']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: at first I thought that now that we don't use that BUILDKITE_ARTIFACTS_S3_BUCKET anymore, that PR was missing a deletion of that constant / env var definition from wherever it was defined in this repo… but then I realized that this env var is not defined in this codebase/repo per se, but instead provided via ~/.mobile-secrets/CI/secrets/env. So there's no BUILDKITE_ARTIFACTS_S3_BUCKET definition to remove from this PR after all 👍

UI.user_error!("'FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY' must be defined as an environment variable.") unless ENV['FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY']

version_name = generate_prototype_build_number
gradle(
Expand All @@ -219,21 +219,21 @@
properties: { prototypeBuildVersionName: version_name }
)

upload_prototype_build(product: 'WordPress', version_name: version_name)
upload_prototype_build(app: :wordpress, version_name: version_name)
upload_gutenberg_sourcemaps(app: 'Wordpress', release_version: version_name)
end

#####################################################################################
# build_and_upload_jetpack_prototype_build
# -----------------------------------------------------------------------------------
# Build a Jetpack Prototype Build and make it available for download
# Build a Jetpack Prototype Build and upload it to Firebase App Distribution
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_jetpack_prototype_build
#####################################################################################
desc 'Build a Jetpack Prototype Build and make it available for download'
desc 'Build a Jetpack Prototype Build and upload it to Firebase App Distribution'
lane :build_and_upload_jetpack_prototype_build do
UI.user_error!("'BUILDKITE_ARTIFACTS_S3_BUCKET' must be defined as an environment variable.") unless ENV['BUILDKITE_ARTIFACTS_S3_BUCKET']
UI.user_error!("'FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY' must be defined as an environment variable.") unless ENV['FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY']

version_name = generate_prototype_build_number
gradle(
Expand All @@ -243,7 +243,7 @@
properties: { prototypeBuildVersionName: version_name }
)

upload_prototype_build(product: 'Jetpack', version_name: version_name)
upload_prototype_build(app: :jetpack, version_name: version_name)
upload_gutenberg_sourcemaps(app: 'Jetpack', release_version: version_name)
end

Expand Down Expand Up @@ -310,44 +310,87 @@
"#{build_dir}#{name}"
end

# Uploads the apk built by the `gradle` (i.e. `SharedValues::GRADLE_APK_OUTPUT_PATH`) to S3 then comment on the PR to provide the download link
# Uploads the APK built by `gradle` to Firebase App Distribution and comments on the PR
#
# @param [String] product the display name of the app to upload to S3. 'WordPress' or 'Jetpack'
# @param [Symbol] app the app identifier (:wordpress or :jetpack)
# @param [String] version_name the version name for the build
#
def upload_prototype_build(product:, version_name:)
filename = "#{product.downcase}-prototype-build-#{version_name}.apk"

upload_path = upload_to_s3(
bucket: 'a8c-apps-public-artifacts',
key: filename,
file: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH],
if_exists: :skip
def upload_prototype_build(app:, version_name:)
app_specific_values = APP_SPECIFIC_VALUES[app]
app_display_name = app_specific_values[:display_name]
firebase_settings = app_specific_values[:firebase]

release_notes = <<~NOTES
App: #{app_display_name} Android
Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'N/A')}`
Commit: #{ENV.fetch('BUILDKITE_COMMIT', 'N/A')[0, 7]}
Build Type: #{PROTOTYPE_BUILD_TYPE}
Version: #{version_name}
NOTES

firebase_app_distribution(
app: firebase_settings[:app_id],
service_credentials_json_data: ENV.fetch('FIREBASE_APP_DISTRIBUTION_ACCOUNT_KEY', nil),
release_notes: release_notes,
groups: firebase_settings[:testers_group]
)

return if ENV['BUILDKITE_PULL_REQUEST'].nil?
return unless is_ci
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: I first this change picked my attention because I noticed it was not checking about the build being on a PR anymore but instead about it being on CI in general (and thus would run the commands even for e.g. builds triggered on trunk, not on PRs). So I was about to comment about that unexpected behavior change.

But then I realized that the test "is it a PR" was (correctly) moved directly into the comment_on_pr_with_prototype_build_install_link helper (line 362–363), so this is all good after all 👍


install_url = "#{PROTOTYPE_BUILD_DOMAIN}/#{upload_path}"
comment_body = prototype_build_details_comment(
app_display_name: product,
app_icon: ":#{product.downcase}:", # Use Buildkite emoji based on product name
download_url: install_url,
metadata: { Flavor: PROTOTYPE_BUILD_FLAVOR, 'Build Type': PROTOTYPE_BUILD_TYPE, Version: version_name },
footnote: '<em>Note: Google Login is not supported on these builds.</em>',
fold: true
comment_on_pr_with_prototype_build_install_link(
project: GITHUB_REPO,
app_display_name: "#{app_display_name} Android",
app_icon: ":#{app}:",
metadata: {
Flavor: PROTOTYPE_BUILD_FLAVOR,
'Build Type': PROTOTYPE_BUILD_TYPE,
Version: version_name
}
)

annotate_ci_build_with_prototype_build_install_link(app_display_name: app_display_name)
end

# Adds an install link for prototype build via PR comment
#
# @param [String] project the GitHub repository (e.g., 'wordpress-mobile/WordPress-Android')
# @param [String] app_display_name the display name of the app (e.g., 'WordPress Android')
# @param [String] app_icon the Buildkite emoji for the app (e.g., ':wordpress:')
# @param [Hash] metadata additional metadata to display in the comment
#
def comment_on_pr_with_prototype_build_install_link(project:, app_display_name:, app_icon: nil, metadata: {})
pr_number = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)
return unless pr_number && pr_number != 'false'

comment_on_pr(
project: GITHUB_REPO,
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST', nil)),
reuse_identifier: "#{product.downcase}-prototype-build-link",
body: comment_body
project: project,
pr_number: Integer(pr_number),
reuse_identifier: "#{app_display_name.downcase.gsub(' ', '-')}-prototype-build-link",
body: prototype_build_details_comment(
app_display_name: app_display_name,
app_icon: app_icon,
metadata: metadata,
footnote: '<em>Note: Google Login is not supported on these builds.</em>'
)
)
end

# If running in Buildkite, annotates the current build with prototype build info
#
# @param [String] app_display_name the display name of the app
#
def annotate_ci_build_with_prototype_build_install_link(app_display_name:)
return unless ENV['BUILDKITE']

message = "#{product} Prototype Build: [#{filename}](#{install_url})"
buildkite_annotate(style: 'info', context: "prototype-build-#{product}", message: message)
buildkite_metadata(set: { versionName: version_name, 'build:flavor': PROTOTYPE_BUILD_FLAVOR, 'build:type': PROTOTYPE_BUILD_TYPE })
install_link = 'Firebase App Distribution'
install_url = lane_context[SharedValues::FIREBASE_APP_DISTRO_RELEASE]&.dig(:testingUri)
install_link = "[#{install_link}](#{install_url})" unless install_url.nil?

buildkite_annotate(
style: 'success',
context: "prototype-build-#{app_display_name.downcase.gsub(' ', '-')}",
message: "#{app_display_name} Prototype Build uploaded to #{install_link}"
)
end

# This function is Buildkite-specific
Expand Down
Loading