orgupdatematrix 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a133c88cdee73f8ad7ebc7b124f1c1bc16480617d71a4e64a9a230f0dc7c353c
4
- data.tar.gz: f3c46ca639b4e9746d6b2b0c18714a7d307f9921692b3dc21cb2f28669ce410d
3
+ metadata.gz: 22b7ebb74cac46f5103f0139dc3dcc3dbb10ca14586c81cdb68319cd47673cfe
4
+ data.tar.gz: 1d2e00daf8c7c7d0ebb74638b8c4ef938a3125cf14cf9d826580561a7ceb8f26
5
5
  SHA512:
6
- metadata.gz: 99a2cc31681e33e8ed180fda5bd362d099251658c1287b7a50b69ee997e0d5e3f28476514c5b59cf0cc5591e8f270cca97a255f8d2c820e38442e525d214234e
7
- data.tar.gz: 66c51f0c3b175a7ba47c8ff2ca4e93f496c9931e09b3957369bd39fd2090569fa1e390420c09f25931134de8e6579f3148abcedebad5c73306d2fb0c86821004
6
+ metadata.gz: 9ba57407f4254f3551d94811d1530fd77c1a3d2788c6780812d45d433b39af9ef89f1ed5666b39291b29226805a08f58c1f6549a03778ce9ce9be8ba5ae4a1b0
7
+ data.tar.gz: a261e70bfc2324ce988173385e5fc45c469230839ab9797a3da79d3bd2f5635de54dc11f22707ea3f379bfb3e20cdd2f2f8018fde897956fed158f7db0fd72cf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orgupdatematrix (0.1.1)
4
+ orgupdatematrix (0.2.0)
5
5
  octokit (~> 4)
6
6
  octopoller
7
7
 
@@ -12,11 +12,11 @@ GEM
12
12
  public_suffix (>= 2.0.2, < 4.0)
13
13
  faraday (0.15.4)
14
14
  multipart-post (>= 1.2, < 3)
15
- multipart-post (2.1.0)
15
+ multipart-post (2.1.1)
16
16
  octokit (4.14.0)
17
17
  sawyer (~> 0.8.0, >= 0.5.3)
18
18
  octopoller (0.1.0)
19
- public_suffix (3.0.3)
19
+ public_suffix (3.1.0)
20
20
  rake (10.5.0)
21
21
  sawyer (0.8.2)
22
22
  addressable (>= 2.3.5)
data/README.md CHANGED
@@ -32,6 +32,12 @@ Add an `:app_url` variable to each deploy env file such as `deploy/environments/
32
32
  set :app_url, 'https://staging.my-application.com'
33
33
  ```
34
34
 
35
+ Add the `matrix` role to the servers you want to report from:
36
+
37
+ ```
38
+ server 'staging.my-application.com', user: 'deploy', roles: %w{web matrix}
39
+ ```
40
+
35
41
  Auth: generate a GitHub [personal access token](https://github.com/settings/tokens) and supply it at deploy time:
36
42
 
37
43
  ```
@@ -47,12 +53,12 @@ Add the following task to your Capistrano config eg. `deploy/config.rb`:
47
53
  'my_var1' => 'value1',
48
54
  'my_var2' => 'value2'
49
55
  }
50
- on roles(:web) do
56
+ on roles(:matrix) do
51
57
  within repo_path do
52
58
  info 'Updating deploy matrix!'
53
59
  commit = capture(:git, 'rev-list', '-n', '1', fetch(:branch)).chomp
54
60
  updater = OrgUpdateMatrix::Updater.new('GitHubUser/RepoName', 'file-path.yml', ENV['GITHUB_API_TOKEN'])
55
- updater.update(fetch(:application), fetch(:stage), fetch(:branch), commit, fetch(:app_url), fetch(:repo_url))
61
+ updater.update(fetch(:application), fetch(:stage), fetch(:branch), commit, fetch(:app_url), fetch(:repo_url), fetch(:extra_env))
56
62
  end
57
63
  end
58
64
  end
@@ -70,7 +76,7 @@ app_name:
70
76
  commit: 6209dc2138df2ecb808559d8f1c5bc41bfd17d0d
71
77
  updated: 2019-05-09 03:51:50 UTC
72
78
  app_url: https://staging.my-application.com
73
- github_url: https///github.com/MyUser/AppRepo.git
79
+ github_url: https://github.com/MyUser/AppRepo.git
74
80
  extras:
75
81
  my_var1: value1
76
82
  my_var2: value2
@@ -20,10 +20,18 @@ module OrgUpdateMatrix
20
20
  puts("#{' ' * indent}#{message}")
21
21
  end
22
22
 
23
- def update(app, stage, branch, commit, app_url, repo_url, extras = nil)
24
- file = get_file_contents
23
+ def sort_data(hash)
24
+ hash.sort.to_h.each { |app, stage| hash[app] = stage.sort.to_h }
25
+ end
26
+
27
+ def update_yaml(file, app, stage, state)
25
28
  data = YAML::load(Base64.decode64(file.content))
29
+ data[app] ||= {}
30
+ data[app][stage] = state
31
+ sort_data(data)
32
+ end
26
33
 
34
+ def update(app, stage, branch, commit, app_url, repo_url, extras = nil)
27
35
  app = app.to_s
28
36
  stage = stage.to_s
29
37
  state = {
@@ -31,26 +39,24 @@ module OrgUpdateMatrix
31
39
  'commit' => commit,
32
40
  'updated' => Time.now.utc.to_s,
33
41
  'app_url' => app_url,
34
- 'github_url' => repo_url.gsub('git@', 'https://').gsub(':', '/'),
42
+ 'github_url' => repo_url.gsub('git@', 'https://').gsub(/(\w):(\w)/, '\1/\2'),
35
43
  }
36
-
37
- data[app] ||= {}
38
- data[app][stage] = state
39
- data[app][stage]['extras'] = extras if extras
44
+ state['extras'] = extras if extras
40
45
 
41
46
  log("app: #{app}", 9)
42
47
  log("stage: #{stage}", 9)
43
48
  state.each { |key, value| log("#{key}: #{value}", 9) }
49
+ message = "update deploy matrix: #{app}:#{stage}"
44
50
 
45
51
  Octopoller.poll(wait: :exponentially, retries: 6) do
46
52
  begin
47
- message = "update deploy matrix: #{app}:#{stage}"
53
+ file = get_file_contents
54
+ data = update_yaml(file, app, stage, state)
48
55
  result = @client.update_contents(@repo, @file_path, message, file[:sha], data.to_yaml)
49
56
  log('Update complete!') if result[:commit]
50
57
  rescue StandardError => e
51
58
  log("Error: #{e.message}")
52
59
  log('Retrying with latest commit...')
53
- file = get_file_contents
54
60
  :re_poll
55
61
  end
56
62
  end
@@ -1,3 +1,3 @@
1
1
  module OrgUpdateMatrix
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orgupdatematrix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Luntzel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-22 00:00:00.000000000 Z
11
+ date: 2019-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit