flow-build 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/flow-build.gemspec +25 -0
- data/lib/flow/build.rb +67 -0
- data/lib/flow/build/configuration.rb +32 -0
- data/lib/flow/build/service/env.rb +39 -0
- data/lib/flow/build/service/env/builtin.rb +12 -0
- data/lib/flow/build/service/env/var.rb +12 -0
- data/lib/flow/build/service/git.rb +37 -0
- data/lib/flow/build/service/git/clone.rb +19 -0
- data/lib/flow/build/service/git/ssh_key.rb +21 -0
- data/lib/flow/build/service/parser.rb +87 -0
- data/lib/flow/build/service/parser/android.rb +14 -0
- data/lib/flow/build/service/parser/nodejs.rb +22 -0
- data/lib/flow/build/service/parser/objective_c.rb +14 -0
- data/lib/flow/build/service/parser/ruby.rb +25 -0
- data/lib/flow/build/service/parser/templates/footer.sh +5 -0
- data/lib/flow/build/service/parser/templates/header.sh +133 -0
- data/lib/flow/build/service/shell/builder.rb +0 -0
- data/lib/flow/build/version.rb +7 -0
- data/lib/flow/core_ext/blank.rb +132 -0
- data/lib/flow/core_ext/hash.rb +85 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 881660392dc1597f0714478ce1ffd3b13d1fc6dd
|
4
|
+
data.tar.gz: d060cfda9f1cdbe28a4f6ee68954181dc38fbc16
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 085c9a4dc8cc268ad346a31bf1852965fbea18d351cf7c098da78ee7e999b6fdb7f40ba9a0fc9f1b0a70ab7e1088892cc58d51a27655d75dd81dd24c8667e247
|
7
|
+
data.tar.gz: f4f3d3e7ebecc37429bf3f2f63220538044a940e695ac341d097b34e35a72941a74eea2ad7f52bd6f64183b1f7a9475bd2928609b7ec4986a4607ad4271effa0
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
if ENV['USE_OFFICIAL_GEM_SOURCE']
|
4
|
+
source 'https://rubygems.org'
|
5
|
+
else
|
6
|
+
source 'https://ruby.taobao.org'
|
7
|
+
end
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in flow-build.gemspec
|
10
|
+
gemspec
|
11
|
+
|
12
|
+
gem 'travis-yaml', github: 'travis-ci/travis-yaml'
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Spirit
|
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,41 @@
|
|
1
|
+
# Flow::Build
|
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/flow/build`. 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 'flow-build'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install flow-build
|
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 test` 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]/flow-build. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "flow/build"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/flow-build.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'flow/build/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "flow-build"
|
8
|
+
spec.version = Flow::Build::VERSION
|
9
|
+
spec.authors = ["Spirit"]
|
10
|
+
spec.email = ["neverlandxy.naix@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{flow build}
|
13
|
+
spec.description = %q{flow build}
|
14
|
+
spec.homepage = "https://github.com/FIRHQ/flow-build"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
data/lib/flow/build.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'logger'
|
5
|
+
require 'tempfile'
|
6
|
+
require 'shellwords'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
unless Object.const_defined?(:ActiveSupport)
|
10
|
+
require 'flow/core_ext/hash'
|
11
|
+
require 'flow/core_ext/blank'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'flow/build/configuration'
|
15
|
+
require 'flow/build/Service/git'
|
16
|
+
require 'flow/build/service/parser'
|
17
|
+
require 'flow/build/version'
|
18
|
+
|
19
|
+
module Flow
|
20
|
+
module Build
|
21
|
+
class << self
|
22
|
+
|
23
|
+
CONFIG = Configuration.new
|
24
|
+
|
25
|
+
def configure(opts={})
|
26
|
+
CONFIG.merge(opts)
|
27
|
+
|
28
|
+
setup_general_logger!
|
29
|
+
@configured = true
|
30
|
+
end
|
31
|
+
|
32
|
+
def configured?
|
33
|
+
!!@configured
|
34
|
+
end
|
35
|
+
|
36
|
+
def clear!
|
37
|
+
CONFIG.clear
|
38
|
+
|
39
|
+
@logger = nil
|
40
|
+
@configured = false
|
41
|
+
end
|
42
|
+
|
43
|
+
def logger=(logger)
|
44
|
+
@logger = logger
|
45
|
+
end
|
46
|
+
|
47
|
+
def logger
|
48
|
+
@logger
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_script(data)
|
52
|
+
Flow::Build::Service::Parser.new(data).script
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def setup_general_logger!
|
58
|
+
if [:info, :debug, :error, :warn].all?{ |meth| CONFIG[:log].respond_to?(meth) }
|
59
|
+
@logger = CONFIG[:log]
|
60
|
+
else
|
61
|
+
@logger = Logger.new(CONFIG[:log])
|
62
|
+
@logger.level = CONFIG[:log_level]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Flow
|
6
|
+
module Build
|
7
|
+
class Configuration
|
8
|
+
extend Forwardable
|
9
|
+
def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete, :has_key?
|
10
|
+
|
11
|
+
DEFAULTS = {
|
12
|
+
env: 'production',
|
13
|
+
log: STDOUT,
|
14
|
+
log_level: Logger::INFO
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
clear
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear
|
22
|
+
@hash = DEFAULTS.dup
|
23
|
+
end
|
24
|
+
|
25
|
+
def merge(hash)
|
26
|
+
instance = self.class.new
|
27
|
+
@hash.merge!(hash.dup)
|
28
|
+
instance
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative './env/builtin'
|
4
|
+
require_relative './env/var'
|
5
|
+
|
6
|
+
module Flow
|
7
|
+
module Build
|
8
|
+
module Service
|
9
|
+
class Env
|
10
|
+
include Builtin
|
11
|
+
include Var
|
12
|
+
|
13
|
+
attr_reader :custom_envs
|
14
|
+
attr_accessor :script
|
15
|
+
|
16
|
+
def initialize(custom_envs = {})
|
17
|
+
@custom_envs = custom_envs
|
18
|
+
@script = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply
|
22
|
+
add_builtin_envs
|
23
|
+
add_custom_envs
|
24
|
+
script.join("\n")
|
25
|
+
end
|
26
|
+
|
27
|
+
def add_builtin_envs
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_custom_envs
|
31
|
+
custom_envs.each do |key, value|
|
32
|
+
script << "export #{key.upcase}=#{value}"
|
33
|
+
end
|
34
|
+
script << "\n"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative './git/clone'
|
4
|
+
require_relative './git/ssh_key'
|
5
|
+
|
6
|
+
module Flow
|
7
|
+
module Build
|
8
|
+
module Service
|
9
|
+
class Git
|
10
|
+
include Clone
|
11
|
+
include SshKey
|
12
|
+
|
13
|
+
attr_reader :git_url, :ssh_key, :branch, :repo_dir, :repo_name
|
14
|
+
attr_accessor :script
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
@git_url = options.fetch(:git_url, '')
|
18
|
+
@ssh_key = options.fetch(:ssh_key, '')
|
19
|
+
@repo_dir = options.fetch(:repo_dir, '')
|
20
|
+
@repo_name = options.fetch(:repo_name, '')
|
21
|
+
@branch = options.fetch(:branch, 'master')
|
22
|
+
@script = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def git_host
|
26
|
+
git_url =~ %r(^(?:https?|git)(?:://|@)([^/]*?)(?:/|:)) && $1.split('@').last
|
27
|
+
end
|
28
|
+
|
29
|
+
def apply
|
30
|
+
install_ssh_key
|
31
|
+
git_clone
|
32
|
+
script.join("\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Flow
|
4
|
+
module Build
|
5
|
+
module Service
|
6
|
+
class Git
|
7
|
+
module Clone
|
8
|
+
def git_clone
|
9
|
+
cmd = "git clone --depth=50 --branch=#{branch} #{git_url} #{repo_dir}/#{repo_name}".shellescape
|
10
|
+
script << "cd $HOME/build"
|
11
|
+
script << "flow_cmd #{cmd} --echo --timing"
|
12
|
+
script << "cd #{repo_dir}/#{repo_name}"
|
13
|
+
script << "\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Flow
|
4
|
+
module Build
|
5
|
+
module Service
|
6
|
+
class Git
|
7
|
+
module SshKey
|
8
|
+
def install_ssh_key
|
9
|
+
script << "mkdir -p $HOME/.ssh"
|
10
|
+
script << "echo \"#{ssh_key}\" >> $HOME/.ssh/id_rsa"
|
11
|
+
script << "chmod 600 $HOME/.ssh/id_rsa"
|
12
|
+
script << "eval `ssh-agent` &> /dev/null"
|
13
|
+
script << "ssh-add $HOME/.ssh/id_rsa &> /dev/null"
|
14
|
+
script << "echo \"Host #{git_host}\n\tBatchMode yes\n\tStrictHostKeyChecking no\n\" >> $HOME/.ssh/config"
|
15
|
+
script << "\n"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative './env'
|
4
|
+
require_relative './git'
|
5
|
+
require_relative './parser/ruby'
|
6
|
+
require_relative './parser/nodejs'
|
7
|
+
require_relative './parser/android'
|
8
|
+
require_relative './parser/objective_c'
|
9
|
+
|
10
|
+
module Flow
|
11
|
+
module Build
|
12
|
+
module Service
|
13
|
+
class Parser
|
14
|
+
include Ruby
|
15
|
+
include Nodejs
|
16
|
+
include Android
|
17
|
+
include ObjectiveC
|
18
|
+
|
19
|
+
attr_reader :object
|
20
|
+
attr_accessor :scripts
|
21
|
+
|
22
|
+
# flow-api Project object
|
23
|
+
def initialize(object)
|
24
|
+
@object = object
|
25
|
+
@scripts = {}
|
26
|
+
|
27
|
+
apply
|
28
|
+
end
|
29
|
+
|
30
|
+
# options = { echo: false, time: false, retry: false, time: false }
|
31
|
+
def flow_cmd(sh, options)
|
32
|
+
sh = "flow_cmd " + sh.shellescape
|
33
|
+
options.each { |k, v| sh += " --#{k}" if v }
|
34
|
+
sh
|
35
|
+
end
|
36
|
+
|
37
|
+
def apply
|
38
|
+
object.versions.each_with_index do |version, index|
|
39
|
+
scripts[index] = [
|
40
|
+
header,
|
41
|
+
set_env,
|
42
|
+
generate_git_script,
|
43
|
+
generate_language_script(version),
|
44
|
+
footer
|
45
|
+
].join("\n")
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def header
|
50
|
+
File.read(File.expand_path('../parser/templates/header.sh', __FILE__))
|
51
|
+
end
|
52
|
+
|
53
|
+
def footer
|
54
|
+
File.read(File.expand_path('../parser/templates/footer.sh', __FILE__))
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_env
|
58
|
+
Env.new(object.envs).apply
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_git_script
|
62
|
+
Git.new(
|
63
|
+
git_url: object.git_url,
|
64
|
+
ssh_key: object.private_key,
|
65
|
+
repo_dir: object.repo_dir,
|
66
|
+
repo_name: object.repo_name,
|
67
|
+
branch: object.branch
|
68
|
+
).apply
|
69
|
+
end
|
70
|
+
|
71
|
+
def generate_language_script(version)
|
72
|
+
case object.language
|
73
|
+
when 'ruby'
|
74
|
+
ruby_apply(version)
|
75
|
+
when 'android'
|
76
|
+
# Android
|
77
|
+
when 'objective_c'
|
78
|
+
# Ios
|
79
|
+
when 'nodejs'
|
80
|
+
nodejs_apply(version)
|
81
|
+
# Nodejs
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Flow
|
4
|
+
module Build
|
5
|
+
module Service
|
6
|
+
class Parser
|
7
|
+
module Nodejs
|
8
|
+
def nodejs_apply(version)
|
9
|
+
script = ['source $HOME/.nvm/nvm.sh']
|
10
|
+
script << flow_cmd('nvm --version', echo: true)
|
11
|
+
script << flow_cmd("nvm use #{version}", echo: true, assert: true, timing: true)
|
12
|
+
script << flow_cmd('node --version', echo: true)
|
13
|
+
script << flow_cmd('npm --version', echo: true)
|
14
|
+
script << flow_cmd('npm install ', echo: true, retry: true, timing: true)
|
15
|
+
script << flow_cmd('npm test', echo: true, timing: true)
|
16
|
+
script.join("\n")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Flow
|
4
|
+
module Build
|
5
|
+
module Service
|
6
|
+
class Parser
|
7
|
+
module Ruby
|
8
|
+
def ruby_apply(version)
|
9
|
+
script = ['source $HOME/.rvm/scripts/rvm']
|
10
|
+
script << flow_cmd('rvm -v', echo: true)
|
11
|
+
script << flow_cmd('ruby -v', echo: true)
|
12
|
+
script << flow_cmd("rvm use #{version} --install --binary --fuzzy", echo: true, assert: true, timing: true)
|
13
|
+
script << flow_cmd('gem -v', echo: true)
|
14
|
+
script << flow_cmd('gem install bundler rake', echo: true)
|
15
|
+
script << flow_cmd('bundle -v', echo: true)
|
16
|
+
script << flow_cmd('bundle install --jobs=3 --retry=3', echo: true, retry: true, timing: true)
|
17
|
+
script << flow_cmd('bundle exec rake', echo: true, timing: true)
|
18
|
+
script.join("\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
source /etc/profile
|
3
|
+
|
4
|
+
ANSI_RED="\033[31;1m"
|
5
|
+
ANSI_GREEN="\033[32;1m"
|
6
|
+
ANSI_RESET="\033[0m"
|
7
|
+
ANSI_CLEAR="\033[0K"
|
8
|
+
|
9
|
+
FLOW_TEST_RESULT=
|
10
|
+
FLOW_CMD=
|
11
|
+
|
12
|
+
flow_cmd() {
|
13
|
+
local cmd assert output display retry timing result
|
14
|
+
|
15
|
+
cmd=$1
|
16
|
+
FLOW_CMD=$cmd
|
17
|
+
shift
|
18
|
+
|
19
|
+
while true; do
|
20
|
+
case "$1" in
|
21
|
+
--assert) assert=true; shift ;;
|
22
|
+
--echo) output=true; shift ;;
|
23
|
+
--display) display=$2; shift 2;;
|
24
|
+
--retry) retry=true; shift ;;
|
25
|
+
--timing) timing=true; shift ;;
|
26
|
+
*) break ;;
|
27
|
+
esac
|
28
|
+
done
|
29
|
+
|
30
|
+
if [[ -n "$timing" ]]; then
|
31
|
+
flow_time_start
|
32
|
+
fi
|
33
|
+
|
34
|
+
if [[ -n "$output" ]]; then
|
35
|
+
echo "\$ ${display:-$cmd}"
|
36
|
+
fi
|
37
|
+
|
38
|
+
if [[ -n "$retry" ]]; then
|
39
|
+
flow_retry eval "$cmd"
|
40
|
+
else
|
41
|
+
eval "$cmd"
|
42
|
+
fi
|
43
|
+
result=$?
|
44
|
+
|
45
|
+
if [[ -n "$timing" ]]; then
|
46
|
+
flow_time_finish
|
47
|
+
fi
|
48
|
+
|
49
|
+
if [[ -n "$assert" ]]; then
|
50
|
+
flow_assert $result
|
51
|
+
fi
|
52
|
+
|
53
|
+
return $result
|
54
|
+
}
|
55
|
+
|
56
|
+
flow_time_start() {
|
57
|
+
flow_timer_id=$(printf %08x $(( RANDOM * RANDOM * RANDOM )))
|
58
|
+
flow_start_time=$(flow_seconds)
|
59
|
+
echo -en "flow_time:start:$flow_timer_id\r${ANSI_CLEAR}"
|
60
|
+
}
|
61
|
+
|
62
|
+
flow_time_finish() {
|
63
|
+
local result=$?
|
64
|
+
flow_end_time=$(flow_seconds)
|
65
|
+
local duration=$(($flow_end_time-$flow_start_time))
|
66
|
+
echo -en "flow_time:end:$flow_timer_id:start=$flow_start_time,finish=$flow_end_time,duration=$duration\r${ANSI_CLEAR}"
|
67
|
+
return $result
|
68
|
+
}
|
69
|
+
|
70
|
+
function flow_seconds() {
|
71
|
+
local cmd="date"
|
72
|
+
local format="+%s"
|
73
|
+
local os=$(uname)
|
74
|
+
|
75
|
+
$cmd -u $format
|
76
|
+
}
|
77
|
+
|
78
|
+
flow_retry() {
|
79
|
+
local result=0
|
80
|
+
local count=1
|
81
|
+
while [ $count -le 3 ]; do
|
82
|
+
[ $result -ne 0 ] && {
|
83
|
+
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
|
84
|
+
}
|
85
|
+
"$@"
|
86
|
+
result=$?
|
87
|
+
[ $result -eq 0 ] && break
|
88
|
+
count=$(($count + 1))
|
89
|
+
sleep 1
|
90
|
+
done
|
91
|
+
|
92
|
+
[ $count -gt 3 ] && {
|
93
|
+
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
|
94
|
+
}
|
95
|
+
|
96
|
+
return $result
|
97
|
+
}
|
98
|
+
|
99
|
+
flow_assert() {
|
100
|
+
local result=${1:-$?}
|
101
|
+
if [ $result -ne 0 ]; then
|
102
|
+
echo -e "\n${ANSI_RED}The command \"$FLOW_CMD\" failed and exited with $result.${ANSI_RESET}\n\nYour build has been stopped."
|
103
|
+
flow_terminate 2
|
104
|
+
fi
|
105
|
+
}
|
106
|
+
|
107
|
+
flow_terminate() {
|
108
|
+
pkill -9 -P $$ &> /dev/null || true
|
109
|
+
exit $1
|
110
|
+
}
|
111
|
+
|
112
|
+
flow_fold() {
|
113
|
+
local action=$1
|
114
|
+
local name=$2
|
115
|
+
echo -en "flow_fold:${action}:${name}\r${ANSI_CLEAR}"
|
116
|
+
}
|
117
|
+
|
118
|
+
flow_result() {
|
119
|
+
local result=$1
|
120
|
+
export FLOW_TEST_RESULT=$(( ${FLOW_TEST_RESULT:-0} | $(($result != 0)) ))
|
121
|
+
|
122
|
+
if [ $result -eq 0 ]; then
|
123
|
+
echo -e "\n${ANSI_GREEN}The command \"$FLOW_CMD\" exited with $result.${ANSI_RESET}"
|
124
|
+
else
|
125
|
+
echo -e "\n${ANSI_RED}The command \"$FLOW_CMD\" exited with $result.${ANSI_RESET}"
|
126
|
+
fi
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
mkdir -p $HOME/build
|
131
|
+
cd $HOME/build
|
132
|
+
|
133
|
+
export GIT_ASKPASS=echo
|
File without changes
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Object
|
4
|
+
# activesupport/lib/active_support/core_ext/object/blank.rb
|
5
|
+
# An object is blank if it's false, empty, or a whitespace string.
|
6
|
+
# For example, '', ' ', +nil+, [], and {} are all blank.
|
7
|
+
#
|
8
|
+
# This simplifies
|
9
|
+
#
|
10
|
+
# address.nil? || address.empty?
|
11
|
+
#
|
12
|
+
# to
|
13
|
+
#
|
14
|
+
# address.blank?
|
15
|
+
#
|
16
|
+
# @return [true, false]
|
17
|
+
def blank?
|
18
|
+
respond_to?(:empty?) ? !!empty? : !self
|
19
|
+
end
|
20
|
+
|
21
|
+
# An object is present if it's not blank.
|
22
|
+
#
|
23
|
+
# @return [true, false]
|
24
|
+
def present?
|
25
|
+
!blank?
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the receiver if it's present otherwise returns +nil+.
|
29
|
+
# <tt>object.presence</tt> is equivalent to
|
30
|
+
#
|
31
|
+
# object.present? ? object : nil
|
32
|
+
#
|
33
|
+
# For example, something like
|
34
|
+
#
|
35
|
+
# state = params[:state] if params[:state].present?
|
36
|
+
# country = params[:country] if params[:country].present?
|
37
|
+
# region = state || country || 'US'
|
38
|
+
#
|
39
|
+
# becomes
|
40
|
+
#
|
41
|
+
# region = params[:state].presence || params[:country].presence || 'US'
|
42
|
+
#
|
43
|
+
# @return [Object]
|
44
|
+
def presence
|
45
|
+
self if present?
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class NilClass
|
50
|
+
# +nil+ is blank:
|
51
|
+
#
|
52
|
+
# nil.blank? # => true
|
53
|
+
#
|
54
|
+
# @return [true]
|
55
|
+
def blank?
|
56
|
+
true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class FalseClass
|
61
|
+
# +false+ is blank:
|
62
|
+
#
|
63
|
+
# false.blank? # => true
|
64
|
+
#
|
65
|
+
# @return [true]
|
66
|
+
def blank?
|
67
|
+
true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class TrueClass
|
72
|
+
# +true+ is not blank:
|
73
|
+
#
|
74
|
+
# true.blank? # => false
|
75
|
+
#
|
76
|
+
# @return [false]
|
77
|
+
def blank?
|
78
|
+
false
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class Array
|
83
|
+
# An array is blank if it's empty:
|
84
|
+
#
|
85
|
+
# [].blank? # => true
|
86
|
+
# [1,2,3].blank? # => false
|
87
|
+
#
|
88
|
+
# @return [true, false]
|
89
|
+
alias_method :blank?, :empty?
|
90
|
+
end
|
91
|
+
|
92
|
+
class Hash
|
93
|
+
# A hash is blank if it's empty:
|
94
|
+
#
|
95
|
+
# {}.blank? # => true
|
96
|
+
# { key: 'value' }.blank? # => false
|
97
|
+
#
|
98
|
+
# @return [true, false]
|
99
|
+
alias_method :blank?, :empty?
|
100
|
+
end
|
101
|
+
|
102
|
+
class String
|
103
|
+
BLANK_RE = /\A[[:space:]]*\z/
|
104
|
+
|
105
|
+
# A string is blank if it's empty or contains whitespaces only:
|
106
|
+
#
|
107
|
+
# ''.blank? # => true
|
108
|
+
# ' '.blank? # => true
|
109
|
+
# "\t\n\r".blank? # => true
|
110
|
+
# ' blah '.blank? # => false
|
111
|
+
#
|
112
|
+
# Unicode whitespace is supported:
|
113
|
+
#
|
114
|
+
# "\u00a0".blank? # => true
|
115
|
+
#
|
116
|
+
# @return [true, false]
|
117
|
+
def blank?
|
118
|
+
BLANK_RE === self
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
class Numeric #:nodoc:
|
123
|
+
# No number is blank:
|
124
|
+
#
|
125
|
+
# 1.blank? # => false
|
126
|
+
# 0.blank? # => false
|
127
|
+
#
|
128
|
+
# @return [false]
|
129
|
+
def blank?
|
130
|
+
false
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Returns a new hash with all keys converted using the block operation.
|
5
|
+
#
|
6
|
+
# hash = { name: 'Rob', age: '28' }
|
7
|
+
#
|
8
|
+
# hash.transform_keys{ |key| key.to_s.upcase }
|
9
|
+
# # => {"NAME"=>"Rob", "AGE"=>"28"}
|
10
|
+
def transform_keys
|
11
|
+
return enum_for(:transform_keys) unless block_given?
|
12
|
+
result = self.class.new
|
13
|
+
each_key do |key|
|
14
|
+
result[yield(key)] = self[key]
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
# Destructively convert all keys using the block operations.
|
20
|
+
# Same as transform_keys but modifies +self+.
|
21
|
+
def transform_keys!
|
22
|
+
return enum_for(:transform_keys!) unless block_given?
|
23
|
+
keys.each do |key|
|
24
|
+
self[yield(key)] = delete(key)
|
25
|
+
end
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns a new hash with all keys converted to symbols, as long as
|
30
|
+
# they respond to +to_sym+.
|
31
|
+
#
|
32
|
+
# hash = { 'name' => 'Rob', 'age' => '28' }
|
33
|
+
#
|
34
|
+
# hash.symbolize_keys
|
35
|
+
# # => {:name=>"Rob", :age=>"28"}
|
36
|
+
def symbolize_keys
|
37
|
+
transform_keys { |key| key.to_sym rescue key }
|
38
|
+
end
|
39
|
+
|
40
|
+
# Destructively convert all keys to symbols, as long as they respond
|
41
|
+
# to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
|
42
|
+
def symbolize_keys!
|
43
|
+
transform_keys!{ |key| key.to_sym rescue key }
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns a new hash with all keys converted by the block operation.
|
47
|
+
# This includes the keys from the root hash and from all
|
48
|
+
# nested hashes and arrays.
|
49
|
+
#
|
50
|
+
# hash = { person: { name: 'Rob', age: '28' } }
|
51
|
+
#
|
52
|
+
# hash.deep_transform_keys{ |key| key.to_s.upcase }
|
53
|
+
# # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
|
54
|
+
def deep_transform_keys(&block)
|
55
|
+
_deep_transform_keys_in_object(self, &block)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns a new hash with all keys converted to symbols, as long as
|
59
|
+
# they respond to +to_sym+. This includes the keys from the root hash
|
60
|
+
# and from all nested hashes and arrays.
|
61
|
+
#
|
62
|
+
# hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
|
63
|
+
#
|
64
|
+
# hash.deep_symbolize_keys
|
65
|
+
# # => {:person=>{:name=>"Rob", :age=>"28"}}
|
66
|
+
def deep_symbolize_keys
|
67
|
+
deep_transform_keys { |key| key.to_sym rescue key }
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# support methods for deep transforming nested hashes and arrays
|
73
|
+
def _deep_transform_keys_in_object(object, &block)
|
74
|
+
case object
|
75
|
+
when Hash
|
76
|
+
object.each_with_object({}) do |(key, value), result|
|
77
|
+
result[yield(key)] = _deep_transform_keys_in_object(value, &block)
|
78
|
+
end
|
79
|
+
when Array
|
80
|
+
object.map { |e| _deep_transform_keys_in_object(e, &block) }
|
81
|
+
else
|
82
|
+
object
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flow-build
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spirit
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-03 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: flow build
|
56
|
+
email:
|
57
|
+
- neverlandxy.naix@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- bin/console
|
70
|
+
- bin/setup
|
71
|
+
- flow-build.gemspec
|
72
|
+
- lib/flow/build.rb
|
73
|
+
- lib/flow/build/configuration.rb
|
74
|
+
- lib/flow/build/service/env.rb
|
75
|
+
- lib/flow/build/service/env/builtin.rb
|
76
|
+
- lib/flow/build/service/env/var.rb
|
77
|
+
- lib/flow/build/service/git.rb
|
78
|
+
- lib/flow/build/service/git/clone.rb
|
79
|
+
- lib/flow/build/service/git/ssh_key.rb
|
80
|
+
- lib/flow/build/service/parser.rb
|
81
|
+
- lib/flow/build/service/parser/android.rb
|
82
|
+
- lib/flow/build/service/parser/nodejs.rb
|
83
|
+
- lib/flow/build/service/parser/objective_c.rb
|
84
|
+
- lib/flow/build/service/parser/ruby.rb
|
85
|
+
- lib/flow/build/service/parser/templates/footer.sh
|
86
|
+
- lib/flow/build/service/parser/templates/header.sh
|
87
|
+
- lib/flow/build/service/shell/builder.rb
|
88
|
+
- lib/flow/build/version.rb
|
89
|
+
- lib/flow/core_ext/blank.rb
|
90
|
+
- lib/flow/core_ext/hash.rb
|
91
|
+
homepage: https://github.com/FIRHQ/flow-build
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.4.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: flow build
|
115
|
+
test_files: []
|