mina-circle 1.4.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 564af880f7175c4b7f2f5d2b4bf3d48717e40d33
4
- data.tar.gz: 7c32699c141eda87c7e11d497174961c7c3711ad
3
+ metadata.gz: c284a694ea4fb03205583c0faf93717b8c7c1d50
4
+ data.tar.gz: 70712c058c5f0fcd874151dcd094ae8cb208773a
5
5
  SHA512:
6
- metadata.gz: 534006608e15d9998887a0fdc905b47dc5033681368257b04a6691c442ecb38e989b4baecd55987f38d28c63481ed21fb8814d11cf3a5a75db3ab745554ae2fd
7
- data.tar.gz: 9843d874c5e77c4338e0696bd8421ddbea0ecb81688e7800fb91fe297ae02c2672e49fb9b08110c701c2a962ec1b83cfae50feb83723f150ff6fa06b0a1129a7
6
+ metadata.gz: 1bd3f9fbf9a60b63114f86261064837273892f460e2f0d0e7ea5b1c108830d643f3c2496ad6d7a19197e889eeb4177e3b596dff11ec25ec4f6828c1002a8dacf
7
+ data.tar.gz: 41fd371865b03df7dd201f44a91c0c09197ed1cf77a5079ce8230b240420c1c7c10be9b846d36657477795ba58b02034d60174267d32af42ab8f5cded7a08fc7
data/lib/mina-circle.rb CHANGED
@@ -1,7 +1,10 @@
1
1
  require 'mina-circle/version'
2
2
  require 'mina-circle/helpers'
3
3
  require 'mina-circle/tasks'
4
+ require 'mina-circle/curl_command'
4
5
  require 'mina-circle/circle-ci/circle_ci'
5
6
  require 'mina-circle/circle-ci/client'
6
7
  require 'mina-circle/circle-ci/artifact'
8
+ require 'mina-circle/circle-ci/build'
7
9
  require 'mina-circle/circle-ci/project'
10
+
@@ -0,0 +1,23 @@
1
+ class CircleCI::Build
2
+ attr_reader :job_name, :build_number, :status, :project
3
+ def initialize(hash, project)
4
+ @job_name = hash['workflows']['job_name']
5
+ @build_number = hash['build_num']
6
+ @status = hash['status']
7
+ @project = project
8
+ end
9
+
10
+ def artifacts
11
+ api_path = [
12
+ 'project',
13
+ project.vcs_type,
14
+ project.organization,
15
+ project.name,
16
+ build_number,
17
+ 'artifacts'
18
+ ].join '/'
19
+ client = CircleCI::Client.instance
20
+ response = client.get(api_path)
21
+ response.collect { |artifact| CircleCI::Artifact.new artifact }
22
+ end
23
+ end
@@ -1,19 +1,10 @@
1
1
  class CircleCI::Project
2
2
  attr_writer :artifacts
3
- attr_reader :vcs_type, :organization, :name, :branch
4
- def initialize(organization:, name:, branch:, vcs_type: 'github')
3
+ attr_reader :vcs_type, :organization, :name
4
+ def initialize(organization:, name:, vcs_type: 'github')
5
5
  @organization = organization
6
6
  @name = name
7
7
  @vcs_type = vcs_type
8
- @branch = branch
9
- end
10
-
11
- def artifacts
12
- @artifacts ||= fetch_artifacts
13
- end
14
-
15
- def api_path
16
- api_path_parts.join('/')
17
8
  end
18
9
 
19
10
  def build_path
@@ -22,32 +13,28 @@ class CircleCI::Project
22
13
  parts.compact.join('/')
23
14
  end
24
15
 
16
+ def recent_builds(branch)
17
+ client = CircleCI::Client.instance
18
+ path = api_path branch
19
+ response = client.get path
20
+ builds = response.collect { |build| CircleCI::Build.new(build, self) }
21
+ builds.compact
22
+ end
23
+
25
24
  private
26
25
 
27
- def api_path_parts
26
+ def api_path(branch)
28
27
  [
29
28
  'project',
30
29
  vcs_type,
31
30
  organization,
32
- name
33
- ]
31
+ name,
32
+ 'tree',
33
+ branch
34
+ ].join('/')
34
35
  end
35
36
 
36
37
  def real_branch
37
38
  branch || 'master'
38
39
  end
39
-
40
- def fetch_artifacts
41
- # To support Circle 2.0
42
- builds = CircleCI::Client.instance.get "#{build_path}", filter: 'successful', has_artifacts: true
43
- builds = builds.sort { |a, b| b['build_num'] - a['build_num'] }
44
- build_num = builds.first['build_num']
45
-
46
- puts "Using Build: #{build_num}"
47
-
48
- artifact_hashes = CircleCI::Client.instance.get "#{api_path}/#{build_num}/artifacts", filter: 'successful', branch: real_branch
49
- artifact_hashes.collect { |artifact_hash|
50
- CircleCI::Artifact.new artifact_hash
51
- }
52
- end
53
40
  end
