|
| 1 | +--- |
| 2 | +title: "GitHub integration" |
| 3 | +description: "Automatically deploy your tasks on every push to your GitHub repository." |
| 4 | +--- |
| 5 | + |
| 6 | +## How it works |
| 7 | + |
| 8 | +Once you connect a GitHub repository to your project, you can configure tracking branches for the production and staging environments. |
| 9 | +Every push to a tracked branch creates a deployment in the corresponding environment. Preview branch deployments are also supported for pull requests. |
| 10 | + |
| 11 | +This eliminates the need to manually run the `trigger.dev deploy` command or set up custom CI/CD workflows. |
| 12 | + |
| 13 | +## Setup |
| 14 | + |
| 15 | +<Steps> |
| 16 | + |
| 17 | +<Step title="Install our GitHub app"> |
| 18 | + Go to your project's settings page and click `Install GitHub app`. |
| 19 | + This will take you to GitHub to authorize the Trigger.dev app for your organization or personal account. |
| 20 | +</Step> |
| 21 | + |
| 22 | +<Step title="Connect your repository"> |
| 23 | + Select a repository to connect to your project. |
| 24 | +</Step> |
| 25 | + |
| 26 | +<Step title="Configure branch tracking"> |
| 27 | + Choose which branches should trigger automatic deployments: |
| 28 | + |
| 29 | + - **Production**: The branch that deploys to your production environment, e.g., `main`. |
| 30 | + - **Staging**: The branch that deploys to your staging environment. |
| 31 | + - **Preview**: Toggle to enable preview deployments for pull requests |
| 32 | +</Step> |
| 33 | + |
| 34 | +<Step title="Customize build settings (optional)"> |
| 35 | + Configure how your project is built: |
| 36 | + |
| 37 | + - **Trigger config file**: Path to your `trigger.config.ts` file. By default, we look for it in the root of your repository. The path should be relative to the root of your repository and contain the config file name, e.g., `apps/tasks/trigger.config.ts`. |
| 38 | + - **Install command**: Auto-detected by default, but you can override it if necessary. The command will be run from the root of your repository. |
| 39 | + - **Pre-build command**: Run any commands before building and deploying your project, e.g., `pnpm run prisma:generate`. The command will be run from the root of your repository. |
| 40 | +</Step> |
| 41 | + |
| 42 | +</Steps> |
| 43 | + |
| 44 | +## Branch tracking |
| 45 | + |
| 46 | +Our GitHub integration uses branch tracking to determine when and where to deploy your code. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +### Production and staging branches |
| 51 | + |
| 52 | +When you connect a repository, the default branch of your repository will be used as the production tracking branch, by default. |
| 53 | + |
| 54 | +When you configure a production or staging branch, every push to that branch will trigger a deployment. |
| 55 | +Our build server will install the project dependencies, build your project, and deploy it to the corresponding environment. |
| 56 | + |
| 57 | +If there are multiple consecutive pushes to a tracked branch, the later deployments will be queued until the previous deployment completes. |
| 58 | + |
| 59 | +<Note> |
| 60 | + When you connect a repository, the default branch of your repository will be used as the production tracking branch by default. |
| 61 | + You can change this in the git settings of your project. |
| 62 | +</Note> |
| 63 | + |
| 64 | +### Pull requests |
| 65 | + |
| 66 | +By default, pull requests will be deployed to preview branch environments, enabling you to test changes before merging. |
| 67 | +When the pull request is merged or closed, the preview branch is automatically archived. |
| 68 | + |
| 69 | +The name of the preview branch matches the branch name of the pull request. |
| 70 | + |
| 71 | +<Note> |
| 72 | + Preview branch deployments require the preview environment to be enabled on your project. Learn more about [preview branches](/deployment/preview-branches). |
| 73 | +</Note> |
| 74 | + |
| 75 | +## Disconnecting a repository |
| 76 | + |
| 77 | +You can disconnect a repository at any time from your project git settings. This will stop automatic deployments triggered from GitHub. |
| 78 | + |
| 79 | +## Managing repository access |
| 80 | + |
| 81 | +To add or remove repository access for the Trigger.dev GitHub app, follow the link in the `Connect GitHub repository` modal: |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +Alternatively, you can follow these steps on GitHub: |
| 86 | + |
| 87 | +1. Go to your GitHub account settings |
| 88 | +2. Navigate to **Settings** → **Applications** → **Installed GitHub Apps** |
| 89 | +3. Click **Configure** next to `Trigger.dev App` |
| 90 | +4. Update repository access under `Repository access` |
| 91 | + |
| 92 | +Changes to repository access will be reflected immediately in your Trigger.dev project settings. |
| 93 | + |
| 94 | +## Environment variables at build time |
| 95 | + |
| 96 | +You can expose environment variables during the build and deployment process by prefixing them with `TRIGGER_BUILD_`. |
| 97 | +Build extensions will also have access to these variables. |
| 98 | + |
| 99 | +Build environment variables only apply to deployments in the environment you set them in. |
| 100 | + |
| 101 | +Learn more about managing [environment variables](/deploy-environment-variables). |
| 102 | + |
| 103 | +## Using a private npm registry |
| 104 | + |
| 105 | +If your project uses packages from a private npm registry, you can provide authentication by setting a `TRIGGER_BUILD_NPM_RC` environment variable. |
| 106 | + |
| 107 | +The value should be the contents of your `.npmrc` file including any token credentials, encoded to base64. |
| 108 | + |
| 109 | +### Example |
| 110 | + |
| 111 | +Example `.npmrc` file containing credentials for a private npm registry and a GitHub package registry: |
| 112 | + |
| 113 | +``` |
| 114 | +//registry.npmjs.org/:_authToken=<YOUR_NPM_TOKEN> |
| 115 | +@<YOUR_NAMESPACE>:registry=https://npm.pkg.github.com |
| 116 | +//npm.pkg.github.com/:always-auth=true |
| 117 | +//npm.pkg.github.com/:_authToken=<YOUR_GITHUB_TOKEN> |
| 118 | +``` |
| 119 | + |
| 120 | +Encode it to base64: |
| 121 | + |
| 122 | +```bash |
| 123 | +# Encode your .npmrc file |
| 124 | +cat .npmrc | base64 |
| 125 | +``` |
| 126 | + |
| 127 | +Then, set the `TRIGGER_BUILD_NPM_RC` environment variable in your project settings with the encoded value. |
| 128 | + |
| 129 | +<Note> |
| 130 | + The build server will automatically create a `.npmrc` file in the installation directory based on the content of the `TRIGGER_BUILD_NPM_RC` environment variable. |
| 131 | + This enables the build server to authenticate to your private npm registry. |
| 132 | +</Note> |
0 commit comments