orgupdatematrix 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a133c88cdee73f8ad7ebc7b124f1c1bc16480617d71a4e64a9a230f0dc7c353c
4
+ data.tar.gz: f3c46ca639b4e9746d6b2b0c18714a7d307f9921692b3dc21cb2f28669ce410d
5
+ SHA512:
6
+ metadata.gz: 99a2cc31681e33e8ed180fda5bd362d099251658c1287b7a50b69ee997e0d5e3f28476514c5b59cf0cc5591e8f270cca97a255f8d2c820e38442e525d214234e
7
+ data.tar.gz: 66c51f0c3b175a7ba47c8ff2ca4e93f496c9931e09b3957369bd39fd2090569fa1e390420c09f25931134de8e6579f3148abcedebad5c73306d2fb0c86821004
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in orgupdatematrix.gemspec
4
+ gemspec
5
+
6
+ gem 'octokit'
7
+ gem 'octopoller'
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ orgupdatematrix (0.1.1)
5
+ octokit (~> 4)
6
+ octopoller
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.6.0)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ faraday (0.15.4)
14
+ multipart-post (>= 1.2, < 3)
15
+ multipart-post (2.1.0)
16
+ octokit (4.14.0)
17
+ sawyer (~> 0.8.0, >= 0.5.3)
18
+ octopoller (0.1.0)
19
+ public_suffix (3.0.3)
20
+ rake (10.5.0)
21
+ sawyer (0.8.2)
22
+ addressable (>= 2.3.5)
23
+ faraday (> 0.8, < 2.0)
24
+
25
+ PLATFORMS
26
+ java
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 2.0)
31
+ octokit
32
+ octopoller
33
+ orgupdatematrix!
34
+ rake (~> 10.0)
35
+
36
+ BUNDLED WITH
37
+ 2.0.1
data/Makefile ADDED
@@ -0,0 +1,2 @@
1
+ all :
2
+ rake build
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # OrgUpdateMatrix
2
+
3
+ This gem revceives data from a Capistrano run and updates a specified YAML file in the specified GitHub repository.
4
+
5
+ Depends on the "octokit" gem [https://github.com/octokit/octokit.rb](https://github.com/octokit/octokit.rb)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'orgupdatematrix'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install orgupdatematrix
22
+
23
+ ## Usage
24
+
25
+ Add to your Capfile:
26
+
27
+ `require 'orgupdatematrix'`
28
+
29
+ Add an `:app_url` variable to each deploy env file such as `deploy/environments/staging.rb`:
30
+
31
+ ```
32
+ set :app_url, 'https://staging.my-application.com'
33
+ ```
34
+
35
+ Auth: generate a GitHub [personal access token](https://github.com/settings/tokens) and supply it at deploy time:
36
+
37
+ ```
38
+ GITHUB_API_TOKEN=token-value cap production deploy
39
+ ```
40
+
41
+ Add the following task to your Capistrano config eg. `deploy/config.rb`:
42
+
43
+ ```
44
+ desc 'Update Matrix'
45
+ task :update_matrix do
46
+ optional_extras = {
47
+ 'my_var1' => 'value1',
48
+ 'my_var2' => 'value2'
49
+ }
50
+ on roles(:web) do
51
+ within repo_path do
52
+ info 'Updating deploy matrix!'
53
+ commit = capture(:git, 'rev-list', '-n', '1', fetch(:branch)).chomp
54
+ 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))
56
+ end
57
+ end
58
+ end
59
+
60
+ after :finished, :update_matrix
61
+ ```
62
+
63
+ This will update the remote YAML file to look like this:
64
+
65
+ ```
66
+ ---
67
+ app_name:
68
+ stage_name:
69
+ branch: branch_or_tag_name
70
+ commit: 6209dc2138df2ecb808559d8f1c5bc41bfd17d0d
71
+ updated: 2019-05-09 03:51:50 UTC
72
+ app_url: https://staging.my-application.com
73
+ github_url: https///github.com/MyUser/AppRepo.git
74
+ extras:
75
+ my_var1: value1
76
+ my_var2: value2
77
+ ```
78
+
79
+ Only the specified `application` + `stage` section will be updated. The rest of the file's contents will remain unchanged.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "orgupdatematrix"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ require "orgupdatematrix/version"
2
+ require "octokit"
3
+ require "octopoller"
4
+ require "yaml"
5
+ require "base64"
6
+
7
+ module OrgUpdateMatrix
8
+ class Updater
9
+ def initialize(repo, file_path, auth_token)
10
+ @repo = repo
11
+ @file_path = file_path
12
+ @client = Octokit::Client.new(access_token: auth_token)
13
+ end
14
+
15
+ def get_file_contents
16
+ @client.contents(@repo, path: @file_path)
17
+ end
18
+
19
+ def log(message, indent = 6)
20
+ puts("#{' ' * indent}#{message}")
21
+ end
22
+
23
+ def update(app, stage, branch, commit, app_url, repo_url, extras = nil)
24
+ file = get_file_contents
25
+ data = YAML::load(Base64.decode64(file.content))
26
+
27
+ app = app.to_s
28
+ stage = stage.to_s
29
+ state = {
30
+ 'branch' => branch.to_s,
31
+ 'commit' => commit,
32
+ 'updated' => Time.now.utc.to_s,
33
+ 'app_url' => app_url,
34
+ 'github_url' => repo_url.gsub('git@', 'https://').gsub(':', '/'),
35
+ }
36
+
37
+ data[app] ||= {}
38
+ data[app][stage] = state
39
+ data[app][stage]['extras'] = extras if extras
40
+
41
+ log("app: #{app}", 9)
42
+ log("stage: #{stage}", 9)
43
+ state.each { |key, value| log("#{key}: #{value}", 9) }
44
+
45
+ Octopoller.poll(wait: :exponentially, retries: 6) do
46
+ begin
47
+ message = "update deploy matrix: #{app}:#{stage}"
48
+ result = @client.update_contents(@repo, @file_path, message, file[:sha], data.to_yaml)
49
+ log('Update complete!') if result[:commit]
50
+ rescue StandardError => e
51
+ log("Error: #{e.message}")
52
+ log('Retrying with latest commit...')
53
+ file = get_file_contents
54
+ :re_poll
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module OrgUpdateMatrix
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "orgupdatematrix/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "orgupdatematrix"
7
+ spec.version = OrgUpdateMatrix::VERSION
8
+ spec.authors = ["Mark Luntzel"]
9
+ spec.email = ["mark@luntzel.com"]
10
+
11
+ spec.summary = %q{"Updates a YAML file with Capistrano deploy data"}
12
+ spec.description = %q{}
13
+ spec.homepage = "https://github.com/ProjectVegas/orgupdatematrix"
14
+
15
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
16
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/ProjectVegas/orgupdatematrix"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ # Specify which files should be added to the gem when it is released.
26
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "bin"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.required_ruby_version = ">= 2.4"
35
+ spec.add_dependency "octokit", "~> 4"
36
+ spec.add_dependency "octopoller"
37
+ spec.add_development_dependency "bundler", "~> 2.0"
38
+ spec.add_development_dependency "rake", "~> 10.0"
39
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: orgupdatematrix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Mark Luntzel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: octopoller
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: ''
70
+ email:
71
+ - mark@luntzel.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".ruby-version"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - Makefile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/orgupdatematrix.rb
86
+ - lib/orgupdatematrix/version.rb
87
+ - orgupdatematrix.gemspec
88
+ homepage: https://github.com/ProjectVegas/orgupdatematrix
89
+ licenses: []
90
+ metadata:
91
+ allowed_push_host: https://rubygems.org
92
+ homepage_uri: https://github.com/ProjectVegas/orgupdatematrix
93
+ source_code_uri: https://github.com/ProjectVegas/orgupdatematrix
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '2.4'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.0.3
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: '"Updates a YAML file with Capistrano deploy data"'
113
+ test_files: []