|
| 1 | +--- |
| 2 | +title: Automating deployments to integrators | GitHub API |
| 3 | +--- |
| 4 | + |
| 5 | +# Automating deployments to integrators |
| 6 | + |
| 7 | +* TOC |
| 8 | +{:toc} |
| 9 | + |
| 10 | +The "[Delivering deployments](/guides/delivering-deployments/)" guide describes how to build a server that uses the [Deployments API][deploy API] to easily get your code from GitHub into production. But what if you don't want to host a separate service for deploying code? What if you just want to merge code and have it deploy without thinking about maintaining another app? |
| 11 | + |
| 12 | +You can use the GitHub Auto-Deployment service to receive changes made to your repository and configure it to deliver a deployment to integrators. The Auto-Deployment service can deliver payloads based on two events: whenever a push is made and whenever [the CI status is passing](/guides/building-a-ci-server/). |
| 13 | + |
| 14 | +Here's a diagram demonstrating what the process might look like: |
| 15 | + |
| 16 | +``` |
| 17 | ++--------------------+ +--------+ +-----------+ |
| 18 | +| GitHub Auto-Deploy | | GitHub | | Heroku | |
| 19 | +| Service | +--------+ +-----------+ |
| 20 | ++--------------------+ | | |
| 21 | + | | | |
| 22 | + | Create Deployment | | |
| 23 | + |------------------------>| | |
| 24 | + | | | |
| 25 | + | | | |
| 26 | + | | Deployment Event | |
| 27 | + | |--------------------------------->| |
| 28 | + | | | |
| 29 | + | | Deployment Status (pending) | |
| 30 | + | |<---------------------------------| |
| 31 | + | | | |
| 32 | + | | | |
| 33 | + | | Deployment Status (success) | |
| 34 | + | |<---------------------------------| |
| 35 | + | | | |
| 36 | +``` |
| 37 | + |
| 38 | +{{#tip}} |
| 39 | + |
| 40 | +Note that the Auto-Deployment service only picks up changes from your default branch, which is usually `master`. |
| 41 | + |
| 42 | +{{/tip}} |
| 43 | + |
| 44 | +## Sending deployments whenever you push to a repository |
| 45 | + |
| 46 | +The Auto-Deployment service will be responsible for creating deployments when a push is made to your defalt branch. Next, we'll set up a service to receive those deployment events and handle the deployment of your project. |
| 47 | + |
| 48 | +1. Navigate to the repository where you’re setting up your deployments. |
| 49 | +2. In your repository's right sidebar, click <span aria-label="The edit icon" title="The edit icon" class="octicon octicon-tools"></span>. |
| 50 | +3. On the left, click **Webhooks & Services**. |
| 51 | + |
| 52 | +4. Click **Add service**, then type "GitHub Auto-Deployment."  |
| 53 | +5. Under **GitHub token**, paste an access token you've created. It must have at least the `repo` scope. For more information, see "[Creating an access token for command-line use](https://help.github.com/articles/creating-an-access-token-for-command-line-use)." |
| 54 | +6. Under **Environments**, optionally provide a list of environments you'd like to send your deployments to. This can be [any string you define](https://developer.github.com/v3/repos/deployments/#parameters) to describe your environment. The default is "production." |
| 55 | +7. If you *only* want builds that successfully passed a continuous test suite, select **Deploy on status**. |
| 56 | +8. If you're running this service on GitHub Enterprise, you must pass in your appliance's [endpoint URL](https://developer.github.com/v3/enterprise/#endpoint-urls). |
| 57 | +9. Click **Add service**. |
| 58 | + |
| 59 | +## Hooking up an integrator to deployments |
| 60 | + |
| 61 | +To implement our deployments, we'll use Heroku as an example service. |
| 62 | + |
| 63 | +1. Navigate to the repository where you’re setting up your deployments. |
| 64 | +2. In your repository's right sidebar, click <span aria-label="The edit icon" title="The edit icon" class="octicon octicon-tools"></span>. |
| 65 | +3. On the left, click **Webhooks & Services**. |
| 66 | + |
| 67 | +4. Click **Add service**, then type "Heroku."  |
| 68 | +5. Type the name of the Heroku application your GitHub repository should deploy to. |
| 69 | +6. Enter in your [Heroku OAuth token](https://devcenter.heroku.com/articles/oauth#direct-authorization). You must generate this yourself following the instructions in Heroku's documentation. |
| 70 | +7. Under **GitHub token**, paste the same token you provided earlier. |
| 71 | +8. Click **Add service**. |
| 72 | + |
| 73 | +From now on, any commits made to your `master` branch--including those generated from merging pull requests--will automatically trigger a deployment to your Heroku application. |
| 74 | + |
| 75 | +[deploy API]: /v3/repos/deployments/ |
0 commit comments