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] Cherry-pick lastest Fastfile tweaks from trunk into release/7.79 #2553

Merged
Prev Previous commit
Next Next commit
Remove some obsolete lanes + reorder for consistency
Now that the build and the upload are done by separate jobs on CI (both for Prototype Builds in `pipeline.yml` and for Beta/Final builds in `release-builds.yml`), we don't need the previous lanes that did both in one go.

IIRC back when we split the lanes in 2 jobs it was argued that it could be useful to keep the old lanes around in case one would need to run them locally.
But I'd argue that this makes us keep some dead/legacy code around that won't be maintained, and is likely to go stale, and clutters the Fastfile and makes it less easy to navigate and reason about, so I think it's clearer if we remove this unused code after all.
  • Loading branch information
AliSoftware committed Dec 13, 2024
commit 143e57df0b37a2f7784593aac4c433283ec420e2
163 changes: 70 additions & 93 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -513,40 +513,14 @@ platform :ios do
trigger_buildkite_release_build(branch: branch_to_build, beta: false)
end

# Builds the Pocket Casts app and uploads it to TestFlight, for beta-testing or final release
# Builds the app binary for distribution to App Store Connect
#
# @param beta_release [Boolean] If true, the GitHub release will be marked as being a pre-release
# @param skip_prechecks [Boolean] If true, don't run the prechecks and ios_build_preflight (default: false)
# @param skip_confirm [Boolean] If true, avoids any interactive prompt (default: false)
# @param create_release [Boolean] If true, creates a GitHub Release draft after the upload, with zipped xcarchive as artefact
#
# @called_by CI
# Once the app binary is built by this lane, you might want to call:
# - `upload_app_store_connect_build_to_testflight` to upload the binary to TestFlight
# - `symbols_upload` to upload dSYMs to Sentry
# - `create_release_on_github(beta_release: …)` to create the GitHub Release
#
lane :build_and_upload_app_store_connect do |beta_release:, skip_prechecks: false, skip_confirm: false, create_release: false|
require_env_vars!('GITHUB_TOKEN', 'SLACK_WEBHOOK')

unless skip_prechecks
# Verify that there's nothing in progress in the working copy
ensure_git_status_clean unless is_ci

ios_build_preflight
end

UI.important("Building version #{release_version_current} (#{build_code_current}) and uploading to TestFlight")
UI.user_error!('Aborted by user request') unless skip_confirm || UI.confirm('Do you want to continue?')

sentry_check_cli_installed

build_app_store_connect

upload_app_store_connect_build_to_testflight

symbols_upload

create_release_on_github(beta_release: beta_release) if create_release
end

# Builds for distribution to App Store Connect
# @param fetch_code_signing [Boolean] If true, will call `configure_code_signing_app_store` before building. Recommended on CI.
#
lane :build_app_store_connect do |fetch_code_signing: true|
configure_code_signing_app_store if fetch_code_signing
Expand Down Expand Up @@ -577,14 +551,28 @@ platform :ios do
zip(path: APP_STORE_CONNECT_XCARCHIVE_PATH, output_path: APP_STORE_CONNECT_XCARCHIVE_ZIP_PATH)
end

# Builds and distributes via Enterprise account (Prototype Build)
# Distributes the binary to TestFlight
#
lane :build_and_upload_enterprise do
build_enterprise
upload_enterprise
# Typically called after having built the binary with `build_app_store_connect`
#
# @param ipa_path [String] Path to the `.ipa` file to upload to TestFlight
#
lane :upload_app_store_connect_build_to_testflight do |ipa_path: APP_STORE_CONNECT_BUILD_IPA_PATH|
require_env_vars!(*ASC_API_KEY_ENV_VARS)

upload_to_testflight(
ipa: ipa_path,
skip_waiting_for_build_processing: true,
team_id: TEAM_ID_APP_STORE,
api_key: app_store_connect_api_key
)
end

# Builds for Enterprise distribution (Prototype Build)
# Builds the app binary for Enterprise distribution (Prototype Build)
#
# Once the app binary is built, you might want to call `upload_enterprise`
#
# @param fetch_code_signing [Boolean] If true, will call `configure_code_signing_app_store` before building. Recommended on CI.
#
lane :build_enterprise do |skip_code_sign_setup: false|
if skip_code_sign_setup
Expand Down Expand Up @@ -617,28 +605,41 @@ platform :ios do
)
end

# Distributes a local app via Enterprise account (Prototype Build)
# Distributes the Prototype Build to App Center
#
# Typically called after having built the binary with `build_enterprise`
#
# @note Expects the `.ipa` and `.dSYM` files to be present in `ARTIFACTS_FOLDER/PROTOTYPE_BUILD_NAME.{ipa,app.dSYM.zip}`
#
lane :upload_enterprise do
upload_pocket_casts_to_appcenter
require_env_vars!('APPCENTER_API_TOKEN')

