diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 5a4eda7..2dac09f 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -36,7 +36,7 @@ platform :mac do sh "cd .. && github_changelog_generator -t $GITHUB_TOKEN && subl CHANGELOG.md" # assume version from the podspec - version = JSON.parse(sh "cd .. && pod spec cat *.podspec")['source']['tag'] + version = read_cocoapod_spec['source']['tag'] # ask for info title = prompt(text: 'Release Title: ') @@ -74,8 +74,6 @@ platform :mac do end - #TODO: create a lane for releasing a new podspec - after_all do |lane| if lane == :postbuild diff --git a/fastlane/actions/read_cocoapod_spec.rb b/fastlane/actions/read_cocoapod_spec.rb new file mode 100644 index 0000000..cd6b4ad --- /dev/null +++ b/fastlane/actions/read_cocoapod_spec.rb @@ -0,0 +1,64 @@ +module Fastlane + module Actions + module SharedValues + READ_COCOAPOD_SPEC_JSON = :READ_COCOAPOD_SPEC_JSON + end + + class ReadCocoapodSpecAction < Action + def self.run(params) + path = params[:path] || Dir['*.podspec*'].first + + # will fail if cocoapods is not installed + require 'cocoapods-core' + spec = Pod::Spec.from_file(path).to_hash + + Helper.log.info "Reading podspec from file #{path}".green + + Actions.lane_context[SharedValues::READ_COCOAPOD_SPEC_JSON] = spec + return spec + end + + ##################################################### + # @!group Documentation + ##################################################### + + def self.description + "Loads a CocoaPods spec as JSON" + end + + def self.details + [ + "This can be used for only specifying a version string in your podspec", + "- and during your release process you'd read it from the podspec by running", + "`version = read_cocoapod_spec['version']` at the beginning of your lane" + ].join("\n") + end + + def self.available_options + [ + FastlaneCore::ConfigItem.new(key: :path, + env_name: "FL_READ_COCOAPOD_SPEC_PATH", + description: "(Optional) Path to the podspec to be read", + optional: true, + verify_block: proc do |value| + raise "File #{value} not found".red unless File.exists?(spec_path) + end) + ] + end + + def self.output + [ + ['READ_COCOAPOD_SPEC_JSON', 'Podspec JSON payload'] + ] + end + + def self.authors + ["czechboy0"] + end + + def self.is_supported?(platform) + true + end + end + end +end \ No newline at end of file