thktool 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f33b93ac9e418bb28ae38a46ad42c688dffbc13e3e275855604958e66324c31
4
+ data.tar.gz: aa4677e762b0fbb02106e3a614f42b5aaf8c1b5f35e0dbc55835c158e0eeac26
5
+ SHA512:
6
+ metadata.gz: 879516bbbaf0229efa7422090c05fb2637fcbbab7e627c1f57e0f458cb5bbe05ed0311d0674209d21ec694c5355cb4e431e3555acd2f8de53b886c931198f719
7
+ data.tar.gz: ca0ed03a3e687140c1144cce9d05028f5103224dac710a8b76a9e00146543a6951b3c2f0ce69aad06f426ac2148f95c63219b201315dd0902877ec4da7133588
@@ -0,0 +1,15 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Debug Local File",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "program": "${workspaceRoot}/lib/thktool.rb",
12
+ "args":["THKMacroKit","TMUICore","Godeye"]
13
+ }
14
+ ]
15
+ }
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in thktool.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem 'ruby-debug-ide'
10
+ gem 'debase'
11
+ gem 'solargraph'
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Thktool
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/thktool`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
+
27
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/thktool.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
data/bin/thktool ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/thktool'
4
+
5
+ Tool.run(ARGV)
data/lib/const.rb ADDED
@@ -0,0 +1,33 @@
1
+ class Const
2
+ def initialize
3
+
4
+ end
5
+
6
+ def self.Home
7
+ ('/Users/'+`whoami`).chomp
8
+ end
9
+
10
+ def self.Source_Repo_Path
11
+ './'
12
+ end
13
+
14
+ def self.Source_Spec_Path
15
+ self.Home + '/thkbusinesskitspecs'
16
+ end
17
+
18
+ def self.Bin_Repo_Path
19
+ self.Home + '/frameworkrepo'
20
+ end
21
+
22
+ def self.Bin_Spec_Path
23
+ self.Home + '/frameworkspec'
24
+ end
25
+
26
+ def self.Source_Repo_Url
27
+ 'http://repo.we.com/iosfeaturelibraries/THKBusinessComponent.git'
28
+ end
29
+
30
+ def self.Bin_Repo_Url
31
+ 'git@repo.we.com:iosfeaturelibraries/frameworkrepo.git'
32
+ end
33
+ end
data/lib/git_until.rb ADDED
@@ -0,0 +1,14 @@
1
+ class GitUntil
2
+ # 推送文件
3
+ def self.git_push(path,commit)
4
+ pn = Pathname.new(path)
5
+ Dir.chdir(pn.to_s)
6
+ `git add . && git commit -m "#{commit}" && git pull && git push`
7
+ end
8
+
9
+ # 获取最后一次提交commit id
10
+ def self.last_commit_id(path)
11
+ Dir.chdir(path)
12
+ `git rev-parse --short HEAD`.chomp
13
+ end
14
+ end
@@ -0,0 +1,87 @@
1
+ require_relative 'const'
2
+ require 'Pathname'
3
+
4
+ class ModifyUntil
5
+ def initialize
6
+
7
+ end
8
+
9
+ # 查找最大版本号
10
+ def self.find_max_ver(path,fwk)
11
+ pn = Pathname.new(path) + fwk
12
+ maxVer = "0.0.0"
13
+ if pn.directory?
14
+ pn.each_entry { |verDir|
15
+ next if verDir.basename.to_s[0] == ?.
16
+ if maxVer.compare_by_fields(verDir.basename.to_s) == -1
17
+ maxVer = verDir.basename.to_s
18
+ end
19
+ }
20
+ end
21
+ if maxVer != "0.0.0"
22
+ return pn + maxVer + "#{fwk}.podspec"
23
+ end
24
+ return nil
25
+ end
26
+
27
+ # 修改文件
28
+ def self.modify_src_file_line(file,commit)
29
+ p 'start modify file ...' + file
30
+
31
+ IO.write(file, File.open(file) do |f|
32
+ f.read.gsub(/:commit => (.*)/, ":commit => \"#{commit}\"")
33
+ end
34
+ )
35
+ end
36
+
37
+
38
+ # 开始修改源码仓库
39
+ def self.modify_src_commit(file,src,commit)
40
+ path = Const.Source_Spec_Path
41
+ pn = find_max_ver(path,src)
42
+ if pn.file?
43
+ modify_src_file_line(pn.to_s,commit)
44
+ return pn.to_s
45
+ else
46
+ return nil
47
+ end
48
+ end
49
+
50
+ # 修改文件
51
+ def self.modify_fwk_file_line(file,src_commit,fwk_commit)
52
+ p 'start modify file ...' + file
53
+
54
+ src_url = Const.Source_Repo_Url
55
+ bin_url = Const.Bin_Repo_Url
56
+
57
+ IO.write(file, File.open(file) do |f|
58
+ f.read.gsub(/.*s.source.*#{src_url}.*/, " s.source = \{ :git => \'#{src_url}\', :commit => \"#{src_commit}\"\}")
59
+ end
60
+ )
61
+
62
+ IO.write(file, File.open(file) do |f|
63
+ f.read.gsub(/.*s.source.*#{bin_url}.*/, " s.source = \{ :git => \'#{bin_url}\', :commit => \"#{fwk_commit}\"\}")
64
+ end
65
+ )
66
+ end
67
+
68
+ def self.modify_fwk_commit(fwk,src_commit,fwk_commit)
69
+ path = Const.Bin_Spec_Path
70
+ pn = find_max_ver(path,fwk)
71
+ if pn.file?
72
+ modify_fwk_file_line(pn.to_s,src_commit,fwk_commit)
73
+ return pn.to_s
74
+ else
75
+ return nil
76
+ end
77
+ end
78
+ end
79
+
80
+
81
+ # >> "1.5.8".compare_by_fields("1.5.8")
82
+ class String
83
+ def compare_by_fields(other, fieldsep = ".")
84
+ cmp = proc { |s| s.split(fieldsep).map(&:to_i) }
85
+ cmp.call(self) <=> cmp.call(other)
86
+ end
87
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'const'
2
+
3
+ class PackageFramework
4
+
5
+ def self.package(podspec)
6
+ Dir.chdir(Const.Bin_Repo_Path)
7
+ spec_source = ['https://github.com/CocoaPods/Specs.git','git@repo.we.com:iosfeaturelibraries/thkbusinesskitspecs.git','git@repo.we.com:ios/tspecsrepo.git']
8
+ command = "pod packagethk #{podspec} --force --exclude-deps --no-mangle --configuration=Debug --spec-sources=#{spec_source.join(',')}"
9
+ puts "start package ..."
10
+ puts command
11
+ output = `#{command}`
12
+ error = nil
13
+ if $?.exitstatus != 0
14
+ error = output
15
+ puts error
16
+ Process.exit
17
+ end
18
+ puts output
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Thktool
4
+ VERSION = "0.1.0"
5
+ end
data/lib/thktool.rb ADDED
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "thktool/version"
4
+ require_relative "trigger_event"
5
+ require_relative "modify_until"
6
+ require_relative "package_framework"
7
+ require_relative "git_until"
8
+
9
+ module Thktool
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+
13
+ # test argv
14
+ # ARGV = ["{\"before\":\"ee7810f9d805d4de60ff16b11fc667a6dc36873f\",\"after\":\"1111222233334444\",\"ref\":\"refs/heads/master\",\"user_id\":1379,\"user_name\":\"joe.cheng\",\"project_id\":8339,\"repository\":{\"name\":\"FrameworkSpec\",\"url\":\"git@repo.we.com:iosfeaturelibraries/frameworkspec.git\",\"description\":\"二进制仓库spec文件\",\"homepage\":\"http://repo.we.com/iosfeaturelibraries/frameworkspec\"},\"commits\":[{\"id\":\"0169573dc981119ae22ea64a850cc252816cb66b\",\"message\":\"【THKMacroKit】\\n\",\"timestamp\":\"2023-03-21T14:51:23+08:00\",\"url\":\"http://repo.we.com/iosfeaturelibraries/frameworkspec/commit/0169573dc981119ae22ea64a850cc252816cb66b\",\"author\":{\"name\":\"Joe.cheng\",\"email\":\"joe.cheng@corp.to8to.com\"}}],\"total_commits_count\":1}"]
15
+
16
+ p "=========THK Tool Event========="
17
+ p "web hook argv : "
18
+ p ARGV
19
+
20
+ # Tool.run(ARGV)
21
+ end
22
+
23
+ class Tool
24
+ def self.run(argv)
25
+ te = TriggerEvent.new(argv)
26
+ if te.validate_object
27
+ # 修改源码仓库对应的spec仓库
28
+ src_podspec = ModifyUntil.modify_src_commit(te.fwk,te.commit)
29
+ # 提交spec仓库代码
30
+ GitUntil.git_push(Const.Source_Spec_Path,"source podspec repo change : #{te.fwk} commit => #{te.commit}")
31
+ # 开始制作二进制包
32
+ PackageFramework.package(src_podspec)
33
+ # 提交二进制包到framwork仓库
34
+ GitUntil.git_push(Const.Bin_Repo_Path,"binary repo change : #{te.fwk}")
35
+ # 获取二进制仓库最后一次提交commit
36
+ last_commit_id = GitUntil.last_commit_id(Const.Bin_Repo_Path)
37
+ # 修改二进制spec仓库
38
+ fwk_podspec = ModifyUntil.modify_fwk_commit(te.fwk,te.commit,last_commit_id)
39
+ # 提交二进制spec仓库
40
+ GitUntil.git_push(Const.Bin_Spec_Path,"binary podspec change : #{te.fwk} src commit => #{te.commit}, bin commit => #{last_commit_id}")
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ require 'json'
2
+
3
+ class TriggerEvent
4
+
5
+ attr_accessor :fwk
6
+ attr_accessor :commit
7
+
8
+ def initialize(argv)
9
+ data = argv.first
10
+ json = JSON.parse(data)
11
+ # p json
12
+ msg = json['commits'].first['message']
13
+ /【([a-zA-Z0-9]*)】/.match(msg)
14
+ @fwk = $1
15
+ @commit = json['after']
16
+ end
17
+
18
+ def validate_object
19
+ p @fwk
20
+ p @commit
21
+ if @fwk.nil? || @commit.nil?
22
+ p "no framework or commit founds"
23
+ return nil
24
+ end
25
+ return @fwk,@commit
26
+ end
27
+ end
data/sig/thktool.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Thktool
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/thktool.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/thktool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "thktool"
7
+ spec.version = Thktool::VERSION
8
+ spec.authors = ["Joe.cheng"]
9
+ spec.email = ["joe.cheng@corp.to8to.com"]
10
+
11
+ spec.summary = "thk tool."
12
+ spec.description = "thk tool."
13
+ spec.homepage = "https://rubygems.org/gems/thktool"
14
+ # spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ # spec.metadata["allowed_push_host"] = "https://github.com/chengzongxin/thktool.git"
17
+
18
+ # spec.metadata["homepage_uri"] = spec.homepage
19
+ # spec.metadata["source_code_uri"] = "https://github.com/chengzongxin/thktool.git"
20
+ # spec.metadata["changelog_uri"] = "https://github.com/chengzongxin/thktool.git"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|circleci)|appveyor)})
27
+ end
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+ spec.executables << "thktool"
33
+ # Uncomment to register a new dependency of your gem
34
+ # spec.add_dependency "example-gem", "~> 1.0"
35
+
36
+ # For more information and examples about making a new gem, check out our
37
+ # guide at: https://bundler.io/guides/creating_gem.html
38
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thktool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Joe.cheng
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-03-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: thk tool.
14
+ email:
15
+ - joe.cheng@corp.to8to.com
16
+ executables:
17
+ - thktool
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".vscode/launch.json"
22
+ - Gemfile
23
+ - README.md
24
+ - Rakefile
25
+ - bin/thktool
26
+ - lib/const.rb
27
+ - lib/git_until.rb
28
+ - lib/modify_until.rb
29
+ - lib/package_framework.rb
30
+ - lib/thktool.rb
31
+ - lib/thktool/version.rb
32
+ - lib/trigger_event.rb
33
+ - sig/thktool.rbs
34
+ - thktool.gemspec
35
+ homepage: https://rubygems.org/gems/thktool
36
+ licenses: []
37
+ metadata: {}
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.4.7
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: thk tool.
57
+ test_files: []