wercker-bundle-update-pr
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.
(Both concept and implementaion are strongly based on circleci-bundle-update-pr.
Installation
$ gem install wercker-bundle-update-pr
Usage
Prerequisites
The application on which you want to execute bundle update
automatically must be on a Wercker CI.
Getting GitHub Personal access token
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.
Getting Werkcer personal token
A Wercker personal token is required for invoking Trigger Build API. Go to your account's settings page and obtain a personal token.
Wercker application configuration
In the application's setting page:
- Generate SSH key named "wercker_github_ci_key" in "SSH Keys" for pushing changes to GitHub
- Register the above generated key to GitHub SSH keys in Personal settings
- 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) - In "Environment variables", add
WERCKER_GITHUB_CI_KEY
as SSH key pair and select "wercker_github_ci_key"
Configure wercker.yml
Add the following 2 steps under steps
to access GitHub via SSH (Set GitHub's SSH key RSA fingerprint to <fingerprint>
. See What are GitHub's SSH key fingerprints?):
- add-ssh-key:
keyname: WERCKER_GITHUB_CI_KEY
- add-to-known_hosts:
hostname: github.com
fingerprint: <fingerprint>
then add this step as well (replace <username>
and <email>
with yours).
- script:
code: |
if [ "${BUNDLE_UPDATE}" ] ; then
gem update bundler -N
gem install wercker-bundle-update-pr -N
wercker-bundle-update-pr <username> <email>
fi
Do not forget git commit
and git push
these changes.
Fire Trigger build API
Now all set to fire Trigger build API.
$ 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
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.
Development
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.
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.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/5t111111/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 code of conduct.
License
The gem is available as open source under the terms of the MIT License.