The GitHub integration enables you to manage your Adobe Commerce on cloud infrastructure environments directly from your GitHub repository. The integration manages content already in GitHub and synchronizes with your Adobe Commerce on cloud infrastructure code repository. In essence, the code repository becomes a mirror of the GitHub repository.
We strongly recommend using a private repository for your Adobe Commerce on cloud infrastructure project to protect any proprietary information or development work, such as extensions and sensitive configurations.
This integration enables you to:
You must obtain a GitHub token and a webhook to continue the process.
Create a classic personal access token in GitHub developer settings. You must be a member of a group with write-access to the GitHub repository, so that you can push to the repository. Include the following scopes when creating your token:
admin:repo_hook
—Create web hooksrepo
—Integrate with your repositoryread:org
—Integrate with your organizational repositorySee GitHub: Create.
Clone your Adobe Commerce on cloud infrastructure project from an existing environment and migrate the project branches to a new, empty GitHub repository, preserving the same branch names. It is critical to retain an identical Git tree, so that you do not lose any existing environments or branches in your Adobe Commerce on cloud infrastructure project.
From the terminal, log in to your Adobe Commerce on cloud infrastructure project.
magento-cloud login
List your projects and copy the project ID.
magento-cloud project:list
Clone the project to your local environment.
magento-cloud project:get <project-ID>
Add your GitHub repository as a remote.
git remote add origin git@github.com:<user-name>/<repo-name>.git
The default name for the remote connection may be origin
or magento
. If origin
exists, you can choose a different name or you can rename or delete the existing reference. See git-remote documentation.
Verify that you added the GitHub remote correctly.
git remote -v
Expected response:
origin git@github.com:<user-name>/<repo-name>.git (fetch)
origin git@github.com:<user-name>/<repo-name>.git (push)
Push the project files to your new GitHub repository. Remember to keep all branch names the same.
git push -u origin master
If you are starting with a new GitHub repository, you may have to use the -f
option, because the remote repository does not match your local copy.
Verify that your GitHub repository contains all of your project files.
Before you begin, your project code and environments must be in the GitHub repository. After enabling the integration, the GitHub repository becomes the code source. If you push code changes to the original magento
repository, it is overwritten by the integration when you push code changes to your GitHub repository.
The following enables the GitHub integration and provides a Payload URL to use when creating a webhook.
The following command overwrites all code in your Adobe Commerce on cloud infrastructure project with code from your GitHub repository, which includes all branches, including the production
branch. This action happens instantly and cannot be undone. As a best practice, it is important to clone all of your branches from your Adobe Commerce on cloud infrastructure project and push them to your GitHub repository before adding the GitHub integration.
You can choose to step through the CLI prompts using magento-cloud integration:add
or you can build the integration command with the following options:
Option | Required? | Description |
---|---|---|
--base-url |
Yes | The base URL of the server installation, which may be https://github.com/ or a custom |
--token |
Yes | The personal access token that you generated for GitHub |
--repository |
Yes | The repository name: owner-or-organisation/repository |
--build-pull-requests |
Optional | Instructs Adobe Commerce on cloud infrastructure to deploy after you merge a pull request (true by default) |
--fetch-branches |
Optional | Causes Adobe Commerce on cloud infrastructure to track branches and deploy after you update a branch (true by default) |
--prune-branches |
Optional | Delete branches that do not exist on the remote (true by default) |
There are many more options, and you can see them using the help option:
magento-cloud integration:add --help
To enable the GitHub integration:
Enable the integration.
magento-cloud integration:add --type=github --project=<project-ID> --token=<your-GitHub-token> {--repository=USER/REPOSITORY | --repository=ORGANIZATION/REPOSITORY} [--build-pull-requests={true|false} --fetch-branches={true|false}
Example 1: Enable the GitHub integration for a personal, private repository:
magento-cloud integration:add --type=github --project=ov58dlacU2e --base-url=https://github.com --token=<token> --repository=myUserName/myrepo
Example 2: Enable the GitHub integration for an organization repository:
magento-cloud integration:add --type=github --project=ov58dlacU2e --base-url=https://github.com --token=<token> --repository=Magento/teamrepo
Enter the required information when prompted.
Copy the Payload URL displayed by the return output.
Created integration <integration-ID> (type: github)
Repository: myUserName/myrepo
Build PRs: yes
Fetch branches: yes
Payload URL: https://us.magento.cloud/api/projects/<project-id>/integrations/wO8a0eoamxwcg/hook
To communicate events—such as a push—with your Cloud Git server, you must create a webhook for your GitHub repository:
In your GitHub repository, click the Settings tab.
In the left navigation bar, click Webhooks.
In the Webhooks pane, click Add webhook.
In the Webhooks/Add webhook form, edit the following fields:
Click Add webhook.
After configuring the GitHub integration, you can verify that the integration is operational using the magento-cloud
CLI:
magento-cloud integration:validate
Or you can test it by pushing a simple change to your GitHub repository.
Create a test file.
touch test.md
Commit and push the change to your GitHub repository.
git add . && git commit -m "Testing GitHub integration" && git push
Log in to the Project Web Interface and verify that your commit message is displayed and your project deploying.
You can safely remove the GitHub integration from your project without affecting your code.
To remove the GitHub integration:
From the terminal, log in to your Adobe Commerce on cloud infrastructure project.
List your integrations. You need the GitHub integration ID to complete the next step.
magento-cloud integration:list
Delete the integration.
magento-cloud integration:delete <int-ID>
Also, you can remove the GitHub integration by logging in to your GitHub account and removing the web hook in the Webhooks tab of the repository Settings.