The PR Build Bot is a Python web application that listens to Travis CI webhooks and posts selections from the build logs as comments on the GitHub PR. This allows commenting on PRs from both trusted and untrusted branches of the main repository without exposing the GitHub Personal Access Token of the commenting user.
This bot can be installed in any number of Python server environments. wptserve and Flask options are described below.
wptserve is a server used throughout the W3C testing infrastructure. There is currently no Ansible configuration for this installation type. The following general instructions should get you running.
- Python 2.7
- Install the
requests
andpyOpenSSL
modules into your Python environment.
- pyOpenSSL requires a dev version of OpenSSL (e.g.
libssl-dev
)
- Install wptserve.
- Clone from GitHub
- Run
sudo python setup.py install
from the cloned directory.
- Clone this project and
cd
into the cloned directory. - Configure the application for your project. See Configuration, below.
- Run
python wptserve_app.py
- May require
sudo
if you receive a "Permission Denied" error.
This installation process uses Ansible to configure the server to use nginx and uWSGI to serve a Flask application. It expects nginx to be able to use port 80.
- Ubuntu-like server environment
- git
- Ansible >= 2.2.1.0
- Note: on Ubuntu, this requires installing ansible via
pip
, notapt
.
- Note: on Ubuntu, this requires installing ansible via
This is how to install the dependencies and application on a base Ubuntu 16.04 box. Git should come out of the box.
- Create a server instance wherever you like.
- Add a non-root user to own the application.
adduser prbuildbot
as root- You will create a password for this user. Keep it secret. Keep it safe.
- Ensure the new user is able to
sudo
.
adduser prbuildbot sudo
as root
- Log into the server as the new user.
- Update apt repositories
sudo apt-get update
- Install pip.
sudo apt install python-pip
- Upgrade pip.
sudo -H pip install --upgrade pip
- Install libssl-dev.
sudo apt install libssl-dev
- Install Ansible.
sudo -H pip install ansible
- Fork this repository and clone it into the user's home directory.
git clone https://github.com/<your user name>/prbuildbot.git
- You will be editing a file under version control, so you should create your own fork and store your changes there.
- Configure the application for your project. See Configuration, below.
- Change into the
ansible
directory and run the provisioning script.
cd prbuildbot/ansible
ansible-playbook provision.yml
- Note: this must be run from the
prbuildbot/ansible
directory, or it will fail. - Note: This does not install any of the python modules into virtual_env, but at the system level. This is possible with Ansible, just not implemented yet.
You will need to set up a user on GitHub, get a personal access token for them, and set up the configuration file for the application.
- Set up a user on GitHub that you want to be the "commenter."
- Get a Personal Access Token for that user.
- Go to https://github.com/settings/tokens.
- Click "Generate new token"
- On the creation page, name the token and give it at least
public_repo
anduser:email
permissions.
- Set up the configuration file on the server.
- In the application directory:
cp config.sample.txt config.txt
- Edit the config properties as necessary (see below for descriptions)
- Edit
log_parser.py
to parse the Travis CI job logs in whatever way you require.
- The included
log_parser.py
includes the logic for parsing log files forw3c/web-platform-tests
as an example. - You should commit this file back into your fork so that you don't lose it in case you lose or change your server.
- Do not ever commit your config.txt, as it contains your Personal Access Token.
- Add a webhook notification in your main project's
.travis.yml
file:
-
notifications: webhooks: http://<your-server-here>/prbuildbot/travis
- Your server can be referenced by either an IP address or a fully-qualified domain name.
- Once your updated
.travis.yml
file is in your project, you should start receiving comments on pull requests from this bot.- Example: bobholt/web-platform-tests#4
Property | Description |
---|---|
TRAVIS_DOMAIN | The Travis CI domain that applies to your application (either travis-ci.com or travis-ci.org ) |
COMMENT_ENV_VAR | An environment variable used in your Travis CI build matrix that serves as a flag for whether or not the job's log should be parsed as a PR comment |
GH_TOKEN | The Personal Access Token created in Configuration Step 2, above |
ORG | The GitHub organization/owner of the main repository (this project's ORG would be "bobholt") |
REPO | The main repository (this project's REPO would be "prbuildbot") |
In the application root run python test
. If you have changed the log_parser,
you will have to update the log_parser.parse_logs
tests for your own
application.