commit = ENV.fetch('BUILDKITE_COMMIT', 'Unknown')
pr = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)
release_notes = <<~NOTES
- Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'Unknown')}`\n
- Commit: [#{commit[0...7]}](#{GITHUB_URL}/commit/#{commit})\n
- Pull Request: [##{pr}](#{GITHUB_URL}/pull/#{pr})\n
NOTES

appcenter_upload(
api_token: get_required_env!('APPCENTER_API_TOKEN'),
owner_name: APPCENTER_OWNER_NAME,
owner_type: APPCENTER_OWNER_TYPE,
app_name: APPCENTER_APP_SLUG,
file: File.join(ARTIFACTS_FOLDER, "#{PROTOTYPE_BUILD_NAME}.ipa"),
dsym: File.join(ARTIFACTS_FOLDER, "#{PROTOTYPE_BUILD_NAME}.app.dSYM.zip"),
release_notes: release_notes,
destinations: 'Collaborators',
notify_testers: false
)

next unless is_ci

annotate_pr_with_appcenter_link
annotate_buildkite_with_appcenter_link
end

lane :upload_app_store_connect_build_to_testflight do |ipa_path: APP_STORE_CONNECT_BUILD_IPA_PATH|
require_env_vars!(*ASC_API_KEY_ENV_VARS)

upload_to_testflight(
ipa: ipa_path,
skip_waiting_for_build_processing: true,
team_id: TEAM_ID_APP_STORE,
api_key: app_store_connect_api_key
)
end

# Uploads DSYM Symbols
#
lane :symbols_upload do |dsym_path: APP_STORE_CONNECT_BUILD_DSYMS_PATH|
Expand Down Expand Up @@ -702,7 +703,6 @@ platform :ios do
# @param skip_commit [Boolean] If true, does not commit the changes made to the `.strings` file (default: false)
#
# @note Uses `genstrings` under the hood.
# @called_by `code_freeze`.
#
lane :generate_strings_file_for_glotpress do |skip_commit: false|
# For reference: Other apps run `cocoapods` here (equivalent to `bundle
Expand Down Expand Up @@ -1229,32 +1229,24 @@ platform :ios do
)
end

# Upload a Prototype Build to App Center
# Generate a build number for Prototype Builds, based on the PR number and short commit SHA1
#
# Expects the `.ipa` and `.dSYM` files to be present in `ARTIFACTS_FOLDER/PROTOTYPE_BUILD_NAME.{ipa,app.dSYM.zip}`
# @note This function uses Buildkite-specific ENV vars
#
def upload_pocket_casts_to_appcenter
require_env_vars!('APPCENTER_API_TOKEN')
def generate_prototype_build_number
if ENV['BUILDKITE']
commit = ENV.fetch('BUILDKITE_COMMIT', nil)[0, 7]
branch = ENV.fetch('BUILDKITE_BRANCH', nil)
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)

commit = ENV.fetch('BUILDKITE_COMMIT', 'Unknown')
pr = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)
release_notes = <<~NOTES
- Branch: `#{ENV.fetch('BUILDKITE_BRANCH', 'Unknown')}`\n
- Commit: [#{commit[0...7]}](#{GITHUB_URL}/commit/#{commit})\n
- Pull Request: [##{pr}](#{GITHUB_URL}/pull/#{pr})\n
NOTES
pr_num == 'false' ? "#{branch}-#{commit}" : "pr#{pr_num}-#{commit}"
else
repo = Git.open(PROJECT_ROOT_FOLDER)
commit = repo.current_branch
branch = repo.revparse('HEAD')[0, 7]

appcenter_upload(
api_token: get_required_env!('APPCENTER_API_TOKEN'),
owner_name: APPCENTER_OWNER_NAME,
owner_type: APPCENTER_OWNER_TYPE,
app_name: APPCENTER_APP_SLUG,
file: File.join(ARTIFACTS_FOLDER, "#{PROTOTYPE_BUILD_NAME}.ipa"),
dsym: File.join(ARTIFACTS_FOLDER, "#{PROTOTYPE_BUILD_NAME}.app.dSYM.zip"),
release_notes: release_notes,
destinations: 'Collaborators',
notify_testers: false
)
"#{branch}-#{commit}"
end
end

# Post a comment on the PR with the info + QRCode to the Prototype Build in App Center
Expand Down Expand Up @@ -1282,27 +1274,12 @@ platform :ios do
metadata = version_data.merge(build_type: 'Prototype', 'appcenter:id': appcenter_id)
appcenter_install_url = "https://install.appcenter.ms/orgs/#{APPCENTER_OWNER_NAME}/apps/#{APPCENTER_APP_SLUG}/releases/#{appcenter_id}"
list = metadata.map { |k, v| " - **#{k}**: #{v}" }.join("\n")
buildkite_annotate(context: 'appcenter-info-pocket-casts', style: 'info', message: "Pocket Casts iOS [App Center Build](#{appcenter_install_url}) Info:\n\n#{list}")
end

# Generate a build number for Prototype Builds, based on the PR number and short commit SHA1
#
# @note This function uses Buildkite-specific ENV vars
#
def generate_prototype_build_number
if ENV['BUILDKITE']
commit = ENV.fetch('BUILDKITE_COMMIT', nil)[0, 7]
branch = ENV.fetch('BUILDKITE_BRANCH', nil)
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST', nil)

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

"#{branch}-#{commit}"
end
buildkite_annotate(
context: 'appcenter-info-pocket-casts',
style: 'info',
message: "Pocket Casts iOS [App Center Build](#{appcenter_install_url}) Info:\n\n#{list}"
)
end

#####################################################################################
Expand Down