Skip to content

Commit

Permalink
Merge pull request #1145 from native-api/npm_v2_alias
Browse files Browse the repository at this point in the history
npm: port alias from travis-yml and dpl v2
  • Loading branch information
BanzaiMan committed Jan 22, 2020
2 parents 4e1456f + c3d1999 commit e1ad6c0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
8 changes: 6 additions & 2 deletions lib/dpl/provider/npm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def setup_auth

def check_auth
setup_auth
log "Authenticated with email #{option(:email)} and API key #{option(:api_key)[-4..-1].rjust(20, '*')}"
log "Authenticated with email #{option(:email)} and API key #{api_key[-4..-1].rjust(20, '*')}"
end

def push_app
log "NPM API key format changed recently. If your deployment fails, check your API key in ~/.npmrc."
log "http://docs.travis-ci.com/user/deployment/npm/"
log "#{NPMRC_FILE} size: #{File.size(File.expand_path(NPMRC_FILE))}"

command = "env NPM_API_KEY=#{option(:api_key)} npm publish"
command = "env NPM_API_KEY=#{api_key} npm publish"
command << " --tag #{option(:tag)}" if options[:tag]
context.shell "#{command}"
FileUtils.rm(File.expand_path(NPMRC_FILE))
Expand Down Expand Up @@ -59,6 +59,10 @@ def npmrc_file_content
def npm_version
`npm --version`
end

def api_key
option(:api_key, :api_token)
end
end
end
end
28 changes: 20 additions & 8 deletions spec/provider/heroku_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,26 @@
provider.trigger_build
end

example do
expect(provider).to receive(:log).with('triggering new deployment')
expect(provider).to receive(:faraday).at_least(:once).and_return(faraday)
expect(provider).to receive(:get_url).and_return 'http://example.com/source.tgz'
expect(provider).to receive(:version).and_return 'v1.3.0'
expect(provider.context).to receive(:shell).with("curl -sS https://build-output.heroku.com/streams/01234567-89ab-cdef-0123-456789abcdef -H 'Accept: application/vnd.heroku+json; version=3' -H 'User-Agent: dpl/#{DPL::VERSION}'")
provider.trigger_build
expect(provider.build_id).to eq('01234567-89ab-cdef-0123-456789abcdef')
context 'when $stdout is a TTY' do
before do
@old_stdout = $stdout
$stdout = StringIO.new
allow($stdout).to receive(:isatty).and_return(true)
end

after do
$stdout = @old_stdout
end

example do
expect(provider).to receive(:log).with('triggering new deployment')
expect(provider).to receive(:faraday).at_least(:once).and_return(faraday)
expect(provider).to receive(:get_url).and_return 'http://example.com/source.tgz'
expect(provider).to receive(:version).and_return 'v1.3.0'
expect(provider.context).to receive(:shell).with("curl https://build-output.heroku.com/streams/01234567-89ab-cdef-0123-456789abcdef -H 'Accept: application/vnd.heroku+json; version=3' -H 'User-Agent: dpl/#{DPL::VERSION}'")
provider.trigger_build
expect(provider.build_id).to eq('01234567-89ab-cdef-0123-456789abcdef')
end
end

context 'when $stdout is not a TTY' do
Expand Down
13 changes: 13 additions & 0 deletions spec/provider/npm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@
described_class.new(DummyContext.new, :email => 'foo@blah.com', :api_key => 'test')
end

describe "#api_key" do
example do
expect(provider).to receive(:api_key).and_return("test")
provider.api_key
end

example do
alt = described_class.new(DummyContext.new, :api_token => 'test')
expect(alt).to receive(:api_key).and_return("test")
alt.api_key
end
end

describe "#check_auth" do
example do
expect(provider).to receive(:setup_auth)
Expand Down

0 comments on commit e1ad6c0

Please sign in to comment.