@@ -430,49 +430,80 @@ platform :ios do
430430 # 1. Signing: usa direttamente configurazione Xcode (Automatic Signing)
431431 UI . message ( '[release] Using Xcode Automatic Signing' )
432432
433- # 2. Versioning: se NEW_VERSION impostato lo usa, altrimenti incrementa patch
434- # MARKETING_VERSION gestita da Xcode build settings (GENERATE_INFOPLIST_FILE=YES)
433+ # 2. Versioning manuale (niente agvtool / increment_* Fastlane)
434+ plist_path = "MirrorSmokerStopper/Info.plist"
435+ # Leggi versione corrente dal plist (fallback 1.0.0 se mancante)
436+ current_v = ` /usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "#{ plist_path } " 2>/dev/null` . strip
437+ current_v = "1.0.0" if current_v . empty?
435438 if ENV [ 'NEW_VERSION' ] && !ENV [ 'NEW_VERSION' ] . empty?
436- increment_version_number (
437- version_number : ENV [ 'NEW_VERSION' ] ,
438- xcodeproj : "MirrorSmokerStopper.xcodeproj"
439- )
439+ new_version = ENV [ 'NEW_VERSION' ]
440440 else
441- # Legge marketing version attuale; se manca, setta 1.0.0
442- current_v = '1.0.0'
443441 bump = ( ENV [ 'BUMP_TYPE' ] || 'patch' ) . downcase
444- segments = current_v . split ( '.' )
445- segments << '0' while segments . length < 3
442+ parts = current_v . split ( '.' )
443+ parts << '0' while parts . length < 3
446444 case bump
447445 when 'patch'
448- segments [ 2 ] = ( segments [ 2 ] . to_i + 1 ) . to_s
446+ parts [ 2 ] = ( parts [ 2 ] . to_i + 1 ) . to_s
449447 when 'minor'
450- segments [ 1 ] = ( segments [ 1 ] . to_i + 1 ) . to_s
451- segments [ 2 ] = '0'
448+ parts [ 1 ] = ( parts [ 1 ] . to_i + 1 ) . to_s
449+ parts [ 2 ] = '0'
452450 when 'major'
453- segments [ 0 ] = ( segments [ 0 ] . to_i + 1 ) . to_s
454- segments [ 1 ] = '0'
455- segments [ 2 ] = '0'
451+ parts [ 0 ] = ( parts [ 0 ] . to_i + 1 ) . to_s
452+ parts [ 1 ] = '0'
453+ parts [ 2 ] = '0'
456454 else
457455 UI . user_error! ( "BUMP_TYPE deve essere patch|minor|major" )
458456 end
459- new_marketing = segments . join ( '.' )
460- increment_version_number ( version_number : new_marketing , xcodeproj : "MirrorSmokerStopper.xcodeproj" )
457+ new_version = parts . join ( '.' )
458+ end
459+ UI . message ( "[release] Marketing version: #{ current_v } -> #{ new_version } " )
460+
461+ # Scrivi nuova marketing version nel plist (add se non esiste)
462+ sh ( %Q{/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString #{ new_version } " "#{ plist_path } " 2>/dev/null || /usr/libexec/PlistBuddy -c "Add :CFBundleShortVersionString string #{ new_version } " "#{ plist_path } "} )
463+
464+ # Aggiorna anche project.pbxproj (MARKETING_VERSION) per coerenza con Xcode build settings
465+ pbxproj = "MirrorSmokerStopper.xcodeproj/project.pbxproj"
466+ if File . exist? ( pbxproj )
467+ # Usa Ruby inline edit evitando duplicare se già uguale
468+ ruby_cmd = <<~RUBY
469+ path = '#{ pbxproj } '
470+ txt = File.read(path)
471+ new_txt = txt.gsub(/MARKETING_VERSION = [0-9.]+;/, "MARKETING_VERSION = #{ new_version } ;")
472+ if txt != new_txt
473+ File.open(path, 'w'){|f| f.write(new_txt)}
474+ end
475+ RUBY
476+ sh ( "ruby -e \" #{ ruby_cmd . gsub ( "\n " , ';' ) } \" " )
461477 end
462478
463- # 3. Increment build number sempre (per evitare duplicati su App Store Connect)
479+ # 3. Build number manuale
480+ current_build = ` /usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "#{ plist_path } " 2>/dev/null` . strip
464481 if ENV [ 'USE_TIMESTAMP_BUILD' ] == '1'
465- ts = Time . now . strftime ( '%Y%m%d%H%M' )
466- increment_build_number (
467- build_number : ts ,
468- xcodeproj : "MirrorSmokerStopper.xcodeproj"
469- )
482+ new_build = Time . now . strftime ( '%Y%m%d%H%M' )
470483 else
471- increment_build_number (
472- xcodeproj : "MirrorSmokerStopper.xcodeproj"
473- )
484+ numeric = current_build . to_i . to_s == current_build
485+ new_build = numeric ? ( current_build . to_i + 1 ) . to_s : '1'
486+ end
487+ UI . message ( "[release] Build number: #{ current_build . empty? ? '(nil)' : current_build } -> #{ new_build } " )
488+ sh ( %Q{/usr/libexec/PlistBuddy -c "Set :CFBundleVersion #{ new_build } " "#{ plist_path } " 2>/dev/null || /usr/libexec/PlistBuddy -c "Add :CFBundleVersion string #{ new_build } " "#{ plist_path } "} )
489+
490+ # Aggiorna CURRENT_PROJECT_VERSION nel project.pbxproj
491+ if File . exist? ( pbxproj )
492+ ruby_cmd2 = <<~RUBY
493+ path = '#{ pbxproj } '
494+ txt = File.read(path)
495+ new_txt = txt.gsub(/CURRENT_PROJECT_VERSION = [0-9A-Za-z_.-]+;/, "CURRENT_PROJECT_VERSION = #{ new_build } ;")
496+ if txt != new_txt
497+ File.open(path, 'w'){|f| f.write(new_txt)}
498+ end
499+ RUBY
500+ sh ( "ruby -e \" #{ ruby_cmd2 . gsub ( "\n " , ';' ) } \" " )
474501 end
475502
503+ # Esponi variabili in ambiente lane
504+ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] = new_version
505+ ENV [ 'EFFECTIVE_BUILD_NUMBER' ] = new_build
506+
476507
477508 # 4. Test rapidi (opzionale: si può abilitare var FASTLANE_SKIP_TESTS)
478509 unless ENV [ 'FASTLANE_SKIP_TESTS' ] == '1'
@@ -505,7 +536,7 @@ platform :ios do
505536 clean : true ,
506537 export_method : "app-store" ,
507538 output_directory : "build" ,
508- output_name : "MirrorSmokerStopper_#{ new_version } .ipa" ,
539+ output_name : "MirrorSmokerStopper_#{ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] } .ipa" ,
509540 skip_codesigning : false
510541 )
511542
@@ -528,7 +559,7 @@ platform :ios do
528559 unless ENV [ 'DRY_RUN' ] == '1'
529560 deliver (
530561 force : true ,
531- ipa : "build/MirrorSmokerStopper_#{ new_version } .ipa" ,
562+ ipa : "build/MirrorSmokerStopper_#{ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] } .ipa" ,
532563 screenshots_path : "./fastlane/screenshots" ,
533564 submit_for_review : true ,
534565 automatic_release : false ,
@@ -541,13 +572,13 @@ platform :ios do
541572 end
542573
543574 # 10. Commit version + build bump + release info json
544- sh ( "git add -A && git commit -m 'release: #{ new_version } ' || true" )
575+ sh ( "git add -A && git commit -m 'release: #{ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] } ' || true" )
545576
546577 # 11. Tag + push
547- add_git_tag ( tag : "v#{ new_version } " ) unless ENV [ 'DRY_RUN' ] == '1'
578+ add_git_tag ( tag : "v#{ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] } " ) unless ENV [ 'DRY_RUN' ] == '1'
548579 push_to_git_remote unless ENV [ 'DRY_RUN' ] == '1'
549580
550- UI . success ( "Release #{ new_version } inviata per review su App Store Connect." )
581+ UI . success ( "Release #{ ENV [ 'EFFECTIVE_MARKETING_VERSION' ] } ( #{ ENV [ 'EFFECTIVE_BUILD_NUMBER' ] } ) inviata per review su App Store Connect." )
551582 end
552583
553584 # Clean up old screenshots and builds
0 commit comments