potemkin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,41 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in potemkin.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ # An IRB alternative and runtime developer console
8
+ # [pry](http://pry.github.com)
9
+ gem 'pry', '~> 0.9.10'
10
+ # Using guard to run the tests autmoatically on file change.
11
+ # Just run `guard` in the root of the folder
12
+ #
13
+ # [guard](https://github.com/guard/guard)
14
+ gem 'guard', '~> 1.5.0'
15
+
16
+ end
17
+
18
+ group :test do
19
+ # Adding rake for Travis.
20
+ gem 'rake'
21
+
22
+ # minitest provides a complete suite of testing facilities...
23
+ # [minitest](https://github.com/seattlerb/minitest)
24
+ gem 'minitest'
25
+
26
+ # Adds color to your MiniTest output
27
+ gem "minitest-rg", "~> 1.0.0"
28
+
29
+ # [mocha](http://gofreerange.com/mocha/docs)
30
+ gem 'mocha', '~> 0.13.0'
31
+
32
+ gem 'guard-minitest'
33
+ end
34
+
35
+ # Workaround for Heroku:
36
+ # [More info](http://www.johnplummer.com/rails/heroku-error-conditional-rbfsevent-gem.html)
37
+ group :test, :darwin do
38
+ # OS X
39
+ gem 'terminal-notifier-guard'
40
+ gem 'rb-fsevent', :require => false
41
+ end
@@ -0,0 +1,12 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'minitest' do
5
+ # with Minitest::Unit
6
+ watch(%r|^test/(.*)\/?(.*)_test\.rb|)
7
+ watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
8
+ watch(%r|^test/helper\.rb|) { "test" }
9
+ watch(%r|^lib/potemkin\.rb|) { "test" }
10
+
11
+ watch(%r|^lib/potemkin/builder/(.*)\.rb|) { |m| "test/builder_#{m[1]}_test.rb" }
12
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Bob Van Landuyt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Potemkin
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'potemkin'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install potemkin
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,20 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ #!/usr/bin/env rake
4
+ require "bundler/gem_tasks"
5
+ require 'rake/testtask'
6
+
7
+ desc 'Run Devise unit tests.'
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'lib'
10
+ t.libs << 'test'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ task :default => :test
16
+
17
+ desc "Open an pry session with Potemkin loaded"
18
+ task :console do
19
+ sh "pry -I lib -r potemkin.rb"
20
+ end
@@ -0,0 +1,30 @@
1
+ require "potemkin/version"
2
+ require "potemkin/version/ios_version"
3
+ require "potemkin/configuration"
4
+ require "potemkin/builder"
5
+ require "potemkin/builder/ios"
6
+ require "potemkin/builder/android"
7
+ require "potemkin/logger"
8
+
9
+ module Potemkin
10
+ class << self
11
+ def config
12
+ @config ||= Configuration.default
13
+ end
14
+
15
+ def configure
16
+ yield config
17
+ end
18
+
19
+ def run(cmd)
20
+ puts "Executing #{cmd}"
21
+ puts system("#{cmd}")
22
+ end
23
+
24
+ def logger
25
+ @logger ||= Potemkin::Logger.new
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,49 @@
1
+ module Potemkin
2
+ class Builder
3
+
4
+ # No environment variables by default
5
+ def env_vars
6
+ {}
7
+ end
8
+
9
+ # Will build the actual APK
10
+ def build
11
+ logger.describe "creating build"
12
+ with_env_vars(env_vars) { Potemkin.run build_command }
13
+ end
14
+
15
+ def clean
16
+ logger.describe "cleaning build"
17
+ with_env_vars(env_vars) { Potemkin.run clean_command }
18
+ end
19
+
20
+ # Takes a hash and a block, wrapping the block with the env variables
21
+ # found in the hash.
22
+ def with_env_vars(env_vars)
23
+ old_values = {}
24
+ env_vars.each do |key,new_value|
25
+ old_values[key] = ENV[key]
26
+ ENV[key] = new_value
27
+ end
28
+
29
+ return_value = yield
30
+
31
+ env_vars.each_key do |key|
32
+ ENV[key] = old_values[key]
33
+ end
34
+
35
+ return_value
36
+ end
37
+
38
+ # Returns the config, mainly here to mock in tests
39
+ def config
40
+ Potemkin.config
41
+ end
42
+
43
+ # Returns the logger, mainly here to mock in tests
44
+ def logger
45
+ Potemkin.logger
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,28 @@
1
+ module Potemkin
2
+ class AndroidBuilder < Builder
3
+
4
+ # android needs the ANDROID_HOME dir to be set in the environment
5
+ def env_vars
6
+ { "ANDROID_HOME" => config.sdk_root }
7
+ end
8
+
9
+ # Returns the command to be executed to build
10
+ # This command should be run in the root of the project dir
11
+ def build_command
12
+ "ant -f #{android_project_dir}/build.xml #{config.build_type}"
13
+ end
14
+
15
+ # this will clean out the bin directories within a project
16
+ def clean_command
17
+ "ant -f #{android_project_dir}/build.xml clean"
18
+ end
19
+
20
+ # The subfolder where the actual app is located
21
+ def android_project_dir
22
+ raise "Please add project dir" unless config.android_project_dir
23
+ config.android_project_dir
24
+ end
25
+
26
+
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module Potemkin
2
+ class IosBuilder < Builder
3
+
4
+ # Returns the command to be executed to build
5
+ # This command should be run in the root of the project dir
6
+ def build_command
7
+ args = {
8
+ "target" => config.target,
9
+ "configuration" => config.configuration,
10
+ "project" => config.project_path
11
+ }.collect{|k,v| "-#{k} '#{v}'"}.join(" ")
12
+
13
+ "#{xcodebuild_path} #{args}"
14
+ end
15
+
16
+ def clean_command
17
+ "#{build_command} clean"
18
+ end
19
+
20
+ def xcodebuild_path
21
+ "/usr/bin/xcodebuild"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require "ostruct"
2
+ module Potemkin
3
+ class Configuration < OpenStruct
4
+
5
+ def self.default
6
+ new \
7
+ :sdk_root => default_sdk_root,
8
+ :build_type => default_build_type
9
+ end
10
+
11
+
12
+ def self.default_sdk_root
13
+ ENV["ANDROID_SDK_ROOT"] || "/usr/local/Cellar/android-sdk/r21"
14
+ end
15
+
16
+ def self.default_build_type
17
+ "debug"
18
+ end
19
+
20
+ end
21
+
22
+ end
@@ -0,0 +1,22 @@
1
+ module Potemkin
2
+ class Git
3
+
4
+ def repository
5
+ @repository ||= Rugged::Repository.new(".")
6
+ end
7
+
8
+ def self.last_commit_is_a_tag?
9
+
10
+ end
11
+
12
+ def self.current_branch
13
+
14
+ end
15
+
16
+ def self.changelog
17
+ tag = `git describe --abbrev=0 --tags`.strip
18
+ `git cat-file tag #{tag} | sed -e '1,/^$/d'`
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ module Potemkin
2
+ class Logger
3
+
4
+ def describe(header)
5
+ width = 50
6
+ log "#" * width
7
+ log header.center(width)
8
+ log "#" * width
9
+ end
10
+
11
+ def log(str)
12
+ puts str
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,32 @@
1
+ module Potemkin
2
+ VERSION = "0.0.1"
3
+
4
+ class Version
5
+ attr_reader :major, :minor, :patch
6
+ def initialize(string)
7
+ @major, @minor, @patch = string.strip.split(".")
8
+ @major = @major.to_i || 0
9
+ @minor = @minor.to_i || 0
10
+ @patch = @patch.to_i || 1
11
+ end
12
+
13
+ def bump_major
14
+ @major += 1
15
+ @minor = 0
16
+ @patch = 0
17
+ end
18
+
19
+ def bump_minor
20
+ @minor += 1
21
+ @patch = 0
22
+ end
23
+
24
+ def bump_patch
25
+ @patch += 1
26
+ end
27
+
28
+ def to_s
29
+ [major, minor, patch].compact.join('.')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Potemkin
2
+ class IosVersion
3
+ extend Forwardable
4
+ def_delegators :@version, :bump_major, :bump_minor, :bump_patch
5
+ def initialize(plist_path)
6
+ @plist_path = plist_path
7
+ semver = fetch_version
8
+ @version = Version.new(semver)
9
+ end
10
+
11
+ def fetch_version
12
+ `/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" #{@plist_path}`
13
+ end
14
+
15
+ def version
16
+ @version
17
+ end
18
+
19
+ def git_sha
20
+ `/usr/bin/git log -1 --format="%H"`.strip()[0..10]
21
+ end
22
+
23
+ def write!
24
+ `/usr/libexec/PlistBuddy -c "Set CFBundleShortVersionString #{@version}" #{@plist_path}`
25
+ `/usr/libexec/PlistBuddy -c "Set CFBundleVersion #{git_sha}" #{@plist_path}`
26
+ end
27
+
28
+ def to_s
29
+ "%s at %s" % [@version, @plist_path]
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'potemkin/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "potemkin"
8
+ gem.version = Potemkin::VERSION
9
+ gem.authors = ["Bob Van Landuyt"]
10
+ gem.email = ["bob.vanlanduyt@gmail.com"]
11
+ gem.description = "A gem to automate builds & deploys for Android, iOS and web apps"
12
+ gem.summary = "A gem to automate builds & deploys for Android, iOS and web apps"
13
+ gem.homepage = ""
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_dependency "rugged", "0.17.0.b7"
19
+
20
+ end
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ hostname
4
+ ruby -v
5
+ bundle install --binstubs --path vendor/gems
6
+ bin/rake
@@ -0,0 +1,40 @@
1
+ require "helper"
2
+ describe Potemkin::AndroidBuilder do
3
+
4
+ before do
5
+ @builder = Potemkin::AndroidBuilder.new
6
+ @builder.stubs(:config).returns(Potemkin::Configuration.new(:sdk_root => "/some/path", :android_project_dir => "dir", :build_type => "debug"))
7
+ end
8
+
9
+ # TODO: This test fails every other time
10
+ it "should run the build command with the android home set" do
11
+ proc = Proc.new { ENV["ANDROID_HOME"] }
12
+ Potemkin.expects(:run).returns(proc.call)
13
+ home = @builder.build
14
+ assert_equal "/some/path", home
15
+ end
16
+
17
+ it "should run a build command" do
18
+ command = "ant -f dir/build.xml debug"
19
+ Potemkin.expects(:run).with(command).once
20
+ @builder.build
21
+ end
22
+
23
+ it "should run a clean command" do
24
+ command = "ant -f dir/build.xml clean"
25
+ Potemkin.expects(:run).with(command).once
26
+ @builder.clean
27
+ end
28
+
29
+ it "should fail if the project dir is not set" do
30
+ @builder_without_dir = Potemkin::AndroidBuilder.new
31
+ @builder_without_dir.stubs(:config).returns(Potemkin::Configuration.new(:sdk_root => "/some/path", :build_type => "debug"))
32
+ builder_error = @builder_without_dir.build rescue "RESCUED"
33
+ assert_equal "RESCUED", builder_error
34
+
35
+ end
36
+
37
+
38
+
39
+
40
+ end
@@ -0,0 +1,24 @@
1
+ require "helper"
2
+ describe Potemkin::IosBuilder do
3
+
4
+ before do
5
+ @builder = Potemkin::IosBuilder.new
6
+ @builder.stubs(:config).returns(Potemkin::Configuration.new(:target => "Butane", :configuration => "Release", "project_path" => "Butane/Butane.xcodeproj"))
7
+ end
8
+
9
+ it "should run a build command" do
10
+ command = "/usr/bin/xcodebuild -target 'Butane' -configuration 'Release' -project 'Butane/Butane.xcodeproj'"
11
+
12
+ Potemkin.expects(:run).with(command).once
13
+ @builder.build
14
+ end
15
+
16
+ it "should run a clean command" do
17
+ command = "/usr/bin/xcodebuild -target 'Butane' -configuration 'Release' -project 'Butane/Butane.xcodeproj' clean"
18
+
19
+ Potemkin.expects(:run).with(command).once
20
+ @builder.clean
21
+ end
22
+
23
+
24
+ end
@@ -0,0 +1,39 @@
1
+ require "helper"
2
+ describe Potemkin::Builder do
3
+
4
+ before do
5
+ @builder = Potemkin::Builder.new
6
+ @builder.stubs(:clean_command).returns("")
7
+ @builder.stubs(:build_command).returns("")
8
+ @builder.stubs(:config).returns(Potemkin::Configuration.new(:sdk_root => "/some/path", :android_project_dir => "dir", :build_type => "debug"))
9
+ end
10
+
11
+ it "should be able to wrap a block in env vars" do
12
+ android_home = "UNKNOWN"
13
+ @builder.with_env_vars("ANDROID_HOME" => "~/her-o") do
14
+ android_home = ENV["ANDROID_HOME"]
15
+ end
16
+ assert_equal "~/her-o", android_home
17
+ end
18
+
19
+ it "should clean up the env vars after the block was run" do
20
+ ENV["hello"] = "test"
21
+ @builder.with_env_vars("hello" => "world") do
22
+ # nothing really
23
+ end
24
+ assert_equal "test", ENV["hello"]
25
+ end
26
+
27
+ it "should run clean commands with environment variables" do
28
+ @builder.expects(:with_env_vars)
29
+ @builder.clean
30
+ end
31
+
32
+ it "should run clean commands with environment variables" do
33
+ @builder.expects(:with_env_vars)
34
+ @builder.build
35
+ end
36
+
37
+
38
+
39
+ end
@@ -0,0 +1,15 @@
1
+ require "helper"
2
+ describe Potemkin::Configuration do
3
+
4
+ it "a new configuration should have an SDK" do
5
+ refute_nil Potemkin.config.sdk_root
6
+ end
7
+
8
+ it "should respect custom SDK path" do
9
+ Potemkin.configure do |config|
10
+ config.sdk_root = "/some/path"
11
+ end
12
+ assert_equal "/some/path", Potemkin.config.sdk_root
13
+ end
14
+
15
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+
3
+ require "minitest/autorun"
4
+ require 'mocha/setup'
5
+
6
+ begin
7
+ # [turn](http://rubygems.org/gems/turn)
8
+ require 'turn/autorun'
9
+ rescue LoadError
10
+ end
11
+
12
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+
15
+ require 'potemkin'
16
+
17
+ class MiniTest::Spec
18
+ before do
19
+ Potemkin::Logger.any_instance.stubs(:log)
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ require "helper"
2
+ describe Potemkin::IosVersion do
3
+
4
+ it "should expose the version object" do
5
+ Potemkin::IosVersion.any_instance.stubs(:fetch_version).returns("1.2.3")
6
+ v = Potemkin::IosVersion.new("some/path")
7
+ assert_equal "1.2.3", v.version.to_s
8
+ end
9
+ end
@@ -0,0 +1,35 @@
1
+ require "helper"
2
+ describe Potemkin::Version do
3
+
4
+ describe "a version initialized from a string" do
5
+
6
+ it "should load a semver string without a problem" do
7
+ assert_equal "1.0.0", Potemkin::Version.new("1.0.0").to_s
8
+ end
9
+
10
+ it "should set anything it doesn't recognise to 0.0.0" do
11
+ assert_equal "0.0.0", Potemkin::Version.new("epic_version").to_s
12
+ end
13
+ end
14
+
15
+ describe "bumping a version" do
16
+ before do
17
+ @version = Potemkin::Version.new("0.0.1")
18
+ end
19
+
20
+ it "should bump the major" do
21
+ @version.bump_major
22
+ assert_equal "1.0.0", @version.to_s
23
+ end
24
+
25
+ it "should bump the minor" do
26
+ @version.bump_minor
27
+ assert_equal "0.1.0", @version.to_s
28
+ end
29
+
30
+ it "should bump the patch" do
31
+ @version.bump_patch
32
+ assert_equal "0.0.2", @version.to_s
33
+ end
34
+ end
35
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: potemkin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Bob Van Landuyt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rugged
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.17.0.b7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - '='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.17.0.b7
30
+ description: A gem to automate builds & deploys for Android, iOS and web apps
31
+ email:
32
+ - bob.vanlanduyt@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - Guardfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - lib/potemkin.rb
44
+ - lib/potemkin/builder.rb
45
+ - lib/potemkin/builder/android.rb
46
+ - lib/potemkin/builder/ios.rb
47
+ - lib/potemkin/configuration.rb
48
+ - lib/potemkin/git.rb
49
+ - lib/potemkin/logger.rb
50
+ - lib/potemkin/version.rb
51
+ - lib/potemkin/version/ios_version.rb
52
+ - potemkin.gemspec
53
+ - script/cibuild
54
+ - test/builder_android_test.rb
55
+ - test/builder_ios_test.rb
56
+ - test/builder_test.rb
57
+ - test/configuration_test.rb
58
+ - test/helper.rb
59
+ - test/version_ios_test.rb
60
+ - test/version_test.rb
61
+ homepage: ''
62
+ licenses: []
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
74
+ - 0
75
+ hash: 2485377496382467505
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ segments:
83
+ - 0
84
+ hash: 2485377496382467505
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.24
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A gem to automate builds & deploys for Android, iOS and web apps
91
+ test_files:
92
+ - test/builder_android_test.rb
93
+ - test/builder_ios_test.rb
94
+ - test/builder_test.rb
95
+ - test/configuration_test.rb
96
+ - test/helper.rb
97
+ - test/version_ios_test.rb
98
+ - test/version_test.rb