wercker-bundle-update-pr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +10 -0
- data/exe/wercker-bundle-update-pr +12 -0
- data/lib/wercker_bundle_update_pr.rb +73 -0
- data/lib/wercker_bundle_update_pr/version.rb +3 -0
- data/wercker-bundle-update-pr.gemspec +28 -0
- metadata +128 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f343168a816e643e6b2c3f342d04275105814303
|
4
|
+
data.tar.gz: 9e64ff09b58c1f401b99448aa6eb371027fcb86f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 573a5d056941830658976115b8c6be8111f28fec9bec7208be673ddc6aa8c40a8b5f96708b500ff539498ec430cf94714e4f811092a7e8ca18caf5ccdf2620c7
|
7
|
+
data.tar.gz: 15f6b302f1bd30df01c6fa1ed29da5a04f9fd8e6f08f98e6be2664a642155dc57f56aed814038e8a0946c53cc5cfa12594b47da00fb02a3426a15b9ba5e6f68c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hirofumi Wakasugi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# wercker-bundle-update-pr
|
2
|
+
|
3
|
+
This is an automation script to bundle update and send pull request via Wercker's Trigger Build API. By requesting trigger build to Wercker with an environment variable which instruct wercker.yml to execute this script, bundle update is invoked, then commit changes and send pull request to GitHub repository if there some changes exist.
|
4
|
+
|
5
|
+
(Both concept and implementaion are strongly based on [circleci-bundle-update-pr](https://github.com/masutaka/circleci-bundle-update-pr). Thnaks to [masutaka](https://github.com/masutaka))
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
``` text
|
10
|
+
$ gem install wercker-bundle-update-pr
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
### Prerequisites
|
16
|
+
|
17
|
+
The application on which you want to execute `bundle update` automatically must be on a Wercker CI.
|
18
|
+
|
19
|
+
### Getting GitHub Personal access token
|
20
|
+
|
21
|
+
A GitHub personal access token is required for sending GitHub pull request. Go to your account's settings page and obtain a personal access token.
|
22
|
+
|
23
|
+
### Getting Werkcer personal token
|
24
|
+
|
25
|
+
A Wercker personal token is required for invoking Trigger Build API. Go to your account's settings page and obtain a personal token.
|
26
|
+
|
27
|
+
### Wercker application configuration
|
28
|
+
|
29
|
+
In the application's setting page:
|
30
|
+
|
31
|
+
1. Generate SSH key named "wercker_github_ci_key" in "SSH Keys" for pushing changes to GitHub
|
32
|
+
1. Register the above generated key to GitHub SSH keys in Personal settings (note a fingerprint shown along with a key like `41:98:4b:7f:ae:...`)
|
33
|
+
1. In "Environment variables", add `GITHUB_ACCESS_TOKEN` with a GitHub personal access token (**Make sure you mark it "protected" otherwise it will be shown in logs**)
|
34
|
+
1. In "Environment variables", add `WERCKER_GITHUB_CI_KEY` as SSH key pair and select "wercker_github_ci_key"
|
35
|
+
|
36
|
+
### Configure wercker.yml
|
37
|
+
|
38
|
+
Add the following 2 steps under `steps` to access GitHub via SSH:
|
39
|
+
|
40
|
+
```yaml
|
41
|
+
- add-ssh-key:
|
42
|
+
keyname: WERCKER_GITHUB_CI_KEY
|
43
|
+
fingerprint: 15:59:4b:7c:59:d6:a1:00:0e:91:5a:0d:71:73:d8:7d
|
44
|
+
|
45
|
+
- add-to-known_hosts:
|
46
|
+
hostname: github.com
|
47
|
+
```
|
48
|
+
|
49
|
+
then add this step as well.
|
50
|
+
|
51
|
+
``` yaml
|
52
|
+
- script:
|
53
|
+
code: |
|
54
|
+
if [ -z "${BUNDLE_UPDATE}" ] ; then
|
55
|
+
ls >/dev/null 2>&1
|
56
|
+
else
|
57
|
+
gem update bundler --no-document
|
58
|
+
gem install wercker-bundle-update-pr
|
59
|
+
wercker-bundle-update-pr 5t111111 baenej@gmail.com
|
60
|
+
fi
|
61
|
+
```
|
62
|
+
|
63
|
+
Do not forget `git commit` and `git push` these changes.
|
64
|
+
|
65
|
+
### Fire Trigger build API
|
66
|
+
|
67
|
+
Now all set to fire Trigger build API.
|
68
|
+
|
69
|
+
``` text
|
70
|
+
$ curl -H 'Content-Type: application/json' -H "Authorization: Bearer <wercker personal token>" -X POST -d '{"applicationId": "<wercker application id>", "branch":"master", "message":"bundle update via trigger build", "envVars":[{"key":"BUNDLE_UPDATE","value":"true"}]}' https://app.wercker.com/api/v3/builds
|
71
|
+
```
|
72
|
+
|
73
|
+
You have to replace `<wercker personal token>` with your Wercker personal access token, and replace `<wercker application id>` which you can find in the URL of your wercker application.
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wercker-bundle-update-pr. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
84
|
+
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Usage:
|
4
|
+
# ruby wercker-bundle-update-pr username (optional) email (optional) branches (optional)
|
5
|
+
# Example:
|
6
|
+
# ruby wercker-bundle-update-pr alice alice@example.com develop
|
7
|
+
|
8
|
+
require 'wercker_bundle_update_pr'
|
9
|
+
|
10
|
+
WerckerBundleUpdatePr.run(username: ARGV.shift,
|
11
|
+
email: ARGV.shift,
|
12
|
+
branches: ARGV.empty? ? ['master'] : ARGV)
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "wercker_bundle_update_pr/version"
|
2
|
+
require 'octokit'
|
3
|
+
require 'compare_linker'
|
4
|
+
|
5
|
+
# An automation script to `bundle update` and send pull request via Wercker's Trigger Build API
|
6
|
+
module WerckerBundleUpdatePr
|
7
|
+
# Main process
|
8
|
+
# @param [String] username username for Git commitment
|
9
|
+
# @param [String] email email for Git commitment
|
10
|
+
# @param [Array] branches list of target branches
|
11
|
+
def self.run(username: nil, email: nil, branches: ['master'])
|
12
|
+
raise '$WERCKER_GIT_OWNER not set' unless ENV['WERCKER_GIT_OWNER']
|
13
|
+
raise '$WERCKER_GIT_REPOSITORY not set' unless ENV['WERCKER_GIT_REPOSITORY']
|
14
|
+
raise '$GITHUB_ACCESS_TOKEN not set' unless ENV['GITHUB_ACCESS_TOKEN']
|
15
|
+
|
16
|
+
username ||= client.user.login
|
17
|
+
email ||= "#{username}@users.noreply.github.com"
|
18
|
+
|
19
|
+
return unless bundle_update?(branches)
|
20
|
+
|
21
|
+
repository = "#{ENV['WERCKER_GIT_OWNER']}/#{ENV['WERCKER_GIT_REPOSITORY']}"
|
22
|
+
now = Time.now
|
23
|
+
branch = "bundle-update-#{now.strftime('%Y%m%d%H%M%S')}"
|
24
|
+
|
25
|
+
create_branch(username, email, branch)
|
26
|
+
pull_request = create_pull_request(repository, branch, now)
|
27
|
+
add_compare_linker_comment(repository, pull_request[:number])
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.bundle_update?(branches)
|
31
|
+
return false unless branches.include?(ENV['WERCKER_GIT_BRANCH'])
|
32
|
+
|
33
|
+
raise "Failed to run `bundle update`" unless system("bundle update")
|
34
|
+
`git status -sb 2> /dev/null`.include?("Gemfile.lock")
|
35
|
+
end
|
36
|
+
private_class_method :bundle_update?
|
37
|
+
|
38
|
+
def self.create_branch(username, email, branch)
|
39
|
+
`git config user.name #{username}`
|
40
|
+
`git config user.email #{email}`
|
41
|
+
`git checkout -b #{branch}`
|
42
|
+
`git add Gemfile.lock`
|
43
|
+
`git commit -m'bundle update'`
|
44
|
+
`git push origin #{branch}`
|
45
|
+
end
|
46
|
+
private_class_method :create_branch
|
47
|
+
|
48
|
+
def self.create_pull_request(repository, branch, now)
|
49
|
+
title = "bundle update at #{now.strftime('%Y-%m-%d %H:%M:%S %Z')}"
|
50
|
+
body = "Auto generated by [Wercker](#{ENV['WERCKER_APPLICATION_URL']})"
|
51
|
+
client.create_pull_request(repository, ENV['WERCKER_GIT_BRANCH'], branch, title, body)
|
52
|
+
end
|
53
|
+
private_class_method :create_pull_request
|
54
|
+
|
55
|
+
def self.add_compare_linker_comment(repository, pr_number)
|
56
|
+
ENV["OCTOKIT_ACCESS_TOKEN"] = ENV["GITHUB_ACCESS_TOKEN"]
|
57
|
+
compare_linker = CompareLinker.new(repository, pr_number)
|
58
|
+
compare_linker.formatter = CompareLinker::Formatter::Markdown.new
|
59
|
+
|
60
|
+
comment = <<-EOC
|
61
|
+
#{compare_linker.make_compare_links.to_a.join("\n")}
|
62
|
+
Powered by [compare_linker](https://rubygems.org/gems/compare_linker)
|
63
|
+
EOC
|
64
|
+
|
65
|
+
compare_linker.add_comment(repository, pr_number, comment)
|
66
|
+
end
|
67
|
+
private_class_method :add_compare_linker_comment
|
68
|
+
|
69
|
+
def self.client
|
70
|
+
Octokit::Client.new(access_token: ENV["GITHUB_ACCESS_TOKEN"])
|
71
|
+
end
|
72
|
+
private_class_method :client
|
73
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wercker_bundle_update_pr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "wercker-bundle-update-pr"
|
8
|
+
spec.version = WerckerBundleUpdatePr::VERSION
|
9
|
+
spec.authors = ["Hirofumi Wakasugi"]
|
10
|
+
spec.email = ["baenej@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An automation script to bundle update and send pull request via Wercker's Trigger Build API}
|
13
|
+
spec.description = %q{By requesting trigger build to Wercker with an environment variable which instruct wercker.yml to execute this script, bundle update is invoked, then commit changes and send pull request to GitHub repository if there some changes exist.}
|
14
|
+
spec.homepage = "https://github.com/5t111111/wercker-bundle-update-pr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "octokit", "~> 4.3"
|
23
|
+
spec.add_runtime_dependency "compare_linker", "~> 1.2"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wercker-bundle-update-pr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hirofumi Wakasugi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-11 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.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: compare_linker
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.11'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.11'
|
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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
description: By requesting trigger build to Wercker with an environment variable which
|
84
|
+
instruct wercker.yml to execute this script, bundle update is invoked, then commit
|
85
|
+
changes and send pull request to GitHub repository if there some changes exist.
|
86
|
+
email:
|
87
|
+
- baenej@gmail.com
|
88
|
+
executables:
|
89
|
+
- wercker-bundle-update-pr
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".travis.yml"
|
95
|
+
- Gemfile
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- exe/wercker-bundle-update-pr
|
100
|
+
- lib/wercker_bundle_update_pr.rb
|
101
|
+
- lib/wercker_bundle_update_pr/version.rb
|
102
|
+
- wercker-bundle-update-pr.gemspec
|
103
|
+
homepage: https://github.com/5t111111/wercker-bundle-update-pr
|
104
|
+
licenses:
|
105
|
+
- MIT
|
106
|
+
metadata: {}
|
107
|
+
post_install_message:
|
108
|
+
rdoc_options: []
|
109
|
+
require_paths:
|
110
|
+
- lib
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.5.1
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: An automation script to bundle update and send pull request via Wercker's
|
127
|
+
Trigger Build API
|
128
|
+
test_files: []
|