Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WordPress and Jetpack Installable Builds #16642

Merged
merged 8 commits into from
Jun 10, 2022
10 changes: 10 additions & 0 deletions .buildkite/commands/jetpack-installable-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu

echo "--- :rubygems: Setting up Gems"
install_gems

echo "--- :closed_lock_with_key: Installing Secrets"
bundle exec fastlane run configure_apply

echo "--- :hammer_and_wrench: Building"
bundle exec fastlane build_and_upload_jetpack_installable_build
10 changes: 10 additions & 0 deletions .buildkite/commands/wordpress-installable-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash -eu

echo "--- :rubygems: Setting up Gems"
install_gems

echo "--- :closed_lock_with_key: Installing Secrets"
bundle exec fastlane run configure_apply

echo "--- :hammer_and_wrench: Building"
bundle exec fastlane build_and_upload_wordpress_installable_build
24 changes: 10 additions & 14 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ steps:
plugins: *common_plugins
artifact_paths:
- "**/build/reports/checkstyle/checkstyle.*"
agents:
queue: "android"
Comment on lines -15 to -16
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a legacy from previous iterations? Or is there something special about this that relates with the installable builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good question – it's a legacy-ish setup. The "best practice" is to define this in the Buildkite configuration so it doesn't need to be repeated over and over in the config. That said, I can see an argument for being safer. For now, it aligns with the other projects and we can revisit it later, if needed? 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

The "best practice" is to define this in the Buildkite configuration so it doesn't need to be repeated over and over in the config. That said, I can see an argument for being safer.

I can see the argument for being safer, too, but I think it's not as strong as the one for defining our steps in such a way that they can all run on the default kind of agent for the pipeline, and only specify a custom queue for those which do something special.


- label: "ktlint"
command: |
Expand All @@ -22,8 +20,6 @@ steps:
plugins: *common_plugins
artifact_paths:
- "**/build/ktlint.xml"
agents:
queue: "android"

- label: "detekt"
command: |
Expand All @@ -32,8 +28,6 @@ steps:
plugins: *common_plugins
artifact_paths:
- "**/build/reports/detekt/detekt.html"
agents:
queue: "android"

- label: "lint"
command: |
Expand All @@ -42,29 +36,31 @@ steps:
plugins: *common_plugins
artifact_paths:
- "**/build/reports/lint-results*.*"
agents:
queue: "android"

- label: "Test WordPress"
command: |
cp gradle.properties-example gradle.properties
./gradlew testWordpressVanillaRelease
plugins: *common_plugins
agents:
queue: "android"

- label: "Test WordPressProcessors"
command: |
cp gradle.properties-example gradle.properties
./gradlew :libs:WordPressProcessors:test
plugins: *common_plugins
agents:
queue: "android"

- label: "Test ImageEditor"
command: |
cp gradle.properties-example gradle.properties
./gradlew :libs:image-editor:ImageEditor:test
plugins: *common_plugins
agents:
queue: "android"

- label: "🛠 WordPress Installable Build"
command: ".buildkite/commands/wordpress-installable-build.sh"
if: build.pull_request.id != null
plugins: *common_plugins

- label: "🛠 Jetpack Installable Build"
command: ".buildkite/commands/jetpack-installable-build.sh"
if: build.pull_request.id != null
plugins: *common_plugins
45 changes: 0 additions & 45 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,47 +31,6 @@ commands:

version: 2.1
jobs:
Installable Build:
executor:
name: android/default
api-version: "29"
steps:
- git/shallow-checkout
- bundle-install/bundle-install:
cache_key_prefix: installable-build-v4
- run:
name: Copy Secrets
command: FASTLANE_SKIP_UPDATE_CHECK=1 bundle exec fastlane run configure_apply
- update-gradle-memory
- android/restore-gradle-cache
- run:
name: Set version environment variable
command: |
if [ -n "$CIRCLE_PULL_REQUEST" ]; then
PR_NUMBER=$(basename $CIRCLE_PULL_REQUEST)
PREFIX="pr-${PR_NUMBER}"
else
PREFIX="$CIRCLE_BRANCH"
fi

VERSION_NAME="${PREFIX}-build-${CIRCLE_BUILD_NUM}"
echo "export VERSION_NAME=$VERSION_NAME" >> $BASH_ENV
- run:
name: Build WordPress APK
command: ./gradlew --stacktrace assembleWordpressJalapenoDebug -PinstallableBuildVersionName="$VERSION_NAME"
- run:
name: Build Jetpack APK
command: ./gradlew --stacktrace assembleJetpackJalapenoDebug -PinstallableBuildVersionName="$VERSION_NAME"
- android/save-gradle-cache
- run:
name: Prepare APK
command: |
mkdir -p Artifacts
mv WordPress/build/outputs/apk/wordpressJalapeno/debug/org.wordpress.android-wordpress-jalapeno-debug.apk "Artifacts/WordPress-${VERSION_NAME}.apk"
mv WordPress/build/outputs/apk/jetpackJalapeno/debug/org.wordpress.android-jetpack-jalapeno-debug.apk "Artifacts/Jetpack-${VERSION_NAME}.apk"
- store_artifacts:
path: Artifacts
destination: Artifacts
Release Build:
parameters:
alpha:
Expand Down Expand Up @@ -361,10 +320,6 @@ workflows:
- << pipeline.parameters.release_build >>
jobs:
- Dependency Tree Diff
- Installable Build:
filters:
branches:
ignore: /pull\/[0-9]+/
- Connected Tests:
post-to-slack: true
# Always run connected tests on trunk and release branches
Expand Down
1 change: 1 addition & 0 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ APP_SPECIFIC_VALUES = {
}.freeze

