tuya-ci-core 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc0a9c16de4cfe342233ac87bd4c7c959c44b65c
4
+ data.tar.gz: 0cf27767a625642a740b9159d2e0092e15e1098e
5
+ SHA512:
6
+ metadata.gz: 9172a9c72fbf310f329580e55bc5786bc90bcee27c06a63263e2997dc36300491719441bb0ea0b8adac07b593fc1b99f128cae5582d814af492c38a015559838
7
+ data.tar.gz: 8e063a90ebd6876355e37c3f50811efd474fd0108966c15745e4301cac4286db1501173687c8e2a80dfaaf27d3d227738e20b45fb976508bc2400e6e220a87dc
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 fangdong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Tuya::Ci::Core
2
+
3
+ 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/tuya/ci/core`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tuya-ci-core'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tuya-ci-core
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tuya-ci-core. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Tuya::Ci::Core project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tuya-ci-core/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,16 @@
1
+ module TYCiCore
2
+ class EXE
3
+ def self.exe(executable, command, raise_if_need = false)
4
+ require 'cocoapods'
5
+ require 'cocoapods/executable'
6
+
7
+ Pod::Executable.execute_command(executable, command, raise_if_need)
8
+ end
9
+
10
+ def self.multi_exe(executable, commands, raise_if_need = false)
11
+ commands.each do |command|
12
+ exe(executable, command, raise_if_need)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,111 @@
1
+ require 'tuya/ci/core'
2
+
3
+ module TYCiCore
4
+ class Git
5
+
6
+ def self.git_tag_add_push(tag)
7
+ git_tag_add tag
8
+ git_tag_push tag
9
+ end
10
+
11
+ def self.git_tag_add(tag)
12
+ command = %W(tag -a #{tag} -m add\ tag:\ #{tag})
13
+ EXE.exe('git', command, true )
14
+ end
15
+
16
+ def self.git_tag_push(tag)
17
+ command = %W(push origin #{tag})
18
+ EXE.exe('git', command, true )
19
+ end
20
+
21
+ def self.git_tag_push_all
22
+ command = %W(push origin --tags)
23
+ EXE.exe('git', command, true )
24
+ end
25
+
26
+ def self.git_tag_delete!(tag, local=true, remote=true)
27
+
28
+ commands = []
29
+
30
+ commands << %W(tag tag -d #{tag}) if local
31
+ commands << %W(push origin :refs/tags/#{tag}) if remote
32
+
33
+ EXE.multi_exe('git', commands, true ) unless commands.empty?
34
+
35
+ end
36
+
37
+ def self.git_tag_exist?(tag, remote=false )
38
+ if remote
39
+ EXE.exe('git', %W(ls-remote -q --exit-code origin #{tag})).length > 0
40
+ else
41
+ EXE.exe('git', %W(rev-parse -q --verify #{tag})).length > 0
42
+ end
43
+ end
44
+
45
+ def self.git_push
46
+ EXE.exe('git', %W(push), true )
47
+ end
48
+
49
+ def self.git_commit_modify(message)
50
+
51
+ git_status = EXE.exe("git", %W(status), true)
52
+
53
+ if git_has_modify? git_status
54
+ commands = [
55
+ %W(add -u),
56
+ %W(commit -m '#{message}')
57
+ ]
58
+
59
+ EXE.multi_exe("git", commands, true)
60
+ end
61
+ end
62
+
63
+ def self.git_commit_all(message)
64
+
65
+ git_commit_commands = [
66
+ %W(add -A),
67
+ %W(commit -am '#{message}')
68
+ ]
69
+ EXE.multi_exe('git', git_commit_commands, true)
70
+ end
71
+
72
+ def self.git_checkout_branch(branch)
73
+ branch_origin = branch
74
+ unless branch_origin.include?("/")
75
+ branch_origin = "origin/" + branch_origin
76
+ end
77
+
78
+ target_branch = branch_origin.split('/')[-1]
79
+
80
+ EXE.exe('git', %W(fetch), true )
81
+
82
+ commands = [
83
+ %W(checkout #{target_branch})
84
+ ]
85
+
86
+ commands << %W(branch --set-upstream-to=#{branch_origin}) unless git_branch_exist? target_branch
87
+
88
+ commands += [
89
+ %W(checkout .),
90
+ %W(reset --hard),
91
+ %W(fetch),
92
+ %W(rebase)
93
+ ]
94
+
95
+ EXE.multi_exe('git', commands, true)
96
+
97
+ end
98
+
99
+
100
+
101
+
102
+ def self.git_branch_exist?(branch)
103
+ TYCiCore::EXE.exe('git', %W(rev-parse -q --verify refs/heads/#{branch})).length > 0
104
+ end
105
+
106
+ def self.git_has_modify?(str)
107
+ return str.include?("Changes not staged for commit") || str.include?("Changes to be committed")
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,43 @@
1
+ module TYCiCore
2
+
3
+ class Lib
4
+
5
+ attr_accessor :repo
6
+ attr_accessor :branch
7
+ attr_accessor :project
8
+ attr_accessor :version
9
+
10
+ def podspec_project
11
+ "#{@project}.podspec"
12
+ end
13
+
14
+ def source
15
+ puts "Job: #{@project} version: #{@version} on :#{@branch} repo: #{@repo}"
16
+ _source
17
+ end
18
+
19
+
20
+ private
21
+
22
+ def _source
23
+
24
+ Git.git_checkout_branch branch
25
+
26
+ podspec = PodSpec.new(podspec_project)
27
+
28
+ if podspec.update('version', @version)
29
+
30
+ podspec.save
31
+
32
+ Git.git_commit_modify "feat: CI add version to #{@version}"
33
+ Git.git_push
34
+ end
35
+
36
+ Git.git_tag_delete! @version if Git.git_tag_exist?(@version, true )
37
+
38
+ Git.git_tag_add_push @version
39
+
40
+ TYRepo::RepoTuya.new('./*.podspec').push
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,16 @@
1
+ require 'tuya/ci/core/lib/lib'
2
+
3
+ module TYCiCore
4
+ class LibTuya < Lib
5
+ def initialize(branch, project, version)
6
+ @repo = 'TYSpecs'
7
+ @branch = branch
8
+ @project = project
9
+ @version = version
10
+ end
11
+
12
+ def source
13
+ super
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module TYCiCore
2
+ class PodSpec
3
+
4
+ attr_accessor :file
5
+ attr_accessor :content
6
+
7
+ def initialize(podspec)
8
+
9
+ raise 'podspec cannot be nil' unless podspec
10
+
11
+ @file = TYUtil::File.podspec_files(podspec)[0]
12
+ @content = File.read(@file)
13
+
14
+ end
15
+
16
+ def update(key, value)
17
+ res = @content.scan(/.#{key}\s*=\s*'#{value}'/)
18
+ need_update = res.size == 0
19
+ if need_update
20
+ @content.gsub!(/s.#{key}\s*=(.*?)'$/, "s.#{key} = '#{value}'")
21
+ end
22
+ need_update
23
+ end
24
+
25
+ def save
26
+ fh = File.new(@file, "w")
27
+ fh.puts @content
28
+ fh.close
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ module TYRepo
2
+
3
+ SPECS_ADDRESS_TUYA = 'https://code.registry.wgine.com/tuyaIOS/TYSpecs.git'
4
+ SPECS_ADDRESS_MASTER = 'https://github.com/CocoaPods/Specs.git'
5
+ SPECS_ADDRESS_TYUA_PUBLIC = 'https://github.com/TuyaInc/TYPublicSpecs.git'
6
+
7
+ class Repo
8
+ attr_accessor :podspec_path
9
+ attr_accessor :sources
10
+ attr_accessor :repo
11
+
12
+ def initialize(podspec_path)
13
+ raise 'Path cannot be nil' unless podspec_path
14
+ end
15
+
16
+ def command_sources
17
+ result = ' --sources=\''
18
+ @sources.each_with_index do |source, index|
19
+ result << source << ((index != @sources.size - 1) ? ',':'')
20
+ end
21
+ result << '\''
22
+ end
23
+
24
+ def command
25
+ "pod repo push #{@repo} #{@podspec_path}" << command_sources << ' --use-libraries --allow-warnings'
26
+ end
27
+
28
+ def push
29
+ `#{command}`
30
+ end
31
+
32
+ end
33
+
34
+ class RepoTuya < Repo
35
+
36
+ def initialize (podspec_path)
37
+ super podspec_path
38
+ @sources = [TYRepo::SPECS_ADDRESS_TUYA, TYRepo::SPECS_ADDRESS_MASTER]
39
+ @podspec_path = podspec_path
40
+ @repo = 'TYSpecs'
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,20 @@
1
+ module TYUtil
2
+ class File
3
+ def self.read(filepath)
4
+
5
+ end
6
+
7
+ def self.podspec_files(podspec)
8
+ if podspec
9
+ path = Pathname(podspec)
10
+ raise Informative, "Couldn't find #{podspec}" unless path.exist?
11
+ [path]
12
+ else
13
+ files = Pathname.glob('*.podspec{,.json}')
14
+ # raise Informative, "Couldn't find any podspec files in current directory" if files.empty?
15
+ puts "Couldn't find any podspec files in current directory".red if files.empty?
16
+ files
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,7 @@
1
+ module Tuya
2
+ module Ci
3
+ module Core
4
+ VERSION = "0.1.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
2
+
3
+ require "tuya/ci/core/version"
4
+
5
+ module TYCiCore
6
+ require 'tuya/ci/core/spec/ty_repo'
7
+ require 'tuya/ci/core/git'
8
+ require 'tuya/ci/core/executable'
9
+ require 'tuya/ci/core/lib/lib_tuya'
10
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tuya-ci-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - fangdong
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cocoapods
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: colored
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: tuya cli core
98
+ email:
99
+ - fangdong@tuyasmart.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE.txt
105
+ - README.md
106
+ - lib/tuya/ci/core.rb
107
+ - lib/tuya/ci/core/executable.rb
108
+ - lib/tuya/ci/core/git.rb
109
+ - lib/tuya/ci/core/lib/lib.rb
110
+ - lib/tuya/ci/core/lib/lib_tuya.rb
111
+ - lib/tuya/ci/core/podspec.rb
112
+ - lib/tuya/ci/core/spec/ty_repo.rb
113
+ - lib/tuya/ci/core/util/file.rb
114
+ - lib/tuya/ci/core/version.rb
115
+ homepage: https://docs.tuya.com/cn/
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.5.2.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: ci-core for tuya
139
+ test_files: []