Browse Source

Add auto release for change log

onevcat 10 years ago
parent
commit
244e85ef14

+ 1 - 0
.gitignore

@@ -76,3 +76,4 @@ fastlane/screenshots/screenshots.html
 # scan temporary files
 fastlane/test_output
 test_output
+fastlane/.env

+ 1 - 4
CHANGELOG.md

@@ -1,11 +1,10 @@
 # Change Log
 
----
+-----
 
 ## [1.9.2 - IOIOIO](https://github.com/onevcat/Kingfisher/releases/tag/1.9.2) (2016-01-14)
 
 #### Fix
-
 * A potential issue causes image cache checking method not working when the image just stored.
 * Better performance and image quality when storing images with original data.
 
@@ -33,7 +32,6 @@
 ## [1.8.5 - Single Dog](https://github.com/onevcat/Kingfisher/releases/tag/1.8.5) (2015-12-16)
 
 #### Fix
-
 * Use single url session to download images.
 * Ignore and return error immediately for empty URL.
 * Internal update for testing stability and code style.
@@ -67,7 +65,6 @@
 ## [1.8.1 - Transition needs rest](https://github.com/onevcat/Kingfisher/releases/tag/1.8.1) (2015-11-13)
 
 #### Fix
-
 * Only apply transition when images are downloaded. It will not show transition animation now if images loaded from either memory or disk cache now.
 * Code style.
 

+ 19 - 7
fastlane/Fastfile

@@ -5,30 +5,42 @@ default_platform :ios
 
 platform :ios do
   before_all do
-    
+
   end
 
   desc "Runs all the tests"
   lane :test do
     scan
   end
-  
+
   desc "Release new version"
   lane :release do |options|
       target_version = options[:version]
       raise "The version is missed. Use `fastlane release version:{version_number}`.`" if target_version.nil?
-      
+
       ensure_git_branch
       ensure_git_status_clean
       scan
       sync_build_number_to_git
       increment_version_number(version_number: target_version)
       version_bump_podspec(path: "Kingfisher.podspec", version_number: target_version)
-      
+
+      log = extract_current_change_log(version: options[:version])
+      release_log = update_change_log(log: log)
+
       git_commit_all(message: "Bump version to #{target_version}")
       add_git_tag tag: target_version
-      
+
       push_to_git_remote
+
+      set_github_release(
+      repository_name: "onevcat/Kingfisher",
+      api_token: ENV['GITHUB_TOKEN'],
+      name: release_log[:title],
+      tag_name: target_version,
+      description: release_log[:text]
+      )
+
       pod_push
   end
 
@@ -37,10 +49,10 @@ platform :ios do
   end
 
   after_all do |lane|
-    
+
   end
 
   error do |lane, exception|
-    
+
   end
 end

+ 57 - 0
fastlane/actions/extract_current_change_log.rb

@@ -0,0 +1,57 @@
+module Fastlane
+  module Actions
+    class ExtractCurrentChangeLogAction < Action
+      require 'yaml'
+      def self.run(params)
+        yaml = File.read(params[:file])
+        data = YAML.load(yaml)
+        version = data["version"]
+        raise "The version should match in the input file".red unless (version and version == params[:version])
+
+        title = "#{version}"
+        title = title + " - #{data["name"]}" if (data["name"] and not data["name"].empty?)
+
+        return {:title => title, :version => version, :add => data["add"], :fix => data["fix"]}
+      end
+
+      #####################################################
+      # @!group Documentation
+      #####################################################
+
+      def self.description
+        "Extract change log information for a specified version."
+      end
+
+      def self.details
+        "This action will check input version and change log. If everything goes well, the change log info will be returned."
+      end
+
+      def self.available_options
+        [
+          FastlaneCore::ConfigItem.new(key: :version,
+                                       env_name: "KF_EXTRACT_CURRENT_CHANGE_LOG_VERSION",
+                                       description: "The target version which is needed to be extract",
+                                       verify_block: proc do |value|
+                                          raise "No version number is given, pass using `version: 'version_number'`".red unless (value and not value.empty?)
+                                       end),
+          FastlaneCore::ConfigItem.new(key: :file,
+                                       env_name: "KF_EXTRACT_CURRENT_CHANGE_LOG_PRECHANGE_FILE",
+                                       description: "Create a development certificate instead of a distribution one",
+                                       default_value: "pre-change.yml")
+        ]
+      end
+
+      def self.return_value
+        "An object contains change log infomation. {version: }"
+      end
+
+      def self.is_supported?(platform)
+        true
+      end
+
+      def self.authors
+        ["onevcat"]
+      end
+    end
+  end
+end

+ 60 - 0
fastlane/actions/update_change_log.rb

@@ -0,0 +1,60 @@
+module Fastlane
+  module Actions
+    class UpdateChangeLogAction < Action
+      def self.run(params)
+          log = params[:log]
+          raise "Invalid log object".red unless !log[:title].empty? and !log[:version].empty?
+
+          readme = File.read(params[:changelogfile])
+          log_text = "## [#{log[:title]}](https://github.com/onevcat/Kingfisher/releases/tag/#{log[:version]}) (#{Time.now.strftime("%Y-%m-%d")})\n\n"
+
+          des = ""
+          add = log[:add].map { |i| "* #{i}" }.join("\n") unless log[:add].nil?
+          des = des + "#### Add\n#{add}\n\n" unless add.nil? or add.empty?
+
+          fix = log[:fix].map { |i| "* #{i}" }.join("\n") unless log[:fix].nil?
+          des = des + "#### Fix\n#{fix}\n\n" unless fix.nil? or fix.empty?
+
+          log_text = log_text + des
+
+          File.open(params[:changelogfile], 'w') { |file| file.write(readme.sub("-----", "-----\n\n#{log_text}---")) }
+
+          return {:title => log[:title], :text => des}
+      end
+
+      #####################################################
+      # @!group Documentation
+      #####################################################
+
+      def self.description
+        "Update the change log file with the content of log"
+      end
+
+      def self.details
+        "Generally speaking, the log is return value of extract_current_change_log action"
+      end
+
+      def self.available_options
+        [
+          FastlaneCore::ConfigItem.new(key: :log,
+                                       env_name: "KF_UPDATE_CHANGE_LOG_LOG",
+                                       description: "Change log extracted by pre change log file",
+                                       is_string: false
+                                       ),
+          FastlaneCore::ConfigItem.new(key: :changelogfile,
+                                       env_name: "KF_UPDATE_CHANGE_LOG_CHANGE_LOG_FILE",
+                                       description: "The change log file, if not set, CHANGELOG.md will be used",
+                                       default_value: "CHANGELOG.md")
+        ]
+      end
+
+      def self.authors
+        ["onevcat"]
+      end
+
+      def self.is_supported?(platform)
+        true
+      end
+    end
+  end
+end

+ 5 - 0
pre-change.yml

@@ -0,0 +1,5 @@
+version: 1.9.3
+name:
+add:
+fix:
+    - Stop indicator animation when loading failed. #215