mina-circle 1.4.0 → 3.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/mina-circle.rb +3 -0
- data/lib/mina-circle/circle-ci/build.rb +23 -0
- data/lib/mina-circle/circle-ci/project.rb +22 -25
- data/lib/mina-circle/curl_command.rb +21 -0
- data/lib/mina-circle/helpers.rb +24 -6
- data/lib/mina-circle/tasks.rb +37 -18
- data/lib/mina-circle/version.rb +1 -1
- metadata +16 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 546110a39af0be56b00c1e981dd2dd9b1af2f5ea80eb159fc822788994394b5b
|
4
|
+
data.tar.gz: 6ab1c740d9d7bf28f58c4894673cd8d2809f2cedb0430851e2e27536b5646e37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4772a7fd3b316f1c7623abb87da3674c6ba3318f49884bb09b42f91ca589e9897524cae767d9281ee1dc9c54fed79408da3ef305766c2b7a22f66cb8ff23950f
|
7
|
+
data.tar.gz: 07f7adbc92a598895e205a69d12dec4c1237a4d6773853efac90e0cede4db69cc0783b214a1d1037c239572eecd8c37be59e8b6d2ada6bd8a3c9693c327cc18b
|
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.dig '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,43 +1,40 @@
|
|
1
1
|
class CircleCI::Project
|
2
2
|
attr_writer :artifacts
|
3
|
-
attr_reader :vcs_type, :organization, :name
|
4
|
-
def initialize(organization:, name:,
|
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
8
|
end
|
10
9
|
|
11
|
-
def
|
12
|
-
|
10
|
+
def build_path
|
11
|
+
parts = api_path_parts + ['tree', real_branch]
|
12
|
+
|
13
|
+
parts.compact.join('/')
|
13
14
|
end
|
14
15
|
|
15
|
-
def
|
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
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def api_path(branch)
|
16
27
|
[
|
17
28
|
'project',
|
18
29
|
vcs_type,
|
19
30
|
organization,
|
20
|
-
name
|
31
|
+
name,
|
32
|
+
'tree',
|
33
|
+
branch
|
21
34
|
].join('/')
|
22
35
|
end
|
23
36
|
|
24
|
-
|
25
|
-
|
26
|
-
def fetch_artifacts
|
27
|
-
# To support Circle 2.0
|
28
|
-
build_info = CircleCI::Client.instance.get "#{api_path}", filter: 'successful', branch: branch ? branch : 'master', has_artifacts: true
|
29
|
-
|
30
|
-
build_num = 'latest' # circle version 1.0
|
31
|
-
|
32
|
-
if build_info.first['previous_successful_build']['build_num']
|
33
|
-
build_num = build_info.first['previous_successful_build']['build_num']
|
34
|
-
end
|
35
|
-
|
36
|
-
puts "Using Build: #{build_num}"
|
37
|
-
|
38
|
-
artifact_hashes = CircleCI::Client.instance.get "#{api_path}/#{build_num}/artifacts", filter: 'successful', branch: branch ? branch : 'master'
|
39
|
-
artifact_hashes.collect { |artifact_hash|
|
40
|
-
CircleCI::Artifact.new artifact_hash
|
41
|
-
}
|
37
|
+
def real_branch
|
38
|
+
branch || 'master'
|
42
39
|
end
|
43
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
|
data/lib/mina-circle/helpers.rb
CHANGED
@@ -1,12 +1,30 @@
|
|
1
1
|
require 'uri'
|
2
2
|
module MinaCircle
|
3
3
|
module Helpers
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
def artifact_fetch_command(settings)
|
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
|
+
if successful_for_job.empty?
|
18
|
+
STDERR.puts 'No successful builds for this branch and job name'
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
build_artifacts = successful_for_job.last.artifacts
|
23
|
+
|
24
|
+
deploy_artifact = build_artifacts.find { |artifact| artifact.filename == settings[:circleci_artifact] }
|
25
|
+
api_token = CircleCI::Client.instance.api_token
|
26
|
+
curl = CurlCommand.new deploy_artifact.url, settings[:circleci_artifact], api_token
|
27
|
+
curl.to_s
|
10
28
|
rescue RuntimeError => e
|
11
29
|
puts "Unable to determine url for deployment artifact"
|
12
30
|
puts e.message
|
data/lib/mina-circle/tasks.rb
CHANGED
@@ -17,28 +17,47 @@ 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
|
-
desc 'Downloads and explodes the archive file containing the build'
|
24
|
-
task :deploy do
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
22
|
+
def required_settings
|
23
|
+
[
|
24
|
+
:circleci_artifact,
|
25
|
+
:circleci_user,
|
26
|
+
:circleci_project,
|
27
|
+
:circleci_job_name,
|
28
|
+
:circleci_explode_command,
|
29
|
+
:branch,
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
def ensure_and_fetch!(setting_name)
|
34
|
+
ensure!(setting_name)
|
35
|
+
fetch(setting_name)
|
33
36
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
+
|
38
|
+
required_settings.each do |required_setting|
|
39
|
+
define_method required_setting do
|
40
|
+
ensure_and_fetch! required_setting
|
37
41
|
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Downloads and explodes the archive file containing the build'
|
45
|
+
task :deploy do
|
46
|
+
required_settings.each &method(:ensure!)
|
47
|
+
|
48
|
+
options = {
|
49
|
+
circleci_user: circleci_user,
|
50
|
+
circleci_project: circleci_project,
|
51
|
+
branch: branch,
|
52
|
+
circleci_job_name: circleci_job_name,
|
53
|
+
circleci_artifact: circleci_artifact,
|
54
|
+
}
|
55
|
+
|
56
|
+
comment "[mina-circle] Fetching: #{circleci_artifact}"
|
57
|
+
command artifact_fetch_command(options)
|
58
|
+
|
59
|
+
command "#{circleci_explode_command} #{circleci_artifact}"
|
38
60
|
|
39
|
-
|
40
|
-
queue echo_cmd("curl -o #{circleci_artifact} #{artifact_url}")
|
41
|
-
queue echo_cmd("#{circleci_explode_command} #{circleci_artifact}")
|
42
|
-
queue echo_cmd("rm #{circleci_artifact}")
|
61
|
+
command "rm #{circleci_artifact}"
|
43
62
|
end
|
44
63
|
end
|
data/lib/mina-circle/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mina-circle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0.beta.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Simpson
|
8
8
|
- Michael Yockey
|
9
|
-
|
9
|
+
- Ryan Cromwell
|
10
|
+
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date:
|
13
|
+
date: 2021-03-19 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: mina
|
@@ -17,47 +18,32 @@ dependencies:
|
|
17
18
|
requirements:
|
18
19
|
- - "~>"
|
19
20
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
21
|
-
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.3.0
|
21
|
+
version: '1.2'
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
24
|
version_requirements: !ruby/object:Gem::Requirement
|
27
25
|
requirements:
|
28
26
|
- - "~>"
|
29
27
|
- !ruby/object:Gem::Version
|
30
|
-
version: '
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.3.0
|
28
|
+
version: '1.2'
|
34
29
|
- !ruby/object:Gem::Dependency
|
35
30
|
name: rake
|
36
31
|
requirement: !ruby/object:Gem::Requirement
|
37
32
|
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.4'
|
41
33
|
- - ">="
|
42
34
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
35
|
+
version: 12.3.3
|
44
36
|
type: :development
|
45
37
|
prerelease: false
|
46
38
|
version_requirements: !ruby/object:Gem::Requirement
|
47
39
|
requirements:
|
48
|
-
- - "~>"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '10.4'
|
51
40
|
- - ">="
|
52
41
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
42
|
+
version: 12.3.3
|
54
43
|
- !ruby/object:Gem::Dependency
|
55
44
|
name: minitest
|
56
45
|
requirement: !ruby/object:Gem::Requirement
|
57
46
|
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '5.8'
|
61
47
|
- - ">="
|
62
48
|
- !ruby/object:Gem::Version
|
63
49
|
version: 5.8.0
|
@@ -65,25 +51,23 @@ dependencies:
|
|
65
51
|
prerelease: false
|
66
52
|
version_requirements: !ruby/object:Gem::Requirement
|
67
53
|
requirements:
|
68
|
-
- - "~>"
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
version: '5.8'
|
71
54
|
- - ">="
|
72
55
|
- !ruby/object:Gem::Version
|
73
56
|
version: 5.8.0
|
74
57
|
description: Deploy without dependancies using mina and CircleCI.
|
75
58
|
email:
|
76
|
-
-
|
77
|
-
- mike@heysparkbox.com
|
59
|
+
- ryan@heysparkbox.com
|
78
60
|
executables: []
|
79
61
|
extensions: []
|
80
62
|
extra_rdoc_files: []
|
81
63
|
files:
|
82
64
|
- lib/mina-circle.rb
|
83
65
|
- lib/mina-circle/circle-ci/artifact.rb
|
66
|
+
- lib/mina-circle/circle-ci/build.rb
|
84
67
|
- lib/mina-circle/circle-ci/circle_ci.rb
|
85
68
|
- lib/mina-circle/circle-ci/client.rb
|
86
69
|
- lib/mina-circle/circle-ci/project.rb
|
70
|
+
- lib/mina-circle/curl_command.rb
|
87
71
|
- lib/mina-circle/helpers.rb
|
88
72
|
- lib/mina-circle/tasks.rb
|
89
73
|
- lib/mina-circle/version.rb
|
@@ -91,7 +75,7 @@ homepage: https://github.com/sparkbox/mina-circle
|
|
91
75
|
licenses:
|
92
76
|
- MIT
|
93
77
|
metadata: {}
|
94
|
-
post_install_message:
|
78
|
+
post_install_message:
|
95
79
|
rdoc_options: []
|
96
80
|
require_paths:
|
97
81
|
- lib
|
@@ -102,13 +86,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
86
|
version: '0'
|
103
87
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
88
|
requirements:
|
105
|
-
- - "
|
89
|
+
- - ">"
|
106
90
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
91
|
+
version: 1.3.1
|
108
92
|
requirements: []
|
109
|
-
|
110
|
-
|
111
|
-
signing_key:
|
93
|
+
rubygems_version: 3.1.4
|
94
|
+
signing_key:
|
112
95
|
specification_version: 4
|
113
96
|
summary: Deploy your application from artifacts produced by CircleCI
|
114
97
|
test_files: []
|