Skip to content

Commit de0c32a

Browse files
committed
Use consistent build versions
1 parent d59b875 commit de0c32a

4 files changed

Lines changed: 32 additions & 27 deletions

File tree

.buildkite/commands/installable-build-jetpack.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ echo "--- :closed_lock_with_key: Installing Secrets"
1414
bundle exec fastlane run configure_apply
1515

1616
echo "--- :hammer_and_wrench: Building"
17-
bundle exec fastlane build_and_upload_jetpack_installable_build build_number:$BUILDKITE_PULL_REQUEST
17+
bundle exec fastlane build_and_upload_jetpack_installable_build

.buildkite/commands/installable-build-wordpress.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ echo "--- :closed_lock_with_key: Installing Secrets"
1414
bundle exec fastlane run configure_apply
1515

1616
echo "--- :hammer_and_wrench: Building"
17-
bundle exec fastlane build_and_upload_installable_build build_number:$BUILDKITE_PULL_REQUEST
17+
bundle exec fastlane build_and_upload_installable_build

fastlane/Fastfile

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ default_platform(:ios)
44
fastlane_require 'xcodeproj'
55
fastlane_require 'dotenv'
66
fastlane_require 'open-uri'
7+
fastlane_require 'git'
78

89
UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Helper.bundler?
910

@@ -547,17 +548,11 @@ platform :ios do
547548
# Get the current build version, and update it if needed
548549
version_config_path = File.join(PROJECT_ROOT_FOLDER, 'config', 'Version.internal.xcconfig')
549550
versions = Xcodeproj::Config.new(File.new(version_config_path)).to_hash
550-
build_number = versions['VERSION_LONG']
551-
552-
if options.key?(:build_number)
553-
build_number = options[:build_number]
554-
555-
UI.message("Updating build version to #{build_number}")
556-
557-
versions['VERSION_LONG'] = build_number
558-
new_config = Xcodeproj::Config.new(versions)
559-
new_config.save_as(Pathname.new(version_config_path))
560-
end
551+
build_number = get_build_number
552+
UI.message("Updating build version to #{build_number}")
553+
versions['VERSION_LONG'] = build_number
554+
new_config = Xcodeproj::Config.new(versions)
555+
new_config.save_as(Pathname.new(version_config_path))
561556

562557
gym(
563558
scheme: 'WordPress Alpha',
@@ -941,6 +936,27 @@ def ensure_sentry_installed
941936
UI.user_error('sentry-cli not installed') unless sh('command -v sentry-cli')
942937
end
943938

939+
# This function is Buildkite-specific
940+
def get_build_number
941+
942+
# This should work outside of Buildkite
943+
if ENV['BUILDKITE'] != 'true'
944+
require 'git'
945+
946+
repo = Git.open(PROJECT_ROOT_FOLDER)
947+
current_branch = repo.current_branch
948+
current_commit = repo.revparse('HEAD')[0, 7]
949+
950+
return "#{current_branch}-#{current_commit}"
951+
end
952+
953+
if ENV['BUILDKITE_PULL_REQUEST'] == 'false'
954+
return "#{ENV['BUILDKITE_BRANCH']}-#{ENV['BUILDKITE_COMMIT'][0,7]}"
955+
end
956+
957+
return "pr#{ENV['BUILDKITE_PULL_REQUEST']}-#{ENV['BUILDKITE_COMMIT'][0,7]}"
958+
end
959+
944960
# Application-agnostic settings for the `upload_to_app_store` action, also
945961
# known as `deliver`.
946962
UPLOAD_TO_APP_STORE_COMMON_PARAMS = {

fastlane/Jetpack-Fastfile

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,13 @@ APP_IDENTIFIER = 'com.automattic.jetpack'
1717
desc "Builds and uploads a Jetpack installable build"
1818
lane :build_and_upload_jetpack_installable_build do | options |
1919
jetpack_alpha_code_signing
20-
require 'git'
2120

2221
# Get the current build version, and update it if needed
23-
version_config_path = File.join(PROJECT_ROOT_FOLDER, "config", "Version.internal.xcconfig")
22+
version_config_path = File.join(PROJECT_ROOT_FOLDER, 'config', 'Version.internal.xcconfig')
2423
versions = Xcodeproj::Config.new(File.new(version_config_path)).to_hash
25-
26-
short_hash = last_git_commit[:abbreviated_commit_hash]
27-
28-
build_number = [
29-
short_hash,
30-
'-',
31-
Time.new.strftime("%Y%m%d-%H%M")
32-
].join
33-
24+
build_number = get_build_number
3425
UI.message("Updating build version to #{build_number}")
35-
36-
versions["VERSION_SHORT"] = "0.1"
37-
versions["VERSION_LONG"] = build_number
26+
versions['VERSION_LONG'] = build_number
3827
new_config = Xcodeproj::Config.new(versions)
3928
new_config.save_as(Pathname.new(version_config_path))
4029

0 commit comments

Comments
 (0)