dpl 2.0.3.beta.4 → 2.0.3.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +15 -3
- data/Gemfile.lock +444 -211
- data/Rakefile +36 -34
- data/bin/dpl +3 -1
- data/dpl.gemspec +25 -0
- data/lib/dpl/cli.rb +19 -14
- data/lib/dpl/ctx/bash.rb +18 -12
- data/lib/dpl/ctx/test.rb +21 -15
- data/lib/dpl/ctx.rb +2 -0
- data/lib/dpl/helper/assets.rb +4 -2
- data/lib/dpl/helper/cmd.rb +20 -18
- data/lib/dpl/helper/config_file.rb +5 -3
- data/lib/dpl/helper/cookbook_site_streaming_uploader.rb +249 -0
- data/lib/dpl/helper/env.rb +26 -22
- data/lib/dpl/helper/github.rb +2 -0
- data/lib/dpl/helper/interpolate.rb +8 -4
- data/lib/dpl/helper/memoize.rb +4 -1
- data/lib/dpl/helper/squiggle.rb +3 -1
- data/lib/dpl/helper/transliterate.rb +3 -1
- data/lib/dpl/helper/wrap.rb +3 -1
- data/lib/dpl/helper/zip.rb +3 -1
- data/lib/dpl/provider/dsl.rb +18 -4
- data/lib/dpl/provider/examples.rb +6 -2
- data/lib/dpl/provider/status.rb +26 -24
- data/lib/dpl/providers/anynines.rb +22 -20
- data/lib/dpl/providers/azure_web_apps.rb +21 -19
- data/lib/dpl/providers/bintray.rb +44 -37
- data/lib/dpl/providers/bluemixcloudfoundry.rb +38 -36
- data/lib/dpl/providers/boxfuse.rb +12 -10
- data/lib/dpl/providers/cargo.rb +7 -5
- data/lib/dpl/providers/chef_supermarket.rb +82 -80
- data/lib/dpl/providers/cloud66.rb +17 -15
- data/lib/dpl/providers/cloudfiles.rb +8 -6
- data/lib/dpl/providers/cloudformation.rb +191 -187
- data/lib/dpl/providers/cloudfoundry.rb +32 -30
- data/lib/dpl/providers/codedeploy.rb +35 -33
- data/lib/dpl/providers/convox.rb +32 -25
- data/lib/dpl/providers/datica.rb +30 -28
- data/lib/dpl/providers/ecr.rb +66 -64
- data/lib/dpl/providers/elasticbeanstalk.rb +14 -12
- data/lib/dpl/providers/engineyard.rb +60 -58
- data/lib/dpl/providers/firebase.rb +6 -4
- data/lib/dpl/providers/flynn.rb +8 -6
- data/lib/dpl/providers/gae.rb +28 -25
- data/lib/dpl/providers/gcs.rb +59 -57
- data/lib/dpl/providers/git_push.rb +199 -195
- data/lib/dpl/providers/gleis.rb +19 -17
- data/lib/dpl/providers/hackage.rb +15 -13
- data/lib/dpl/providers/hephy.rb +18 -16
- data/lib/dpl/providers/heroku/api.rb +72 -70
- data/lib/dpl/providers/heroku/git.rb +15 -13
- data/lib/dpl/providers/heroku.rb +40 -38
- data/lib/dpl/providers/lambda.rb +134 -134
- data/lib/dpl/providers/launchpad.rb +45 -43
- data/lib/dpl/providers/netlify.rb +7 -5
- data/lib/dpl/providers/npm.rb +61 -58
- data/lib/dpl/providers/nuget.rb +8 -6
- data/lib/dpl/providers/openshift.rb +8 -6
- data/lib/dpl/providers/opsworks.rb +23 -21
- data/lib/dpl/providers/pages/api.rb +14 -14
- data/lib/dpl/providers/pages/git.rb +53 -47
- data/lib/dpl/providers/pages.rb +3 -1
- data/lib/dpl/providers/puppetforge.rb +6 -4
- data/lib/dpl/providers/pypi.rb +55 -54
- data/lib/dpl/providers/releases.rb +30 -23
- data/lib/dpl/providers/rubygems.rb +35 -31
- data/lib/dpl/providers/s3.rb +148 -142
- data/lib/dpl/providers/scalingo.rb +18 -16
- data/lib/dpl/providers/script.rb +4 -2
- data/lib/dpl/providers/snap.rb +12 -9
- data/lib/dpl/providers/surge.rb +7 -5
- data/lib/dpl/providers/testfairy.rb +47 -43
- data/lib/dpl/providers/transifex.rb +20 -18
- data/lib/dpl/providers.rb +3 -1
- data/lib/dpl/string_ext.rb +3 -1
- data/lib/dpl/support/aws_sdk_patch.rb +4 -1
- data/lib/dpl/support/gems.rb +7 -3
- data/lib/dpl/support/gstore_patch.rb +3 -1
- data/lib/dpl/support/version.rb +13 -12
- data/lib/dpl/version.rb +3 -1
- data/lib/dpl.rb +2 -0
- data/status.json +237 -0
- metadata +32 -15
- /data/lib/dpl/providers/{packagecloud.rb → packagecloud.rb_} +0 -0
data/lib/dpl/providers/lambda.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'dpl/helper/zip'
|
2
4
|
|
3
5
|
module Dpl
|
@@ -9,13 +11,13 @@ module Dpl
|
|
9
11
|
|
10
12
|
full_name 'AWS Lambda'
|
11
13
|
|
12
|
-
description sq(<<-
|
14
|
+
description sq(<<-STR)
|
13
15
|
tbd
|
14
|
-
|
16
|
+
STR
|
15
17
|
|
16
|
-
gem 'aws-sdk-lambda', '~> 1.
|
17
|
-
gem 'nokogiri', '
|
18
|
-
gem 'rubyzip', '~>
|
18
|
+
gem 'aws-sdk-lambda', '~> 1.104.0'
|
19
|
+
gem 'nokogiri', '~> 1.15'
|
20
|
+
gem 'rubyzip', '~> 2.3', require: 'zip'
|
19
21
|
|
20
22
|
env :aws, :lambda
|
21
23
|
config '~/.aws/credentials', '~/.aws/config', prefix: 'aws'
|
@@ -32,23 +34,23 @@ module Dpl
|
|
32
34
|
opt '--memory_size MB', 'Amount of memory in MB to allocate to this Lambda', default: 128
|
33
35
|
opt '--subnet_ids IDS', 'List of subnet IDs to be added to the function', type: :array, note: 'Needs the ec2:DescribeSubnets and ec2:DescribeVpcs permission for the user of the access/secret key to work'
|
34
36
|
opt '--security_group_ids IDS', 'List of security group IDs to be added to the function', type: :array, note: 'Needs the ec2:DescribeSecurityGroups and ec2:DescribeVpcs permission for the user of the access/secret key to work'
|
35
|
-
opt '--environment VARS', 'List of Environment Variables to add to the function', type: :array, format: /[\w
|
36
|
-
opt '--runtime NAME', 'Lambda runtime to use', note: 'required when creating a new function', default: 'nodejs12.x', enum: %w
|
37
|
+
opt '--environment VARS', 'List of Environment Variables to add to the function', type: :array, format: /[\w-]+=.+/, note: 'Can be encrypted for added security', alias: :environment_variables
|
38
|
+
opt '--runtime NAME', 'Lambda runtime to use', note: 'required when creating a new function', default: 'nodejs12.x', enum: %w[nodejs16.x nodejs14.x nodejs12.x python3.8 python3.7 python3.6 python2.7 ruby2.7 ruby2.5 java11 java8 go1.x dotnetcore2.1]
|
37
39
|
opt '--dead_letter_arn ARN', 'ARN to an SNS or SQS resource used for the dead letter queue.'
|
38
40
|
opt '--kms_key_arn ARN', 'KMS key ARN to use to encrypt environment_variables.'
|
39
|
-
opt '--tracing_mode MODE', 'Tracing mode', default: 'PassThrough', enum: %w
|
41
|
+
opt '--tracing_mode MODE', 'Tracing mode', default: 'PassThrough', enum: %w[Active PassThrough], note: 'Needs xray:PutTraceSegments xray:PutTelemetryRecords on the role'
|
40
42
|
opt '--layers LAYERS', 'Function layer arns', type: :array
|
41
|
-
opt '--function_tags TAGS', 'List of tags to add to the function', type: :array, format: /[\w
|
43
|
+
opt '--function_tags TAGS', 'List of tags to add to the function', type: :array, format: /[\w-]+=.+/, note: 'Can be encrypted for added security'
|
42
44
|
opt '--publish', 'Create a new version of the code instead of replacing the existing one.'
|
43
45
|
opt '--zip PATH', 'Path to a packaged Lambda, a directory to package, or a single file to package', default: '.'
|
44
46
|
opt '--dot_match', 'Include hidden .* files to the zipped archive'
|
45
47
|
|
46
|
-
msgs login:
|
48
|
+
msgs login: 'Using Access Key: %{access_key_id}',
|
47
49
|
create_function: 'Creating function %{function_name}.',
|
48
|
-
update_config:
|
49
|
-
update_tags:
|
50
|
-
update_code:
|
51
|
-
description:
|
50
|
+
update_config: 'Updating existing function %{function_name}.',
|
51
|
+
update_tags: 'Updating tags.',
|
52
|
+
update_code: 'Updating code.',
|
53
|
+
description: 'Deploy build %{build_number} to AWS Lambda via Travis CI'
|
52
54
|
|
53
55
|
def login
|
54
56
|
info :login
|
@@ -62,150 +64,148 @@ module Dpl
|
|
62
64
|
|
63
65
|
private
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
def exists?
|
68
|
+
!!client.get_function(function_name:)
|
69
|
+
rescue ::Aws::Lambda::Errors::ResourceNotFoundException
|
70
|
+
false
|
71
|
+
end
|
70
72
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
73
|
+
def create
|
74
|
+
info :create_function
|
75
|
+
config = function_config
|
76
|
+
config = config.merge(code: { zip_file: function_zip })
|
77
|
+
config = config.merge(tags: function_tags) if function_tags?
|
78
|
+
client.create_function(config)
|
79
|
+
end
|
78
80
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end
|
89
|
-
end
|
81
|
+
def update
|
82
|
+
arn = update_config
|
83
|
+
client.wait_until(:function_updated, { function_name: })
|
84
|
+
update_tags(arn) if function_tags?
|
85
|
+
client.wait_until(:function_updated, { function_name: })
|
86
|
+
update_code
|
87
|
+
rescue Aws::Waiters::Errors::WaiterFailed
|
88
|
+
error 'Update timed out.'
|
89
|
+
end
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
def update_config
|
92
|
+
info :update_config
|
93
|
+
response = client.update_function_configuration(function_config)
|
94
|
+
response.function_arn
|
95
|
+
end
|
96
96
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
def update_tags(arn)
|
98
|
+
info :update_tags
|
99
|
+
client.tag_resource(tag_resource(arn))
|
100
|
+
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
def update_code
|
103
|
+
info :update_code
|
104
|
+
client.update_function_code(function_code)
|
105
|
+
end
|
106
106
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
107
|
+
def function_config
|
108
|
+
compact(
|
109
|
+
function_name:,
|
110
|
+
role:,
|
111
|
+
handler:,
|
112
|
+
description:,
|
113
|
+
timeout:,
|
114
|
+
memory_size:,
|
115
|
+
vpc_config:,
|
116
|
+
environment:,
|
117
|
+
runtime:,
|
118
|
+
dead_letter_config: dead_letter_arn,
|
119
|
+
kms_key_arn:,
|
120
|
+
tracing_config:,
|
121
|
+
layers:
|
122
|
+
)
|
123
|
+
end
|
124
124
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
125
|
+
def tag_resource(arn)
|
126
|
+
{
|
127
|
+
resource: arn,
|
128
|
+
tags: function_tags
|
129
|
+
}
|
130
|
+
end
|
131
131
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
132
|
+
def function_code
|
133
|
+
{
|
134
|
+
function_name:,
|
135
|
+
zip_file: function_zip,
|
136
|
+
publish: publish?
|
137
|
+
}
|
138
|
+
end
|
139
139
|
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
def handler
|
141
|
+
Handler.new(runtime, module_name, handler_name).to_s if handler_name?
|
142
|
+
end
|
143
143
|
|
144
|
-
|
145
|
-
|
146
|
-
|
144
|
+
def function_zip
|
145
|
+
Zip.new(zip, tmp_filename, opts).zip
|
146
|
+
end
|
147
147
|
|
148
|
-
|
149
|
-
|
150
|
-
|
148
|
+
def vpc_config
|
149
|
+
compact(subnet_ids:, security_group_ids:)
|
150
|
+
end
|
151
151
|
|
152
|
-
|
153
|
-
|
154
|
-
|
152
|
+
def environment
|
153
|
+
{ variables: split_vars(super) } if environment?
|
154
|
+
end
|
155
155
|
|
156
|
-
|
157
|
-
|
158
|
-
|
156
|
+
def dead_letter_arn
|
157
|
+
{ target_arn: super } if dead_letter_arn?
|
158
|
+
end
|
159
159
|
|
160
|
-
|
161
|
-
|
162
|
-
|
160
|
+
def tracing_config
|
161
|
+
{ mode: tracing_mode } if tracing_mode?
|
162
|
+
end
|
163
163
|
|
164
|
-
|
165
|
-
|
166
|
-
|
164
|
+
def function_tags
|
165
|
+
split_vars(super) if function_tags?
|
166
|
+
end
|
167
167
|
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
def description
|
169
|
+
interpolate(super || msg(:description), vars:)
|
170
|
+
end
|
171
171
|
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
def client
|
173
|
+
@client ||= Aws::Lambda::Client.new(region:, credentials:)
|
174
|
+
end
|
175
175
|
|
176
|
-
|
177
|
-
|
178
|
-
|
176
|
+
def credentials
|
177
|
+
Aws::Credentials.new(access_key_id, secret_access_key)
|
178
|
+
end
|
179
179
|
|
180
|
-
|
181
|
-
|
180
|
+
def split_vars(vars)
|
181
|
+
vars.map { |var| var.split('=', 2) }.to_h
|
182
|
+
end
|
183
|
+
|
184
|
+
def tmp_filename
|
185
|
+
@tmp_filename ||= "#{tmp_dir}/#{repo_name}.zip"
|
186
|
+
end
|
187
|
+
|
188
|
+
class Handler < Struct.new(:runtime, :module_name, :handler_name)
|
189
|
+
SEP = {
|
190
|
+
default: '.',
|
191
|
+
java: '::',
|
192
|
+
dotnet: '::',
|
193
|
+
go: ''
|
194
|
+
}.freeze
|
195
|
+
|
196
|
+
def to_s
|
197
|
+
[go? ? nil : module_name, sep, handler_name].compact.join
|
182
198
|
end
|
183
199
|
|
184
|
-
def
|
185
|
-
|
200
|
+
def sep
|
201
|
+
key = SEP.keys.detect { |key| runtime.start_with?(key.to_s) }
|
202
|
+
SEP[key || :default]
|
186
203
|
end
|
187
204
|
|
188
|
-
|
189
|
-
|
190
|
-
default: '.',
|
191
|
-
java: '::',
|
192
|
-
dotnet: '::',
|
193
|
-
go: ''
|
194
|
-
}
|
195
|
-
|
196
|
-
def to_s
|
197
|
-
[go? ? nil : module_name, sep, handler_name].compact.join
|
198
|
-
end
|
199
|
-
|
200
|
-
def sep
|
201
|
-
key = SEP.keys.detect { |key| runtime.start_with?(key.to_s) }
|
202
|
-
SEP[key || :default]
|
203
|
-
end
|
204
|
-
|
205
|
-
def go?
|
206
|
-
runtime.start_with?('go')
|
207
|
-
end
|
205
|
+
def go?
|
206
|
+
runtime.start_with?('go')
|
208
207
|
end
|
208
|
+
end
|
209
209
|
end
|
210
210
|
end
|
211
211
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dpl
|
2
4
|
module Providers
|
3
5
|
class Launchpad < Provider
|
@@ -5,18 +7,18 @@ module Dpl
|
|
5
7
|
|
6
8
|
status :alpha
|
7
9
|
|
8
|
-
description sq(<<-
|
10
|
+
description sq(<<-STR)
|
9
11
|
tbd
|
10
|
-
|
12
|
+
STR
|
11
13
|
|
12
14
|
env :launchpad
|
13
15
|
|
14
16
|
opt '--oauth_token TOKEN', 'Launchpad OAuth token', secret: true
|
15
17
|
opt '--oauth_token_secret SECRET', 'Launchpad OAuth token secret', secret: true
|
16
|
-
opt '--slug SLUG', 'Launchpad project slug', format:
|
18
|
+
opt '--slug SLUG', 'Launchpad project slug', format: %r{^~[^/]+/[^/]+/[^/]+$}, example: '~user-name/project-name/branch-name'
|
17
19
|
|
18
20
|
msgs invalid_credentials: 'Invalid credentials (%s)',
|
19
|
-
unknown_error:
|
21
|
+
unknown_error: 'Error: %s (%s)'
|
20
22
|
|
21
23
|
def deploy
|
22
24
|
handle_response(post)
|
@@ -24,34 +26,34 @@ module Dpl
|
|
24
26
|
|
25
27
|
private
|
26
28
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
29
|
+
def post
|
30
|
+
req = Net::HTTP::Post.new(path)
|
31
|
+
req['Authorization'] = authorization
|
32
|
+
req.set_form_data(data)
|
33
|
+
http.request(req)
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_response(res)
|
37
|
+
error :invalid_credentials, res.code if res.code == '401'
|
38
|
+
error :unknown_error, res.body, res.code unless res.is_a?(Net::HTTPSuccess)
|
39
|
+
end
|
40
|
+
|
41
|
+
def http
|
42
|
+
http = Net::HTTP.new('api.launchpad.net', 443)
|
43
|
+
http.use_ssl = true
|
44
|
+
http
|
45
|
+
end
|
46
|
+
|
47
|
+
def path
|
48
|
+
"/1.0/#{slug}/+code-import"
|
49
|
+
end
|
50
|
+
|
51
|
+
def data
|
52
|
+
{ 'ws.op' => 'requestImport' }
|
53
|
+
end
|
54
|
+
|
55
|
+
def authorization
|
56
|
+
squish(<<-AUTH)
|
55
57
|
OAuth oauth_consumer_key="Travis%20Deploy",
|
56
58
|
oauth_nonce="#{nonce}",
|
57
59
|
oauth_signature="%26#{oauth_token_secret}",
|
@@ -59,20 +61,20 @@ module Dpl
|
|
59
61
|
oauth_timestamp="#{now}",
|
60
62
|
oauth_token="#{oauth_token}",
|
61
63
|
oauth_version="1.0"
|
62
|
-
|
63
|
-
|
64
|
+
AUTH
|
65
|
+
end
|
64
66
|
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
def nonce
|
68
|
+
rand(36**32).to_s(36)
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
def now
|
72
|
+
Time.now.to_i
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
75
|
+
def squish(str)
|
76
|
+
str.strip.gsub(/\s+/, ' ')
|
77
|
+
end
|
76
78
|
end
|
77
79
|
end
|
78
80
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dpl
|
2
4
|
module Providers
|
3
5
|
class Netlify < Provider
|
@@ -5,9 +7,9 @@ module Dpl
|
|
5
7
|
|
6
8
|
status :stable
|
7
9
|
|
8
|
-
description sq(<<-
|
10
|
+
description sq(<<-STR)
|
9
11
|
tbd
|
10
|
-
|
12
|
+
STR
|
11
13
|
|
12
14
|
node_js '>= 12.0.0'
|
13
15
|
|
@@ -28,9 +30,9 @@ module Dpl
|
|
28
30
|
|
29
31
|
private
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
33
|
+
def deploy_opts
|
34
|
+
opts_for(%i[site auth dir functions message prod])
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
data/lib/dpl/providers/npm.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Dpl
|
2
4
|
module Providers
|
3
5
|
class Npm < Provider
|
@@ -7,9 +9,9 @@ module Dpl
|
|
7
9
|
|
8
10
|
full_name 'npm'
|
9
11
|
|
10
|
-
description sq(<<-
|
12
|
+
description sq(<<-STR)
|
11
13
|
tbd
|
12
|
-
|
14
|
+
STR
|
13
15
|
|
14
16
|
gem 'json'
|
15
17
|
|
@@ -17,27 +19,27 @@ module Dpl
|
|
17
19
|
|
18
20
|
opt '--email EMAIL', 'npm account email'
|
19
21
|
opt '--api_token TOKEN', 'npm api token', alias: :api_key, required: true, secret: true, note: 'can be retrieved from your local ~/.npmrc file', see: 'https://docs.npmjs.com/creating-and-viewing-authentication-tokens'
|
20
|
-
opt '--access ACCESS', 'Access level', enum: %w
|
22
|
+
opt '--access ACCESS', 'Access level', enum: %w[public private]
|
21
23
|
opt '--registry URL', 'npm registry url'
|
22
24
|
opt '--src SRC', 'directory or tarball to publish', default: '.'
|
23
25
|
opt '--tag TAGS', 'distribution tags to add'
|
24
26
|
opt '--run_script SCRIPT', 'run the given script from package.json', type: :array, note: 'skips running npm publish'
|
25
27
|
opt '--dry_run', 'performs test run without uploading to registry'
|
26
|
-
opt '--auth_method METHOD', 'Authentication method', enum: %w
|
28
|
+
opt '--auth_method METHOD', 'Authentication method', enum: %w[auth]
|
27
29
|
|
28
30
|
REGISTRY = 'https://registry.npmjs.org'
|
29
31
|
NPMRC = '~/.npmrc'
|
30
32
|
|
31
|
-
msgs version:
|
32
|
-
login:
|
33
|
+
msgs version: 'npm version: %{npm_version}',
|
34
|
+
login: 'Authenticated with API token %{api_token}'
|
33
35
|
|
34
36
|
cmds registry: 'npm config set registry "%{registry}"',
|
35
|
-
publish:
|
36
|
-
run:
|
37
|
+
publish: 'npm publish %{src} %{publish_opts}',
|
38
|
+
run: 'npm run %{script}'
|
37
39
|
|
38
40
|
errs registry: 'Failed to set registry config',
|
39
|
-
publish:
|
40
|
-
run:
|
41
|
+
publish: 'Failed to publish',
|
42
|
+
run: 'Failed to run script %{script}'
|
41
43
|
|
42
44
|
def login
|
43
45
|
info :version
|
@@ -60,68 +62,69 @@ module Dpl
|
|
60
62
|
|
61
63
|
private
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
end
|
65
|
+
def run_scripts
|
66
|
+
run_script.each do |script|
|
67
|
+
shell :run, script:
|
67
68
|
end
|
69
|
+
end
|
68
70
|
|
69
|
-
|
70
|
-
|
71
|
-
|
71
|
+
def publish_opts
|
72
|
+
opts_for(%i[access tag dry_run], dashed: true)
|
73
|
+
end
|
72
74
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
75
|
+
def write_npmrc
|
76
|
+
write_file(npmrc_path, npmrc)
|
77
|
+
info "#{NPMRC} size: #{file_size(npmrc_path)}"
|
78
|
+
end
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
def remove_npmrc
|
81
|
+
rm_f npmrc_path
|
82
|
+
end
|
81
83
|
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
def npmrc_path
|
85
|
+
expand(NPMRC)
|
86
|
+
end
|
85
87
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
88
|
+
def npmrc
|
89
|
+
if npm_version =~ /^1/ || auth_method == 'auth'
|
90
|
+
"_auth = #{api_token}\nemail = #{email}"
|
91
|
+
else
|
92
|
+
"//#{auth_endpoint}/:_authToken=#{api_token}"
|
92
93
|
end
|
94
|
+
end
|
93
95
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
96
|
+
def auth_endpoint
|
97
|
+
str = registry
|
98
|
+
str = strip_path(str) if str.include?('npm.pkg.github.com')
|
99
|
+
str = strip_protocol(str).sub(%r{/$}, '')
|
100
|
+
str
|
101
|
+
end
|
100
102
|
|
101
|
-
|
102
|
-
|
103
|
-
|
103
|
+
def registry
|
104
|
+
super || registry_from_package_json || REGISTRY
|
105
|
+
end
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
data && data.fetch('publishConfig', {})['registry']
|
108
|
-
end
|
107
|
+
def registry_from_package_json
|
108
|
+
return unless data = package_json
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
end
|
110
|
+
data && data.fetch('publishConfig', {})['registry']
|
111
|
+
end
|
113
112
|
|
114
|
-
|
115
|
-
|
116
|
-
|
113
|
+
def strip_path(url)
|
114
|
+
url.sub(URI(url).path, '')
|
115
|
+
end
|
117
116
|
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
def strip_protocol(url)
|
118
|
+
url.sub("#{URI(url).scheme}://", '')
|
119
|
+
end
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
121
|
+
def host(url)
|
122
|
+
URI(url).host
|
123
|
+
end
|
124
|
+
|
125
|
+
def package_json
|
126
|
+
File.exist?('package.json') ? JSON.parse(File.read('package.json')) : {}
|
127
|
+
end
|
125
128
|
end
|
126
129
|
end
|
127
130
|
end
|