Circle Github Bot
This library helps you submit a comment on the PR from inside your CircleCI
build and link to a static artifact from the build.
When reviewing a PR on github, it's useful to read the code but even more useful
to test out the code on that branch in a live working web app.
See an example PR on this github repo https://github.com/themadcreator/circle-github-bot/pull/3
It works like so:
- Someone creates a pull request on your github project
- This triggers a CircleCI build, which:
- Runs tests
- Builds your static demo site
- Runs your demo.js script, submitting a comment back to the PR
- A comment shows up on the github PR
- CircleCI "collects" the artifacts from the build and makes them available on the web
- You click the link on the PR and see the static site!
Create a demo.js
script using this library to post a comment on github
referencing the current PR.
Example:
#!/usr/bin/env node
const bot = require("circle-github-bot").create();
bot.comment(`
<h3>${bot.env.commitMessage}</h3>
Demo: <strong>${bot.artifactLink('demo/index.html', 'demo')}</strong>
`);
With that "shebang" at the top, you can chmod +x
your script file from the
command line to make it self-executable.
Integrate CircleCI into your Repo
- Add CircleCI service integration to your github project in your repo's project settings
- Settings > Integrations & Services > Services
- Once CircleCI is following your github project, it will add its own deploy key to this repo
- Add
circle.yml
file to the root of your repo - Include your
demo/
directory in the general.artifacts
list - Include a section in
deployment
that generates your preview and posts the comment
general:
artifacts:
- demo
deployment:
demo:
branch: /.*/
commands:
- ./demo.js
Add Github Auth Token to CircleCI Environment
Make sure your script can actually post the comment to github
- Go to your github profile settings
- Add a new OAuth token under "Personal access tokens"
- Once created, add the token string to your CircleCI build's environment variables
- Build Settings > Environment variables
- Name the variable "GH_AUTH_TOKEN"
Require CircleCI Build for PRs
Optional, but helpful. This makes sure your builds actually pass before a PR can be submitted.
- Set your main branch (e.g. master) to protected
- Enabled "required status checks"
- Select "ci/circleci" as a required status check