abtion-scripts 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55e361f8696410094af177be969b938b133cfc23e61422888e9dc82579ddf46d
4
+ data.tar.gz: 62b021ccf44c0a177a8f2c47d37b66687eebfa892c883b79da2dfe44dcd66d87
5
+ SHA512:
6
+ metadata.gz: 801de11d039b4d8799972a7b2d52ef56165e67bee921b39240bb795d1450a1e7dcc73cf0ff4c7ca0dd00726633b1a3fad214839669321cd53cddd8cd1280df8b
7
+ data.tar.gz: e003a9a147fdd1dd7cbfb0196c097477422b6a80094fcbae8ace7b1be9409c603586b57a77da84581c80e86b78a75851b48a5f0a55949ac86b826ad88abf0e38
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.pairs ADDED
@@ -0,0 +1,11 @@
1
+ pairs:
2
+ eh: Erik Hanson; erik
3
+ erik: Erik Hanson
4
+ hm: Heather Moore; heather
5
+ heather: Heather Moore
6
+ db: David Balatero; dbalatero
7
+ david: David Balatero
8
+ bj: Bion Johnson; bion
9
+ bion: Bion Johnson
10
+ email:
11
+ domain: abtion.io
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.6.3
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "jeweler"
5
+ gem 'pry'
6
+ gem 'pry-stack_explorer'
7
+ gem "rdoc"
8
+ gem "rspec"
9
+ gem "shoulda"
10
+ gem "simplecov"
11
+ end
@@ -0,0 +1,116 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activesupport (6.0.0)
5
+ concurrent-ruby (~> 1.0, >= 1.0.2)
6
+ i18n (>= 0.7, < 2)
7
+ minitest (~> 5.1)
8
+ tzinfo (~> 1.1)
9
+ zeitwerk (~> 2.1, >= 2.1.8)
10
+ addressable (2.4.0)
11
+ binding_of_caller (0.8.0)
12
+ debug_inspector (>= 0.0.1)
13
+ builder (3.2.3)
14
+ coderay (1.1.2)
15
+ concurrent-ruby (1.1.5)
16
+ debug_inspector (0.0.3)
17
+ descendants_tracker (0.0.4)
18
+ thread_safe (~> 0.3, >= 0.3.1)
19
+ diff-lcs (1.3)
20
+ docile (1.3.2)
21
+ faraday (0.9.2)
22
+ multipart-post (>= 1.2, < 3)
23
+ git (1.5.0)
24
+ github_api (0.16.0)
25
+ addressable (~> 2.4.0)
26
+ descendants_tracker (~> 0.0.4)
27
+ faraday (~> 0.8, < 0.10)
28
+ hashie (>= 3.4)
29
+ mime-types (>= 1.16, < 3.0)
30
+ oauth2 (~> 1.0)
31
+ hashie (3.6.0)
32
+ highline (2.0.2)
33
+ i18n (1.6.0)
34
+ concurrent-ruby (~> 1.0)
35
+ jeweler (2.3.9)
36
+ builder
37
+ bundler
38
+ git (>= 1.2.5)
39
+ github_api (~> 0.16.0)
40
+ highline (>= 1.6.15)
41
+ nokogiri (>= 1.5.10)
42
+ psych
43
+ rake
44
+ rdoc
45
+ semver2
46
+ json (2.2.0)
47
+ jwt (2.2.1)
48
+ method_source (0.9.2)
49
+ mime-types (2.99.3)
50
+ mini_portile2 (2.4.0)
51
+ minitest (5.12.0)
52
+ multi_json (1.13.1)
53
+ multi_xml (0.6.0)
54
+ multipart-post (2.1.1)
55
+ nokogiri (1.10.4)
56
+ mini_portile2 (~> 2.4.0)
57
+ oauth2 (1.4.1)
58
+ faraday (>= 0.8, < 0.16.0)
59
+ jwt (>= 1.0, < 3.0)
60
+ multi_json (~> 1.3)
61
+ multi_xml (~> 0.5)
62
+ rack (>= 1.2, < 3)
63
+ pry (0.12.2)
64
+ coderay (~> 1.1.0)
65
+ method_source (~> 0.9.0)
66
+ pry-stack_explorer (0.4.9.3)
67
+ binding_of_caller (>= 0.7)
68
+ pry (>= 0.9.11)
69
+ psych (3.1.0)
70
+ rack (2.0.7)
71
+ rake (12.3.3)
72
+ rdoc (6.2.0)
73
+ rspec (3.8.0)
74
+ rspec-core (~> 3.8.0)
75
+ rspec-expectations (~> 3.8.0)
76
+ rspec-mocks (~> 3.8.0)
77
+ rspec-core (3.8.2)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-expectations (3.8.4)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-mocks (3.8.1)
83
+ diff-lcs (>= 1.2.0, < 2.0)
84
+ rspec-support (~> 3.8.0)
85
+ rspec-support (3.8.2)
86
+ semver2 (3.4.2)
87
+ shoulda (3.6.0)
88
+ shoulda-context (~> 1.0, >= 1.0.1)
89
+ shoulda-matchers (~> 3.0)
90
+ shoulda-context (1.2.2)
91
+ shoulda-matchers (3.1.3)
92
+ activesupport (>= 4.0.0)
93
+ simplecov (0.17.1)
94
+ docile (~> 1.1)
95
+ json (>= 1.8, < 3)
96
+ simplecov-html (~> 0.10.0)
97
+ simplecov-html (0.10.2)
98
+ thread_safe (0.3.6)
99
+ tzinfo (1.2.5)
100
+ thread_safe (~> 0.1)
101
+ zeitwerk (2.1.10)
102
+
103
+ PLATFORMS
104
+ ruby
105
+
106
+ DEPENDENCIES
107
+ jeweler
108
+ pry
109
+ pry-stack_explorer
110
+ rdoc
111
+ rspec
112
+ shoulda
113
+ simplecov
114
+
115
+ BUNDLED WITH
116
+ 2.0.2
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2019 Abtion, A/S
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,113 @@
1
+ # abtion-scripts
2
+
3
+ Handy scripts for developing. Initially built for projects based on [Abtion Rails](https://github.com/abtion/abtion-rails),
4
+ but hopefully useful for other projects as well.
5
+
6
+ ## Installation
7
+
8
+ Add to your project's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'abtion-scripts'
12
+ ```
13
+
14
+
15
+ ## Getting help
16
+
17
+ You can run `abtion help` at any time for a list of commands.
18
+
19
+ Running `abtion help [command name]` will print specific help for that
20
+ command.
21
+
22
+ ## Commands
23
+
24
+ `abtion doctor` will run a bunch of checks to make sure all the project dependencies are met
25
+
26
+ `abtion promote` will promote staging to production and run migrations on production
27
+
28
+ `abtion update` will pull from git, bundle if necessary, migrate the DB if necessary, remove old logs, and restart Rails
29
+
30
+
31
+ ## Extending/adding commands to your project
32
+
33
+ Any files in `.abtion/scripts/**/*.rb` will be automatically required
34
+ by the `abtion` command on a per-project basis. Any overrides/extensions
35
+ can be added in that directory.
36
+
37
+ ## Example of adding a project-specific command
38
+
39
+ If you have a custom command you'd like to add, just put it in
40
+ `.abtion/scripts/custom_command.rb`
41
+
42
+ Each command needs to subclass `AbtionScripts::Base` and implement
43
+ a `run` method.
44
+
45
+ As an example, here's how you might override the `abtion test` command to
46
+ add ESLint as a step:
47
+
48
+ ```ruby
49
+ class CustomTest < AbtionScripts::Test
50
+ # override the default 'test' command by naming it
51
+ # the same
52
+ def self.name
53
+ "test"
54
+ end
55
+
56
+ def run
57
+ # Other scripts can be reused by calling .run
58
+ AbtionScripts::Rspec.run
59
+
60
+ # Adding a custom step to run eslint after RSpec runs
61
+ step "Running eslint" do
62
+ system! "bin/eslint"
63
+ end
64
+ end
65
+ end
66
+ ```
67
+
68
+ ## Extending doctor
69
+
70
+ Create a file called `.abtion/scripts/doctor.rb`, and as an example:
71
+
72
+ ```ruby
73
+ class Doctor < AbtionScripts::Doctor
74
+ def run_checks
75
+ # Use built-in default checks, if still desired
76
+ run_default_checks
77
+
78
+ # Add a custom check
79
+ check_aws_configured
80
+ end
81
+
82
+ private
83
+
84
+ def check_aws_configured
85
+ check(
86
+ name: "AWS env configured",
87
+ command: "cat .envrc | grep AWS_ACCESS_KEY_ID",
88
+ remedy: "cp .envrc .env # and edit"
89
+ )
90
+ end
91
+ end
92
+ ```
93
+
94
+ If you want to cherry pick some of the default checks, you'll need
95
+ to call each of their methods manually. For a list of default checks,
96
+ run `abtion doctor list`. Then, create a `.abtion/scripts/doctor.rb`
97
+ file that looks something like this:
98
+
99
+ ```ruby
100
+ class Doctor < AbtionScripts::Doctor
101
+ def run_checks
102
+ # Only run these two defaults
103
+ check_envrc_file_exists
104
+ check_phantomjs_installed
105
+
106
+ # Add any custom checks here...
107
+ end
108
+ end
109
+ ```
110
+
111
+ ## Copyright
112
+
113
+ Copyright (c) 2019 Abtion. See LICENSE.txt for further details.
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
+ gem.name = "abtion-scripts"
18
+ gem.homepage = "http://github.com/abtion/abtion-scripts"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Abtion command-line scripts for easy testing and deployment}
21
+ gem.description = %Q{Abtion tools for easy building, testing, and deploying}
22
+ gem.email = "admin@abtion.com"
23
+ gem.authors = ["Heather Moore"]
24
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
25
+ gem.require_paths = ["lib"]
26
+ # dependencies defined in Gemfile
27
+ end
28
+ Jeweler::RubygemsDotOrgTasks.new
29
+
30
+ require 'rake/testtask'
31
+ Rake::TestTask.new(:test) do |test|
32
+ test.libs << 'lib' << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+
37
+ desc "Code coverage detail"
38
+ task :simplecov do
39
+ ENV['COVERAGE'] = "true"
40
+ Rake::Task['test'].execute
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rdoc/task'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "abtion-scripts #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.1
@@ -0,0 +1,5 @@
1
+ # Sample abtion.yml
2
+
3
+ heroku_app_names:
4
+ production: PROJECT-NAME-production
5
+ staging: PROJECT-NAME-staging
@@ -0,0 +1,26 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require_relative '../lib/abtion_scripts'
4
+
5
+ # Require any overrides or additional hooks for abtion here
6
+ Dir.glob(".abtion/scripts/**/*.rb").each do |file|
7
+ require File.expand_path(file)
8
+ end
9
+
10
+ script = ARGV.first
11
+
12
+ if ARGV.size == 0
13
+ AbtionScripts::Help.run
14
+ elsif AbtionScripts::Base.script_names.include?(script)
15
+ AbtionScripts::Base
16
+ .scripts[script]
17
+ .run(*ARGV[1 .. -1])
18
+ else
19
+ puts "Script '#{script}' not recognized"
20
+ AbtionScripts::Help.run
21
+
22
+ similar_commands = Levenstein.closest_match(script, AbtionScripts::Base.script_names)
23
+ puts
24
+ puts "Did you mean #{similar_commands.map{|c|"`#{c}`"}.join(' or ')} ?"
25
+ puts
26
+ end
@@ -0,0 +1,7 @@
1
+ module AbtionScripts; end
2
+
3
+ require_relative './abtion_scripts/colorize'
4
+ require_relative './abtion_scripts/base'
5
+
6
+ search_path = File.dirname(__FILE__) + '/abtion_scripts/**/*.rb'
7
+ Dir.glob(search_path).each { |path| require path }
@@ -0,0 +1,135 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+
5
+ class AbtionScripts::Base
6
+ include AbtionScripts::Colorize
7
+ include FileUtils
8
+
9
+ attr_reader :argv
10
+
11
+ def initialize(*argv)
12
+ @argv = argv
13
+ end
14
+
15
+ def self.name
16
+ self
17
+ .to_s
18
+ .split('::')
19
+ .last
20
+ .gsub(/[A-Z]/, "-\\0")
21
+ .downcase[1..-1]
22
+ end
23
+
24
+ def self.inherited(klass)
25
+ AbtionScripts::Base.script_classes << klass
26
+ end
27
+
28
+ def self.script_classes
29
+ @script_classes ||= []
30
+ end
31
+
32
+ def self.scripts
33
+ @scripts ||= load_scripts_deferred
34
+ end
35
+
36
+ def self.load_scripts_deferred
37
+ script_classes.reduce(Hash.new) do |result, klass|
38
+ result[klass.name] = klass
39
+ result
40
+ end
41
+ end
42
+
43
+ def self.script_names
44
+ scripts.keys
45
+ end
46
+
47
+ def self.help
48
+ msg = <<-HELP
49
+ Help has not been implemented for "#{name}". Please implement a help method like so:
50
+
51
+ class #{self} < AbtionScripts::Base
52
+ def self.help
53
+ <<-EOF
54
+ My awesome help message here.
55
+
56
+ This will be so useful for people.
57
+ EOF
58
+ end
59
+ end
60
+ HELP
61
+
62
+ puts msg
63
+ end
64
+
65
+ def self.description
66
+ ""
67
+ end
68
+
69
+ def self.run(*args)
70
+ new(*args).run
71
+ end
72
+
73
+ # path to your application root.
74
+ def app_root
75
+ Pathname.new(Dir.pwd)
76
+ end
77
+
78
+ def run_script(name, *args)
79
+ script = AbtionScripts::Base.scripts[name.to_s]
80
+
81
+ if script.nil?
82
+ raise "Could not find script with name #{name.inspect} to run"
83
+ end
84
+
85
+ script.run(*args)
86
+ end
87
+
88
+ def rails?
89
+ File.exist?("config/application.rb")
90
+ end
91
+
92
+ def bundler?
93
+ File.exist?("Gemfile")
94
+ end
95
+
96
+ def yarn?
97
+ File.exist?("yarn.lock")
98
+ end
99
+
100
+ def ci?
101
+ # Set by Circle automatically:
102
+ # https://circleci.com/docs/1.0/environment-variables/#basics
103
+ ENV.has_key?('CI')
104
+ end
105
+
106
+ def system!(*args)
107
+ puts colorize(:command, args.join(" "))
108
+ system(*args) || abort(colorize(:error, "\n== Command #{args} failed =="))
109
+ end
110
+
111
+ def step(name)
112
+ puts colorize(:info, "\n== #{name} ==")
113
+ yield
114
+ end
115
+
116
+ def app_names
117
+ YAML.load_file('abtion.yml')['heroku_app_names']
118
+ end
119
+
120
+ def heroku_app_name(remote)
121
+ app_names[remote.to_s]
122
+ end
123
+
124
+ def heroku(command, remote:)
125
+ validate_heroku_remote(remote)
126
+ system! "heroku #{command} -r #{remote}"
127
+ end
128
+
129
+ private
130
+
131
+ def validate_heroku_remote(remote)
132
+ raise "Missing remote" if remote.nil?
133
+ raise "Unknown remote" unless %w[staging production].include?(remote.to_s)
134
+ end
135
+ end