docs/docs/cloud-ci-cd/github-integration.mdx
import Thumbnail from '@site/src/components/Thumbnail'; import HeadingIcon from '@site/src/components/HeadingIcon'; import ProductBadge from '@site/src/components/ProductBadge';
GitHub integration is intended to improve the CI/CD experience on Hasura Cloud. With GitHub integration, you can link a GitHub repository and a branch to a Hasura Cloud project and automatically deploy Metadata and Migrations in a given directory to the linked project.
Check out our Starter Kit to see a few example workflows.
With the Automatic deployment mode, Hasura Cloud automatically triggers a deployment for every commit pushed to the
GitHub repository from the given branch and directory.
The Automatic deployment mode also has the Deploy Now button which allows the user to retry deploying the latest
commit.
With Manual deployment mode, Hasura Cloud does not automatically deploy the commits pushed to the configured branch.
The deployment of the latest commit in that branch can be triggered manually by clicking the Deploy Now button.
To link a GitHub account, click on the Sign in with GitHub button in the Git Deployment section of the project
details.
When you link a new GitHub account, Hasura Cloud installs the Hasura Cloud GitHub App on your GitHub account. While authenticating, you can choose to grant access to all repositories or to specific repositories only.
<Thumbnail src="/img/projects/github-grant-access.png" alt="GitHub grant access" width="500px" />The permissions requested by Hasura Cloud can be viewed in the GitHub app settings once you install the app.
Once linked, the GitHub account with the granted scope becomes available to all the admins on the project as the session is used to manage the GitHub integration from the UI.
You'll need to set up a GitHub repository with the current Metadata of your Hasura project. This will become the starting point of the version control of the Metadata. If the repository is empty, the GitHub integration will result in loss of your existing Metadata on Hasura Cloud.
Within your local Hasura project's directory, if not already done, initialize a git repository. Then, run the following command via the Hasura CLI:
hasura metadata export --admin-secret <your-project-admin-secret> --endpoint <your-hasura-cloud-project-url>
This will export your project's Metadata to the metadata directory in your project directory in YAML format. Add and
commit these changes to git. Then, push the changes to your GitHub repository.
:::warning Working with Metadata
Once the GitHub integration is set-up, refrain from making changes in your Cloud project using Console. All the changes
to your project now should be executed by the version control process. If you have made a change directly in the Cloud
Console for any reason, please follow the metadata export command above and update your version control with the
latest Metadata. Otherwise, you may lose the manual changes in your project the next time GitHub integration runs.
You can learn more in our Metadata Best Practices guide.
:::
Specify the GitHub repository, branch and the hasura-project directory in the form as shown below.
<Thumbnail src="/img/projects/setup-github-integration.png" alt="Setup GitHub Integration" width="900px" />If the repository that you're looking for doesn't show up in the repository list, click
Configure Hasura Cloud on GitHub to grant access to the required repository.
Clicking on the Setup Git Deployment button integrates the specified GitHub repository, branch and directory with the
Hasura Cloud project. The details for the integration can be viewed in the Git Deployment section of project details.
Click on the Edit Deployment button in the GitHub Deployment section to edit the GitHub
repository/branch/directory/deployment mode for the GitHub integration.
User can view the deployed commits and their deployment status in the Deployment Log section of Git Deployment.
Once a commit deployment is triggered, the progress for a commit can be tracked by clicking on the View Logs button in
the Deployment Log section.
Refer to the following task wise breakdown of the deployment job to understand what the job will be doing.
Check the troubleshooting section below and do reach out to support if you observe any issues with the deployment process or run into any other problems post the deployment.
The following is a task wise breakdown of the commit deployment job.
<Thumbnail src="/img/projects/github-deployment-status.png" alt="GitHub deployment Progress" width="500px" />Each task in the deployment has realtime logs and can be viewed by clicking on the Logs option for each
successful/failed step.
The Metadata and Migrations are fetched from the GitHub repository and validated.
The Metadata in the GitHub repository is applied to the server.
The Migrations in the GitHub repository are applied to your data sources.
The Metadata on the server is reloaded and project health is verified before finalizing the update.
You need to ensure the your Cloud project has been appropriately set up to execute the deployment.
If a deployment fails, depending on the kind of error, you can fix it by retrying the deployment by either updating your Metadata and Migrations with a fix and pushing a commit to deploy again or by just redeploying the failed commit after making any required fixes to your project.
The following are some troubleshooting steps to fix some possible errors in the deployment sub-tasks:
As your Metadata has already been applied but applying your Migrations have failed, your project might be in an unhealthy state. If your Migrations and Metadata had only incremental changes, i.e. no existing objects were modified, you likely won’t have any service impact because existing parts of your Metadata are likely to be still valid and your existing functionality will be working as it were.
Look at the underlying database error. Make the appropriate fix depending on the error and redeploy.
Some common errors:
source with name “default” is inconsistent
In this situation, most likely either the target project doesn't have the required database connected or the ENV VARS or the database name used to connect the database is not matching in your source and target projects.
To fix this, use the same ENV VARS and connect the database with the same name in both your projects.
“relation '<some-object>' already exists”
In such situations when you get errors of tables or other objects already existing, this might be because the Migration might have been already applied on the database and the project was not yet aware of it.
To fix this, use the Hasura CLI command
hasura migrate apply --skip-execution --version <migration_version> --endpoint "<cloud_project_endpoint>" to mark
the Migration as already applied on the project. Then redeploy the failed commit to continue with further steps.
version check: failed to get version from server
In such situations, the project has inconsistent Metadata and has issues connecting to the server.
To fix this, try reloading the Metadata and confirming all required ENV VARS for the project are available. If the issue persists, please contact the Hasura Help Center.
Error code: 520
If you encounter an error code of 520 after attempting to apply migrations, this is likely due to a long-running
process. This issue can arise in various database systems when certain actions require exclusive access to data
structures, such as tables or rows.
For example, in PostgreSQL, operations that require an ACCESS EXCLUSIVE lock can lead to this error. Such locks
are commonly needed when performing actions like adding columns. More about PostgreSQL’s explicit locking can be
found in their documentation on explicit locking.
In these cases, it's helpful to create a new table with any new columns / changed column types, insert your data to the new table, and then drop the old table and rename the new one to match the now deprecated table.
Applying Migrations and Finalizing Update.<table-name></em>, it could be because:
hasura migrate delete --version <migration_version> --server --database-name <database-name> --endpoint <cloud_project_endpoint>
and redeploy the commit.