UPLOAD_TO_PLAY_STORE_JSON_KEY = File.join(Dir.home, '.configure', 'wordpress-android', 'secrets', 'google-upload-credentials.json')
INSTALLABLE_BUILD_DOMAIN = 'https://d2twmm2nzpx3bg.cloudfront.net'

########################################################################
# Environment
Expand Down
4 changes: 2 additions & 2 deletions fastlane/Pluginfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ group :screenshots, optional: true do
gem 'rmagick', '~> 4.1'
end

gem 'fastlane-plugin-wpmreleasetoolkit', git: 'git@github.com:wordpress-mobile/release-toolkit.git', branch: 'trunk'
# gem 'fastlane-plugin-wpmreleasetoolkit', '~> 4.1'
#gem 'fastlane-plugin-wpmreleasetoolkit', git: 'git@github.com:wordpress-mobile/release-toolkit.git', branch: 'trunk'
gem 'fastlane-plugin-wpmreleasetoolkit', '~> 4.1'
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid this was an intentional breakage of our convention of always pointing to a stable release of trunk.

We haven't shipped a new version of the toolkit since merging the GlotPress 429 workaround. See the current CHANGELOG.md.

Although, thinking about it... It's conceivable that we'll have a new release out before the next beta (as we don't need to download from GlotPress during code freeze, and the release branch "correctly" points to trunk still), so maybe we can keep this as is.

(I'm leaving a comment about making a release instead of doing it myself because I'm at EOD and I don't want to start something else at this point)

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed by releasing release-toolkit 4.2.0 earlier today (which includes both the changes from 4.1 but also the changes that WPAndroid was pointing to to get the rate limiting fix from the toolkit which were not released yet before), then updating the Pluginfile and re-ran bundle install to update the Gemfile.lock accordingly.

See 7e3abb5

84 changes: 84 additions & 0 deletions fastlane/lanes/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,50 @@
end
end

#####################################################################################
# build_and_upload_installable_build
# -----------------------------------------------------------------------------------
# Build a WordPress Installable Build and make it available for download
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_installable_build
#####################################################################################
desc "Build an Installable Build and make it available for download"
lane :build_and_upload_wordpress_installable_build do | options |
Copy link
Contributor

Choose a reason for hiding this comment

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

| options |, WordPress-style formatting 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

rubocop would definitively have complained about that one… if we had it set up to lint the fastlane/lanes/*.rb files 😅 (one day…)

Copy link
Contributor

Choose a reason for hiding this comment

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

I took the liberty to address those myself in 144ff03


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

gradle(
task: "assemble",
flavor: "WordPressJalapeno",
build_type: "Debug"
)

upload_installable_build(product: 'WordPress')
end

#####################################################################################
# build_and_upload_jetpack_installable_build
# -----------------------------------------------------------------------------------
# Build a Jetpack Installable Build and make it available for download
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_installable_build
#####################################################################################
desc "Build an Installable Build and make it available for download"
lane :build_and_upload_jetpack_installable_build do | options |

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

gradle(
task: "assemble",
flavor: "JetpackJalapeno",
build_type: "Debug"
)

upload_installable_build(product: 'Jetpack')
end

#####################################################################################
# build_bundle
# -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -262,4 +306,44 @@
end
"#{build_dir}#{name}"
end

def upload_installable_build(product:)

filename = "#{product.downcase}-installable-build-#{generate_installable_build_number}.apk"

upload_path = upload_to_s3(
bucket: 'a8c-apps-public-artifacts',
key: filename,
file: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
)

install_url = "#{INSTALLABLE_BUILD_DOMAIN}/#{upload_path}"
qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{URI::encode( install_url )}&choe=UTF-8"
comment_body = "You can test the #{product} changes on this Pull Request by <a href='#{install_url}'>downloading an installable build (#{filename})</a>, or scanning this QR code:<br><a href='#{install_url}'><img src='#{qr_code_url}' width='250' height='250' /></a>"

comment_on_pr(
project: GHHELPER_REPO,
pr_number: Integer(ENV['BUILDKITE_PULL_REQUEST']),
reuse_identifier: "#{product.downcase}-installable-build-link",
body: comment_body
) unless ENV['BUILDKITE_PULL_REQUEST'].nil?
end

# This function is Buildkite-specific
def generate_installable_build_number

if ENV['BUILDKITE']
commit = ENV['BUILDKITE_COMMIT'][0,7]
branch = ENV['BUILDKITE_BRANCH'].parameterize
pr_num = ENV['BUILDKITE_PULL_REQUEST']

return pr_num == 'false' ? "#{branch}-#{commit}" : "pr#{pr_num}-#{commit}"
else
repo = Git.open(PROJECT_ROOT_FOLDER)
commit = repo.current_branch.parameterize
branch = repo.revparse('HEAD')[0, 7]

return "#{branch}-#{commit}"
end
end
end