Prepare your repository
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
ormagento
. Iforigin
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.
Enable the GitHub integration
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.
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. Omit this option if your repository is hosted with public Github or if your repository is not hosted on private servers. Omit this option if your repository URL is similar to https://github.com/{account}/{repository-name} . This can cause errors like Unable to connect to GitHub: repository not found . |
--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
Add the webhook in GitHub
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:
- Payload URL: Enter the URL returned when you enabled the GitHub integration.
- Content type: Choose application/json from the list.
- Secret: Enter a verification secret.
- Which events would you like to trigger this webhook?: Select Send me everything.
- Select the Active checkbox.
-
Click Add webhook.
Test the integration
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 Cloud Console and verify that your commit message is displayed and your project deploying.
Remove the integration
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.