capistrano-dotenv-tasks 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/capistrano-dotenv-tasks.gemspec +3 -2
- data/lib/capistrano/dotenv/config.rb +14 -9
- data/lib/capistrano/dotenv/tasks.rb +35 -8
- data/lib/capistrano/dotenv/version.rb +1 -1
- data/spec/config_spec.rb +32 -0
- data/spec/spec_helper.rb +96 -0
- metadata +37 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85532c366a0e19d0c8464795bc776747ec85d9f1
|
4
|
+
data.tar.gz: 79d90b1fbe3cbaf5e9392cf762b7cb6a185579ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8ae04e86375abee226a05bb34e5d923de5fe19425585d476b5f5dbb4fd0026c1f44bd1682514bb801107b8a013e230945cc1bad7302859224622c9ef262ed3c
|
7
|
+
data.tar.gz: 1e6f86adc60585cf236e7bf602deeefb2b119372f1b0be0e52499eb7e0be7dc216f146114fd1a07251ca1f61dd11d0e9b81334a763b3ed67745cbe537e9ebe43
|
data/.rspec
ADDED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["vala@glyph.fr"]
|
11
11
|
spec.summary = %q{Capistrano tasks to configure your remote dotenv files}
|
12
12
|
spec.description = %q{Capistrano tasks to configure your remote dotenv files}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/glyph-fr/capistrano-dotenv-tasks"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -18,7 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
|
21
|
+
spec.add_dependency 'capistrano', '~> 3.0'
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.7"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
25
|
end
|
@@ -1,26 +1,25 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module Capistrano
|
2
4
|
module Dotenv
|
3
5
|
class Config
|
4
6
|
VARIABLE_PATTERN = /^(\w+)=(.+)$/i
|
5
7
|
|
6
|
-
|
8
|
+
attr_reader :contents, :variables
|
7
9
|
|
8
|
-
def initialize(contents)
|
9
|
-
|
10
|
-
|
10
|
+
def initialize(contents = ''.freeze)
|
11
|
+
@contents = contents.to_s
|
12
|
+
@variables = {}
|
13
|
+
add(*@contents.lines)
|
11
14
|
end
|
12
15
|
|
13
16
|
def set(key, value)
|
14
17
|
variables[key] = value
|
15
18
|
end
|
16
19
|
|
17
|
-
def variables
|
18
|
-
@variables ||= {}
|
19
|
-
end
|
20
|
-
|
21
20
|
def compile
|
22
21
|
variables.map do |key, value|
|
23
|
-
%(#{ key }
|
22
|
+
%(#{ key }=#{ value })
|
24
23
|
end.join("\n")
|
25
24
|
end
|
26
25
|
|
@@ -39,6 +38,12 @@ module Capistrano
|
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
41
|
+
alias_method :to_s, :compile
|
42
|
+
|
43
|
+
def to_io
|
44
|
+
StringIO.new(compile)
|
45
|
+
end
|
46
|
+
|
42
47
|
private
|
43
48
|
|
44
49
|
def extract_variable_from(string)
|
@@ -1,20 +1,34 @@
|
|
1
1
|
require "capistrano/dotenv/version"
|
2
2
|
require "capistrano/dotenv/config"
|
3
3
|
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
set :capistrano_dotenv_role, -> { :app }
|
7
|
+
set :capistrano_dotenv_path, -> { shared_path.join('.env') }
|
8
|
+
set :capistrano_dotenv_path_escaped, -> {fetch(:capistrano_dotenv_path).to_s.shellescape }
|
9
|
+
set :capistrano_dotenv_path_exists, -> { "[ -f #{fetch(:capistrano_dotenv_path_escaped)} ]" }
|
10
|
+
|
4
11
|
namespace :config do
|
5
12
|
desc "fetch existing environments variables from .env config file"
|
6
13
|
task :show do
|
7
|
-
|
8
|
-
|
14
|
+
dotenv_path = fetch(:capistrano_dotenv_path_escaped)
|
15
|
+
|
16
|
+
on roles(fetch(:capistrano_dotenv_role)) do
|
17
|
+
info capture(:cat, dotenv_path) if test fetch(:capistrano_dotenv_path_exists)
|
9
18
|
end
|
10
19
|
end
|
11
20
|
|
12
21
|
desc "Set an environment variable in .env config file"
|
13
22
|
task :set do
|
14
|
-
|
15
|
-
|
23
|
+
dotenv_path = fetch(:capistrano_dotenv_path_escaped)
|
24
|
+
|
25
|
+
on roles(fetch(:capistrano_dotenv_role)) do
|
26
|
+
contents = capture(:cat, dotenv_path) if test fetch(:capistrano_dotenv_path_exists)
|
27
|
+
config = Capistrano::Dotenv::Config.new(contents)
|
28
|
+
|
16
29
|
config.add(*ARGV[2..-1])
|
17
|
-
|
30
|
+
|
31
|
+
upload!(config.to_io, dotenv_path)
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
@@ -24,10 +38,23 @@ namespace :config do
|
|
24
38
|
raise "You need to set `key=KEY_TO_BE_REMOVED` to remove a key"
|
25
39
|
end
|
26
40
|
|
27
|
-
|
28
|
-
|
41
|
+
dotenv_path = fetch(:capistrano_dotenv_path_escaped)
|
42
|
+
|
43
|
+
on roles(fetch(:capistrano_dotenv_role)) do
|
44
|
+
contents = capture(:cat, dotenv_path) if test fetch(:capistrano_dotenv_path_exists)
|
45
|
+
config = Capistrano::Dotenv::Config.new(contents)
|
46
|
+
|
29
47
|
config.remove(ENV['key'])
|
30
|
-
upload!(
|
48
|
+
upload!(config.to_io, dotenv_path)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :dotenv do
|
54
|
+
desc 'create the .env in shared directory'
|
55
|
+
task :touch do
|
56
|
+
on release_roles :all do # same as deploy:check:linked_files
|
57
|
+
execute :touch, fetch(:capistrano_dotenv_path_escaped)
|
31
58
|
end
|
32
59
|
end
|
33
60
|
end
|
data/spec/config_spec.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'capistrano/dotenv/config'
|
2
|
+
|
3
|
+
RSpec.describe Capistrano::Dotenv::Config do
|
4
|
+
|
5
|
+
shared_examples_for '#to_s' do
|
6
|
+
subject { config.to_s }
|
7
|
+
it { is_expected.to eq(contents) }
|
8
|
+
end
|
9
|
+
|
10
|
+
subject(:config) { described_class.new(contents) }
|
11
|
+
|
12
|
+
context 'VAR=foo' do
|
13
|
+
let(:contents) { 'VAR=foo' }
|
14
|
+
|
15
|
+
it_behaves_like '#to_s' do
|
16
|
+
describe '#add' do
|
17
|
+
before { config.add('NAME=value') }
|
18
|
+
it { is_expected.to eq("VAR=foo\nNAME=value")}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#remove' do
|
22
|
+
before { config.remove('VAR') }
|
23
|
+
it { is_expected.to eq('') }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'VAR=foo bar' do
|
29
|
+
let(:contents) { 'VAR=foo bar' }
|
30
|
+
it_behaves_like '#to_s'
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Allows RSpec to persist some state between runs in order to support
|
54
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
55
|
+
# you configure your source control system to ignore this file.
|
56
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
57
|
+
|
58
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
59
|
+
# recommended. For more details, see:
|
60
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
61
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
62
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
63
|
+
config.disable_monkey_patching!
|
64
|
+
|
65
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
66
|
+
# be too noisy due to issues in dependencies.
|
67
|
+
config.warnings = true
|
68
|
+
|
69
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
70
|
+
# file, and it's useful to allow more verbose output when running an
|
71
|
+
# individual spec file.
|
72
|
+
if config.files_to_run.one?
|
73
|
+
# Use the documentation formatter for detailed output,
|
74
|
+
# unless a formatter has already been configured
|
75
|
+
# (e.g. via a command-line flag).
|
76
|
+
config.default_formatter = 'doc'
|
77
|
+
end
|
78
|
+
|
79
|
+
# Print the 10 slowest examples and example groups at the
|
80
|
+
# end of the spec run, to help surface which specs are running
|
81
|
+
# particularly slow.
|
82
|
+
config.profile_examples = 10
|
83
|
+
|
84
|
+
# Run specs in random order to surface order dependencies. If you find an
|
85
|
+
# order dependency and want to debug it, you can fix the order by providing
|
86
|
+
# the seed, which is printed after each run.
|
87
|
+
# --seed 1234
|
88
|
+
config.order = :random
|
89
|
+
|
90
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
91
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
92
|
+
# test failures related to randomization by passing the same `--seed` value
|
93
|
+
# as the one that triggered the failure.
|
94
|
+
Kernel.srand config.seed
|
95
|
+
=end
|
96
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-dotenv-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Valentin Ballestrino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +52,20 @@ dependencies:
|
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
41
69
|
description: Capistrano tasks to configure your remote dotenv files
|
42
70
|
email:
|
43
71
|
- vala@glyph.fr
|
@@ -46,6 +74,7 @@ extensions: []
|
|
46
74
|
extra_rdoc_files: []
|
47
75
|
files:
|
48
76
|
- ".gitignore"
|
77
|
+
- ".rspec"
|
49
78
|
- Gemfile
|
50
79
|
- LICENSE.txt
|
51
80
|
- README.md
|
@@ -54,7 +83,9 @@ files:
|
|
54
83
|
- lib/capistrano/dotenv/config.rb
|
55
84
|
- lib/capistrano/dotenv/tasks.rb
|
56
85
|
- lib/capistrano/dotenv/version.rb
|
57
|
-
|
86
|
+
- spec/config_spec.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
homepage: https://github.com/glyph-fr/capistrano-dotenv-tasks
|
58
89
|
licenses:
|
59
90
|
- MIT
|
60
91
|
metadata: {}
|
@@ -78,4 +109,6 @@ rubygems_version: 2.4.4
|
|
78
109
|
signing_key:
|
79
110
|
specification_version: 4
|
80
111
|
summary: Capistrano tasks to configure your remote dotenv files
|
81
|
-
test_files:
|
112
|
+
test_files:
|
113
|
+
- spec/config_spec.rb
|
114
|
+
- spec/spec_helper.rb
|