Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add GitHub Actions recipe #930

Merged
merged 4 commits into from
Mar 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
107 changes: 107 additions & 0 deletions docs/pages/docs/guides/continuous-integration.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: Continuous Integration
description: Recipes for using Turborepo with GitHub Actions, CircleCI, and other continuous integration providers.
---

# Continuous Integration

Turborepo not only speeds up builds, but also your CI pipeline. Below are a few ways to use Turborepo with various Continuous Integration providers.

## GitHub Actions

The following example shows how to use Turborepo with GitHub Actions and pnpm.

```yaml
name: CI

on:
push:
branches: ["main"]
pull_request:
types: [opened, synchronize]

build:
name: Build and Test
timeout-minutes: 15
runs-on: ${{ matrix.os }}
# To use Remote Caching, uncomment the next lines and follow the steps below.
# env:
# TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
# TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2

- uses: pnpm/action-setup@v2.0.1
with:
version: 6.32.2

- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: 16
cache: pnpm

- name: Install dependencies
run: pnpm install

- name: Test
run: pnpm turbo run test
```

#### Remote Caching

To use Remote Caching with GitHub Actions, add the following environment variables to your GitHub Actions workflow
and make them available to your `turbo` commands.

- `TURBO_TOKEN` - The Bearer token to access the Remote Cache
- `TURBO_TEAM` - The team to which the monorepo belongs

To use Vercel Remote Caching, you can get the value of these variables in a few steps:

1. Create a Scoped Access Token to your account in the [Vercel Dashboard](https://vercel.com/account/tokens)

![Vercel Access Tokens](/images/docs/vercel-tokens.png)

![Vercel Access Tokens](/images/docs/vercel-create-token.png)

Copy the value to a safe place. You'll need it in a moment.

2. Go to your GitHub repository settings and click on the **Secrets** and then **Actions** tab.
Create a new secret called `TURBO_TOKEN` and enter the value of your Scoped Access Token.

![GitHub Secrets](/images/docs/github-actions-secrets.png)
![GitHub Secrets Create](/images/docs/github-actions-create-secret.png)

3. Make a second secret called `TURBO_TEAM` and enter the value of your Vercel team's URL. Do not include `https://vercel.com` part, but only the slug.

![Vercel Team Slug](/images/docs/vercel-slug.png)

4. At the top of your GitHub Actions workflow, provide the following environment variables to jobs that use `turbo`:

```yaml highlight="6-8"
build:
name: Build and Test
timeout-minutes: 15
runs-on: ${{ matrix.os }}
# To use Turborepo Remote Caching, set the following environment variables for the job.
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]

steps:
- name: Check out code
uses: actions/checkout@v2
with:
fetch-depth: 2
# ...
```
6 changes: 1 addition & 5 deletions docs/pages/docs/guides/meta.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"pipelines": "Pipelines",
"caching": "Caching",
"scopes": "Scoped Tasks",
"guides": "Guides",
"continuous-integration": "Continuous Integration",
"migrate-from-lerna": "Migrate from Lerna",
"remote-caching": "Remote Caching (Beta)",
"monorepo-tools": "Complementary Tools"
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/images/docs/vercel-create-token.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/images/docs/vercel-slug.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/images/docs/vercel-tokens.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.