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

[Tooling] Create a Single, Unified GitHub Releases for WP Alpha, WP Beta & JP Beta #15319

Merged
merged 12 commits into from
Sep 14, 2021
Merged
31 changes: 26 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
init-submodules: true
- checkout-submodules
- bundle-install/bundle-install:
cache_key_prefix: release-build-v2
cache_key_prefix: &release-build-cache-key release-build-v2
- run:
name: Copy Secrets
command: FASTLANE_SKIP_UPDATE_CHECK=1 bundle exec fastlane run configure_apply
Expand All @@ -124,7 +124,7 @@ jobs:
name: Build << parameters.app >> Zalpha
command: |
if [[ ${APP_VERSION} == *"-rc-"* ]]; then
bundle exec fastlane build_alpha app:<< parameters.app >> skip_confirm:true skip_prechecks:true create_release:true upload_to_play_store:true
bundle exec fastlane build_alpha app:<< parameters.app >> skip_confirm:true skip_prechecks:true upload_to_play_store:true
fi
no_output_timeout: 15m
- unless:
Expand All @@ -134,22 +134,41 @@ jobs:
name: Build << parameters.app >> Vanilla
command: |
if [[ ${APP_VERSION} == *"-rc-"* ]]; then
bundle exec fastlane build_beta app:<< parameters.app >> skip_confirm:true skip_prechecks:true create_release:true upload_to_play_store:true
bundle exec fastlane build_beta app:<< parameters.app >> skip_confirm:true skip_prechecks:true upload_to_play_store:true
else
bundle exec fastlane build_and_upload_release app:<< parameters.app >> skip_confirm:true skip_prechecks:true create_release:true upload_to_play_store:true
bundle exec fastlane build_and_upload_release app:<< parameters.app >> skip_confirm:true skip_prechecks:true upload_to_play_store:true
fi
no_output_timeout: 15m
- android/save-gradle-cache
- store_artifacts:
path: build
destination: Artifacts
- persist_to_workspace:
root: build
paths: ['*.aab'] # So they are made available for the "Create GitHub Release" job
- slack/status:
include_job_number_field: false
include_project_field: false
include_visit_job_action: false
webhook: '${SLACK_BUILD_WEBHOOK}'
failure_message: '${SLACK_FAILURE_MESSAGE}'
success_message: '${SLACK_SUCCESS_MESSAGE}'
Create GitHub Release:
executor:
name: android/default
api-version: "29"
steps:
- git/shallow-checkout:
init-submodules: false
- bundle-install/bundle-install:
cache_key_prefix: *release-build-cache-key
- attach_workspace:
at: build # Restore *.aab files built from "Release Build" jobs so we can attach them to the GitHub release
- run:
name: Create GitHub Release
command: |
bundle exec fastlane create_gh_release


Connected Tests:
parameters:
Expand Down Expand Up @@ -404,4 +423,6 @@ workflows:
- Release Build:
name: "Release: JP Beta"
app: jetpack
alpha: false
alpha: false
- Create GitHub Release:
requires: ["Release: WP Alpha", "Release: WP Beta", "Release: JP Beta"]
133 changes: 75 additions & 58 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,13 @@ REPOSITORY_NAME="WordPress-Android"
# This lane builds the final release of the app and uploads it
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_release [skip_confirm:<skip confirm>] [skip_prechecks:<skip prechecks>] [create_release:<Create release on GH> ]
# bundle exec fastlane build_and_upload_release app:<wordpress|jetpack> [skip_confirm:<skip confirm>] [skip_prechecks:<skip prechecks>] [create_release:<Create release on GH> ]
#
# Example:
# bundle exec fastlane build_and_upload_release
# bundle exec fastlane build_and_upload_release skip_confirm:true
# bundle exec fastlane build_and_upload_release skip_prechecks:true
# bundle exec fastlane build_and_upload_release create_release:true
# bundle exec fastlane build_and_upload_release app:wordpress
# bundle exec fastlane build_and_upload_release app:wordpress skip_confirm:true
# bundle exec fastlane build_and_upload_release app:jetpack skip_prechecks:true
# bundle exec fastlane build_and_upload_release app:wordpress create_release:true
#####################################################################################
desc "Builds and updates for distribution"
lane :build_and_upload_release do |options|
Expand All @@ -445,7 +445,7 @@ REPOSITORY_NAME="WordPress-Android"
upload_build_to_play_store(version: version, track: "production", app: app)