@@ -0,0 +1,21 @@
1
+ class CurlCommand
2
+ attr_reader :artifact_url, :output_file_name, :api_key, :follow_redirects
3
+ def initialize(artifact_url, output_file_name, api_key, follow_redirects = true)
4
+ @artifact_url = artifact_url
5
+ @output_file_name = output_file_name
6
+ @api_key = api_key
7
+ @follow_redirects = follow_redirects
8
+ end
9
+
10
+ def follow_redirects?
11
+ !!follow_redirects
12
+ end
13
+
14
+ def authenticated_artifact_url
15
+ "#{artifact_url}?circle-token=#{api_key}"
16
+ end
17
+
18
+ def to_s
19
+ "curl #{follow_redirects? ? '-L' : ''} -o #{output_file_name} #{authenticated_artifact_url}"
20
+ end
21
+ end
@@ -1,12 +1,25 @@
1
1
  require 'uri'
2
2
  module MinaCircle
3
3
  module Helpers
4
- def artifact_url
5
- options = settings.select { |k,v|
6
- k.to_s.start_with? artifact_source.to_s.downcase or
7
- options_whitelist.include? k
8
- }
9
- Module.const_get(artifact_source.to_s).artifact_url(options)
4
+ def artifact_fetch_command
5
+ project = CircleCI::Project.new(
6
+ organization: settings[:circleci_user],
7
+ name: settings[:circleci_project]
8
+ )
9
+
10
+ recent_builds = project.recent_builds settings[:branch]
11
+
12
+ successful_for_job =
13
+ recent_builds
14
+ .select { |build| build.status == 'success' && build.job_name == settings[:circleci_job_name] }
15
+ .sort { |a, b| a.build_number <=> b.build_number }
16
+
17
+ build_artifacts = successful_for_job.last.artifacts
18
+
19
+ deploy_artifact = build_artifacts.find { |artifact| artifact.filename == settings[:circleci_artifact] }
20
+ api_token = CircleCI::Client.instance.api_token
21
+ curl = CurlCommand.new deploy_artifact.url, settings[:circleci_artifact], api_token
22
+ curl.to_s
10
23
  rescue RuntimeError => e
11
24
  puts "Unable to determine url for deployment artifact"
12
25
  puts e.message
@@ -17,8 +17,6 @@ extend MinaCircle::Helpers
17
17
  # ### circleci_explode_command
18
18
  # Command with options for decompressing the artifact archive
19
19
 
20
- set :artifact_source, :CircleCI
21
-
22
20
  namespace :mina_circle do
23
21
  desc 'Downloads and explodes the archive file containing the build'
24
22
  task :deploy do
@@ -37,7 +35,7 @@ namespace :mina_circle do
37
35
  end
38
36
 
39
37
  print_str "[mina-circle] Fetching: #{circleci_artifact}"
40
- queue echo_cmd("curl -o #{circleci_artifact} #{artifact_url}")
38
+ queue echo_cmd(artifact_fetch_command)
41
39
  queue echo_cmd("#{circleci_explode_command} #{circleci_artifact}")
42
40
  queue echo_cmd("rm #{circleci_artifact}")
43
41
  end
@@ -1,3 +1,3 @@
1
1
  module MinaCircle
2
- VERSION = '1.4.2'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-circle
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Simpson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-15 00:00:00.000000000 Z
12
+ date: 2019-03-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mina
@@ -81,9 +81,11 @@ extra_rdoc_files: []
81
81
  files:
82
82
  - lib/mina-circle.rb
83
83
  - lib/mina-circle/circle-ci/artifact.rb
84
+ - lib/mina-circle/circle-ci/build.rb
84
85
  - lib/mina-circle/circle-ci/circle_ci.rb
85
86
  - lib/mina-circle/circle-ci/client.rb
86
87
  - lib/mina-circle/circle-ci/project.rb
88
+ - lib/mina-circle/curl_command.rb
87
89
  - lib/mina-circle/helpers.rb
88
90
  - lib/mina-circle/tasks.rb
89
91
  - lib/mina-circle/version.rb
@@ -107,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
109
  version: '0'
108
110
  requirements: []
109
111
  rubyforge_project:
110
- rubygems_version: 2.5.1
112
+ rubygems_version: 2.5.2.3
111
113
  signing_key:
112
114
  specification_version: 4
113
115
  summary: Deploy your application from artifacts produced by CircleCI