Information for: DEVELOPERS   PARTNERS

Integrating GitHub

Tutorial Goal

Implement continuous integration for a Drupal application on Acquia Cloud.

Lesson Goal

Integrate GitHub with your Acquia Cloud application so that when you create a new pull request on GitHub, a new pipelines build is automatically started.

Note

GitHub is not a requirement for Acquia Cloud CD.

In this lesson, we will integrate GitHub with the Acquia Cloud application such that, when a new pull request is created, a new CD pipelines build starts. GitHub is a popular SaaS tool that allows developers to write software collaboratively. It facilitates code review, discussion, and integration with Continuous Integration and Continuous Delivery tools.

A GitHub “pull request” allows a developer to propose code changes to a project. The changes in the pull request can be tested, reviewed, and discussed prior to merging those changes into a project.

In this lesson we will:

To complete this lesson you will need:

Create a GitHub repository

If you already have a GitHub repository, skip this step. Otherwise, sign into your GitHub account and navigate to https://github.com/new to create one.

Add GitHub as a new remote by modifying your project repository’s local clone. Then, push your code to GitHub:

git remote add github
[email protected]:[org-or-username]/[project-name].git
git push github master

Connect Acquia Cloud CD to GitHub

There are two ways to connect Acquia Cloud CD with GitHub:

  1. Use the Acquia Cloud interface in your web browser
  2. Use the Pipelines client on your command line

Use the Acquia Cloud UI in your web browser

To connect Acquia Cloud CD to GitHub using the Acquia Cloud interface, open a web browser and follow these steps:

  1. Visit cloud.acquia.com and log in.
  2. Select your Drupal application.
  3. Click the “Pipelines” link in the left-hand sidebar.
  4. Click More links and then click View application info.
  5. Under Connected repository information click Configure.
  6. Under Configure Pipelines with your GitHub repository click Configure.
  7. Click Connect to GitHub.
  8. Grant Pipelines access to GitHub.
  9. Click Select GitHub repository.
  10. Choose a repository to connect. Note that you may filter the list by entering a string into the Filter repositories field.

Use the Pipelines client on your command line

Note

If you have already connected Acquia Cloud CD to GitHub via the Acquia Cloud interface, skip ahead to the next section.

To connect Acquia Cloud CD to GitHub using the command line, generate a new access key on GitHub using the following steps:

  1. Navigate to https://github.com/settings/tokens.
  2. Click the gray Generate new token button.
  3. Click “repo” as the scope, then click the green Generate token button.
  4. Leave this tab open – you will need the token soon.

generate token image

The application ID is needed for the Acquia application. To find this, execute:

pipelines list-applications

A list of accessible applications appears. Find the correlating application and copy the ID to your clipboard. then run the following command:

pipelines github-connect --application-id=[Application ID from
list-applications] GITHUB_USER/GITHUB_REPO GITHUB_PERSONAL_ACCESS_TOKEN

Congratulations, GitHub is now integrated with Acquia Cloud CD pipelines!

Submit a pull request on GitHub

Introduce a simple change to the repository and propose that change by submitting a pull request.

Use GitHub’s user interface to complete the following:

  • Delete the default README.acquia file
  • Create a new git branch named remove-default-readme
  • Create a pull request from remove-default-readme to master

Triggering a pull request image

Optional: If you prefer not to use the GitHub UI to make changes, you may perform these same actions using the command line and then submit the pull request via the GitHub UI.

git checkout -b remove-default-readme
rm README.acquia
git add README.acquia
git commit -m 'Removing default README.acquia.'
git push github remove-default-readme

View the log for the triggered build

The pull request displays information about the CD pipelines job, including the ID, and the status (i.e. in progress, successful, or failed).

Pull request progress image

You may click on the yellow circle icon next to the build in order to view the log output for the job in the Pipelines UI. You may also view the log output on the command line by executing:

pipelines logs --job-id=[job-id]

Merge and manually deploy a build artifact to Acquia Cloud

Once the build is successful, a green check mark will be displayed in the GitHub UI. This indicates all of the commands in the acquia-pipelines.yaml file executed successfully.

You may confidently click the Merge button in the GitHub UI to merge the remove-default-readme branch into the master branch.

CD pipelines will automatically start another job for the newly merged commit(s) on the master branch. When finished, CD pipelines will create or update the pipelines-master-build branch on the Acquia Cloud with changes.

Deploy the pipelines-master-build branch to one of your Acquia environments to test your changes.

Deploying on Cloud image

Optional: If you prefer not to use the Acquia Cloud interface to deploy this branch, you may perform the following action on the command line using Acquia Cloud API’s drush commands:

drush ac-code-path-deploy @mysite.dev pipelines-master-build

However, this requires that you locally install drush aliases for your site.

Next Lesson