The GitHub integration allows you to manage your Platform.sh environments directly from your GitHub repository.
- Create a new environment when creating a branch or opening a pull request on GitHub.
- Rebuild the environment when pushing new code to GitHub.
- Delete the environment when merging a pull request.
To integrate your Platform.sh project with an existing GitHub repository, you first need to generate a token on your GitHub user profile. Simply go to your Settings, then select
Developer settings and click
Personal access tokens. Here you can Generate a new token.
Give it a description and then ensure the token has the following scopes:
- To integrate with public repositories:
- To integrate with your own private repositories:
- To integrate with your organization's private repositories:
Copy the token and make a note of it (temporarily).
Note that for the integration to work, your GitHub user needs to have permission to push code to the repository.
Note that only the project owner can manage integrations.
Open a terminal window (you need to have the Platform.sh CLI installed). Enable the GitHub integration as follows:
platform integration:add --type=github --project=PROJECT_ID --token=GITHUB-USER-TOKEN --repository=USER/REPOSITORY
PROJECT_IDis the project ID for your Platform.sh project
GITHUB-USER-TOKENis the token you generated in step 1
USERis your github user name
REPOSITORYis the name of the repository in github (not the git address)
Note that if your repository belongs to an organization, use
platform integration:add --type=github --project=abcde12345 --token=xxx --repository=platformsh/platformsh-docs
--fetch-branches: Track and deploy branches (true by default)
--build-pull-requests: Track and deploy pull-requests (true by default)
falseto have Platform.sh build the branch specified in a PR.
trueto build the result of merging the PR. (
--pull-requests-clone-parent-data: Set to
falseto disable cloning of parent environment data when creating a PR environment, so each PR environment starts with no data. (
The CLI will create the necessary webhook for you when there's correct permission set in the given token.
If you see the message
Failed to read or write webhooks, you will need to add a webhook manually:
- Copy the hook URL shown in the message.
- Go to your GitHub repository and click Settings, select the Webhooks and Services tab, and click Add webhook.
- Paste the hook URL, choose application/json for the content type, choose "Send me everything" for the events you want to receive, and click Add webhook.
You can now start pushing code, creating new branches or opening pull requests directly on your GitHub repository.
Note that if you have created your account using the GitHub oAuth Login then in order to use the Platform CLI, you will need to setup a password.
Environments based on GitHub pull requests will have the correct 'parent' environment on Platform.sh; they will be activated automatically with a copy of the parent's data.
However, environments based on (non-pull-request) branches cannot have parents; they will inherit directly from
master and start inactive by default.