sync_build_number_to_git.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. module Fastlane
  2. module Actions
  3. module SharedValues
  4. BUILD_NUMBER = :BUILD_NUMBER
  5. end
  6. class SyncBuildNumberToGitAction < Action
  7. def self.is_git?
  8. Actions.sh 'git rev-parse HEAD'
  9. return true
  10. rescue
  11. return false
  12. end
  13. def self.run(params)
  14. if is_git?
  15. command = 'git rev-list HEAD --count'
  16. else
  17. raise "Not in a git repository."
  18. end
  19. build_number = (Actions.sh command).strip
  20. Fastlane::Actions::IncrementBuildNumberAction.run(build_number: build_number)
  21. Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
  22. end
  23. def self.output
  24. [
  25. ['BUILD_NUMBER', 'The new build number']
  26. ]
  27. end
  28. #####################################################
  29. # @!group Documentation
  30. #####################################################
  31. def self.description
  32. "Set the build version of your project to the same number of your total git commit count"
  33. end
  34. def self.authors
  35. ["onevcat"]
  36. end
  37. def self.is_supported?(platform)
  38. [:ios, :mac].include? platform
  39. end
  40. end
  41. end
  42. end