if (options[:create_release])
create_gh_release(version: version, app: app)
create_gh_release(app: app, version: version)
end
end

Expand Down Expand Up @@ -483,12 +483,12 @@ REPOSITORY_NAME="WordPress-Android"
# This lane builds the app it for internal testing and optionally uploads it
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_alpha [skip_confirm:<skip confirm>] [upload_to_play_store:<upload to play store>] [create_release:<Create release on GH> ]
# bundle exec fastlane build_alpha app:<wordpress|jetpack> [skip_confirm:<true|false>] [upload_to_play_store:<true|false>] [create_release:<true|false>]
#
# Example:
# bundle exec fastlane build_alpha
# bundle exec fastlane build_alpha skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_alpha create_release:true
# bundle exec fastlane build_alpha app:wordpress create_release:true
# bundle exec fastlane build_alpha app:wordpress skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_alpha app:jetpack
#####################################################################################
desc "Builds and updates for distribution"
lane :build_alpha do |options|
Expand All @@ -506,7 +506,7 @@ REPOSITORY_NAME="WordPress-Android"
end

if (options[:create_release])
create_gh_release(version: version, prerelease: true, app: app)
create_gh_release(app: app, version: version, prerelease: true)
end
end

Expand All @@ -516,12 +516,12 @@ REPOSITORY_NAME="WordPress-Android"
# This lane builds the app it for internal testing and optionally uploads it
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_beta [skip_confirm:<skip confirm>] [upload_to_play_store:<upload to play store>] [create_release:<Create release on GH> ]
# bundle exec fastlane build_beta app:<wordpress|jetpack> [skip_confirm:<true|false>] [upload_to_play_store:<true|false>] [create_release:<true|false>]
#
# Example:
# bundle exec fastlane build_beta
# bundle exec fastlane build_beta skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_beta create_release:true
# bundle exec fastlane build_beta app:wordpress create_release:true
# bundle exec fastlane build_beta app:wordpress skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_beta app:jetpack create_release:true
#####################################################################################
desc "Builds and updates for distribution"
lane :build_beta do |options|
Expand All @@ -539,7 +539,7 @@ REPOSITORY_NAME="WordPress-Android"
end

if (options[:create_release])
create_gh_release(version: version, prerelease: true, app: app)
create_gh_release(app: app, version: version, prerelease: true)
end
end

Expand All @@ -549,12 +549,12 @@ REPOSITORY_NAME="WordPress-Android"
# This lane builds the app for restricted internal testing, and optionally uploads it to PlayStore's Internal track
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_internal [app:<name of app>] [skip_confirm:<skip confirm>] [upload_to_play_store:<upload to play store>] [create_release:<Create release on GH> ]
# bundle exec fastlane build_internal app:<wordpress|jetpack>] [skip_confirm:<true|false>] [upload_to_play_store:<true|false>] [create_release:<true|false>]
#
# Example:
# bundle exec fastlane build_internal
# bundle exec fastlane build_internal skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_internal create_release:true
# bundle exec fastlane build_internal app:wordpress
# bundle exec fastlane build_internal app:wordpress skip_confirm:true upload_to_play_store:true
# bundle exec fastlane build_internal app:jetpack create_release:true
#####################################################################################
desc "Builds and updates for internal testing"
lane :build_internal do |options|
Expand All @@ -572,7 +572,7 @@ REPOSITORY_NAME="WordPress-Android"
end

if (options[:create_release])
create_gh_release(version: version, prerelease: true, app: app)
create_gh_release(app: app, version: version, prerelease: true)
end
end

Expand Down Expand Up @@ -940,6 +940,59 @@ REPOSITORY_NAME="WordPress-Android"
)
end

