Automate branching with GitHub Actions
Create and delete branches with GitHub Actions
Neon provides the following GitHub Actions for working with Neon branches, which you can add to your CI workflows:
tip
Neon supports a GitHub integration that connects your Neon project to a GitHub repository. The integration automatically configures a NEON_API_KEY
secret and PROJECT_ID
variable in your GitHub repository and provides a sample GitHub Actions workflow that utilizes Neon's Create branch and Delete branch actions. See Neon GitHub integration for more.
Create branch action
This GitHub Action creates a new branch in your Neon project.
info
The source code for this action is available on GitHub.
Prerequisites
- Using the action requires a Neon API key. For information about obtaining an API key, see Create an API key.
- Add your Neon API key to your GitHub Secrets:
- In your GitHub repository, go to Project settings and locate Secrets at the bottom of the left sidebar.
- Click Actions > New Repository Secret.
- Name the secret
NEON_API_KEY
and paste your API key in the Secret field - Click Add Secret.
Example
The following example creates a branch based on the specified parent branch:
Input variables
Outputs
Delete branch action
This GitHub Action deletes a branch from your Neon project.
info
The source code for this action is available on GitHub.
Prerequisites
- Using the action requires a Neon API key. For information about obtaining an API key, see Create an API key.
- Add your Neon API key to your GitHub Secrets:
- In your GitHub repository, go to Project settings and locate Secrets at the bottom of the left sidebar.
- Click Actions > New Repository Secret.
- Name the secret
NEON_API_KEY
and paste your API key in the Secret field - Click Add Secret.
Example
The following example deletes a branch with the br-long-forest-224191
branch ID from a Neon project with the project ID rapid-haze-373089
when a pull request is merged.
Input variables
Outputs
This Action has no outputs.
Reset from parent action
This GitHub Action resets a child branch with the latest data from its parent branch.
info
The source code for this action is available on GitHub.
Prerequisites
- Using this action requires a Neon API key. For information about obtaining an API key, see Create an API key.
- Add your Neon API key to your GitHub Secrets:
- In your GitHub repository, go to Project settings and locate Secrets at the bottom of the left sidebar.
- Click Actions > New Repository Secret.
- Name the secret
NEON_API_KEY
and paste your API key in the Secret field. - Click Add Secret.
Example
The following example demonstrates how to reset a branch in your Neon project:
Input variables
project_id
: The ID of your Neon project. Find this value in the Neon Console on the Settings page.parent
: If specified, the branch will be reset to the latest state of the parent branch.branch
: The name or id of the branch to reset.api_key
: An API key created in your Neon account.
The action outputs a connection string. You can modify the connection string with these optional connection string (cs_*
) inputs:
cs_role_name
: The output connection string database role name.cs_database
: The output connection string database name.cs_prisma
: Use Prisma in output connection string or not. The default is 'false'.cs_ssl
: Addsslmode
to the connection string. Supported values are:"require"
,"verify-ca"
,"verify-full"
,"omit"
. The default is"require"
.
Outputs
branch_id
: The ID of the newly reset branch.db_url
: Database connection string for the branch after the reset.db_url_with_pooler
: The pooled database connection string for the branch after the reset.host
: The branch host after the reset.host_with_pooler
: The branch host with pooling after the reset.password
: The password for connecting to the branch database after the reset.
Example applications
The following example applications use GitHub Actions workflows to create and delete branches in Neon.
Preview branches with Cloudflare Pages
Demonstrates using GitHub Actions workflows to create a Neon branch for every Cloudflare Pages preview deployment
Preview branches with Vercel
Demonstrates using GitHub Actions workflows to create a Neon branch for every Vercel preview deployment
Preview branches with Fly.io
Demonstrates using GitHub Actions workflows to create a Neon branch for every Fly.io preview deployment
Neon Twitter app
Demonstrates using GitHub Actions workflows to create a Neon branch for schema validation and perform migrations
Need help?
Join our Discord Server to ask questions or see what others are doing with Neon. Users on paid plans can open a support ticket from the console. For more detail, see Getting Support.