@@ -4,6 +4,7 @@ default_platform(:ios)
44fastlane_require 'xcodeproj'
55fastlane_require 'dotenv'
66fastlane_require 'open-uri'
7+ fastlane_require 'git'
78
89UI . 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' )
942937end
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`.
946962UPLOAD_TO_APP_STORE_COMMON_PARAMS = {
0 commit comments