@@ -73,6 +73,7 @@ platform :mac do
7373 desc "Build, archive and sign the app for distribution"
7474 lane :create_and_sign_release do |options |
7575 remove_zip = options . fetch ( :remove_zip , true )
76+ version = options . fetch ( :version , nil )
7677 setup_ci if ENV [ 'CI' ]
7778
7879 personal_github_access_token = load_secret ( "FASTLANE_MACH_REPO_GITHUB_ACCESS_TOKEN" )
@@ -167,11 +168,9 @@ platform :mac do
167168
168169 sparkle_output = sh ( "echo '#{ sparkle_secret_key } ' | #{ sparkle_path } /bin/sign_update #{ app_zip_path } --ed-key-file -" )
169170 app_config_path = File . absolute_path ( "../command.shared.xcconfig" )
170- version = sh ( "cat #{ app_config_path } | grep APP_VERSION=" ) . split ( "APP_VERSION=" ) . last . strip
171-
172- puts "version: #{ version } "
171+ version = version || sh ( "cat #{ app_config_path } | grep APP_VERSION=" ) . split ( "APP_VERSION=" ) . last . strip
173172
174- puts "Notarization completed successfully. app_path: #{ app_path } "
173+ puts "Notarization completed successfully. version: #{ version } , app_path: #{ app_path } "
175174
176175 appcast_template_path = File . absolute_path ( "./appcast.template.xml" )
177176 appcast_path = File . absolute_path ( "./appcast.xml" )
@@ -187,7 +186,23 @@ platform :mac do
187186
188187 desc "Build, archive, sign and publish the app for distribution"
189188 lane :distribute_release do
190- result = create_and_sign_release ( remove_zip : false )
189+ app_config_path = File . absolute_path ( "../command.shared.xcconfig" )
190+ version = sh ( "cat #{ app_config_path } | grep APP_VERSION=" ) . split ( "APP_VERSION=" ) . last . strip
191+ # Look for an existing version tag. If one exist, bump the version.
192+ existing_version = sh ( "git ls-remote origin refs/tags/v#{ version } " ) . strip
193+ if existing_version . empty?
194+ puts "Using version: #{ version } "
195+ else
196+ version_parts = version . split ( '.' )
197+ version_parts [ -1 ] = ( version_parts [ -1 ] . to_i + 1 ) . to_s
198+ new_version = version_parts . join ( '.' )
199+ puts "Bumping version from #{ version } to #{ new_version } ."
200+
201+ sh ( "sed -i '' 's/APP_VERSION=#{ version } /APP_VERSION=#{ new_version } /' #{ app_config_path } " )
202+ version = new_version
203+ end
204+
205+ result = create_and_sign_release ( remove_zip : false , version : version )
191206 version = result [ :version ]
192207 app_zip_path = result [ :app_zip_path ]
193208 build_path = result [ :build_path ]
@@ -203,19 +218,13 @@ platform :mac do
203218 upload_assets : app_zip_path
204219 )
205220
206- set_github_release (
207- api_token : load_secret ( "GITHUB_TEST_TOKEN" ) ,
208- server_url : "https://api.github.com" ,
209- repository_name : "gsabran/test" ,
210- name : "v#{ version } " ,
211- tag_name : "v#{ version } " ,
212- description : "test release" ,
213- commitish : "main" ,
214- upload_assets : app_zip_path
215- )
216-
217221 sh ( "rm -rf #{ build_path } " )
218222
219- puts "👉 Don't forget to push the changes to appcast.xml"
223+ create_pull_request (
224+ api_token : load_secret ( "GH_WRITE_TOKEN" ) ,
225+ repo : "getcmd-dev/cmd" ,
226+ title : "Release v#{ version } " ,
227+ base : "main"
228+ )
220229 end
221230end
0 commit comments