#####################################################################################
# create_gh_release
# -----------------------------------------------------------------------------------
# This lane creates a GitHub release for the current version
# - Attaching the existing .aab files in `build/` as the release assets
# - Using the WP & JP release_notes.txt as description
# - If `prerelease:<true|false>`` is not provided, the pre-release status will be inferred from the version name
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane create_gh_release [app:<wordpress|jetpack>] [version:<Hash{name,code}>] [prerelease:<true|false>]
#
# Examples:
# bundle exec fastlane create_gh_release # Guesses prerelease status based on version name. Includes existing assets for WPAlpha+WPBeta+JPBeta
# bundle exec fastlane create_gh_release app:wordpress prerelease:true # Includes existing assets for WPAlpha+WPBeta
# bundle exec fastlane create_gh_release version:{name:12.3-rc-4} prerelease:true # Includes existing assets for WPAlpha+WPBeta+JPBeta 12.3-rc-4
AliSoftware marked this conversation as resolved.
Show resolved Hide resolved
# bundle exec fastlane create_gh_release app:jetpack version:{name:12.3-rc-4} prerelease:true # Includes only existing asset for JPBeta 12.3-rc-4
#####################################################################################
lane :create_gh_release do |options|
apps = options[:app].nil? ? ['wordpress', 'jetpack'] : [options[:app]]
versions = options[:version].nil? ? [android_get_alpha_version(app: 'wp_jp'), android_get_release_version(app: 'wp_jp')] : [options[:version]]

release_assets = apps.flat_map do |app|
versions.flat_map { |vers| bundle_file_path(app, vers) }
end.select { |f| File.exist?(f) }

release_title = versions.last['name']
set_prerelease_flag = options[:prerelease].nil? ? /-rc-|alpha-/.match?(release_title) : options[:prerelease]

UI.message("Creating release for #{release_title} with the following assets: #{release_assets.inspect}")

app_titles = { 'wordpress' => 'WordPress', 'jetpack' => 'Jetpack' }
tmp_file = File.absolute_path('unified-release-notes.txt')
unified_notes = apps.map do |app|
notes = File.read(release_notes_path(app))
"\#\# #{app_titles[app]}\n\n#{notes}"
end.join("\n\n")
File.write(tmp_file, unified_notes)

create_release(
repository: GHHELPER_REPO,
version: release_title,
release_notes_file_path: tmp_file,
prerelease: set_prerelease_flag,
release_assets: release_assets.join(',')
)

FileUtils.rm(tmp_file)
end

#####################################################################################
# Private lanes
#####################################################################################

#####################################################################################
# trigger_ci
# -----------------------------------------------------------------------------------
Expand Down Expand Up @@ -983,9 +1036,6 @@ REPOSITORY_NAME="WordPress-Android"
end
end

#####################################################################################
# Private lanes
#####################################################################################
private_lane :delete_old_changelogs do |options|
app = options[:app] || 'wordpress'
app_values = APP_SPECIFIC_VALUES[app.to_sym]
Expand All @@ -994,28 +1044,6 @@ REPOSITORY_NAME="WordPress-Android"
end
end

private_lane :create_gh_release do | options |
set_prerelease_flag = options[:prerelease].nil? ? false : options[:prerelease]
version = options[:version]

if version.nil?
UI.message("Ignoring request to create GH version since version specified is nil")
next
end

apk_file_path = universal_apk_file_path(options[:app], version)
aab_file_path = bundle_file_path(options[:app], version)
# APKs built on CI are unsigned, so don't upload them until we have a fix
release_assets = [aab_file_path]
release_assets.append(apk_file_path) unless is_ci
create_release(repository:GHHELPER_REPO,
version: version["name"],
release_notes_file_path: release_notes_path(options[:app]),
prerelease: set_prerelease_flag,
release_assets: release_assets.join(',')
)
end

private_lane :cleanup_release_files do | options |
files = options[:files]

Expand Down Expand Up @@ -1046,20 +1074,9 @@ REPOSITORY_NAME="WordPress-Android"
]
end

def universal_apk_name(app, version)
basenames = { wordpress: 'wpandroid', jetpack: 'jpandroid' }
basename = basenames[app.to_sym] || basenames[:wordpress]
"#{basename}-#{version["name"]}-universal.apk"
end

def bundle_file_path(app, version)
prefix = app.downcase == "jetpack" ? JP_PREFIX : WP_PREFIX
project_root = File.dirname(File.expand_path(File.dirname(__FILE__)))
File.join(project_root, "build", "#{prefix}-#{ version["name"] }.aab")
end

def universal_apk_file_path(app, version)
project_root = File.dirname(File.expand_path(File.dirname(__FILE__)))
File.join(project_root, "build", universal_apk_name(app, version))
File.join(project_root, "build", "#{prefix}-#{version["name"]}.aab")
end
end