references/ci/github-actions.md
references/ci/github-actions.mdBrowse 26 files
4,284 bytes
Token encoding: o200k_base
Snapshot 064d74a
GitHub Actions
Complete setup guide for Turborepo with GitHub Actions.
Basic Workflow Structure
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Build and Test
run: turbo run build test lint
Package Manager Setup
pnpm
- uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install --frozen-lockfile
Yarn
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"
- run: yarn install --frozen-lockfile
Bun
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun install --frozen-lockfile
Remote Cache Setup
There are two ways to authenticate to Vercel Remote Cache from GitHub Actions:
- OpenID Connect (OIDC): configure a policy that allows exchanging the CI/CD provider's OIDC tokens for short-lived Turborepo access tokens that grant access to Remote Cache (recommended).
- Personal Access Token (PAT): configure a long-lived, team-scoped PAT as a secret in your CI/CD provider (use when OIDC is not an option).
For the full setup, see Use Remote Caching from external CI/CD. The GitHub Actions workflow configuration is shown below.
Option A: OpenID Connect (recommended)
Follow these instructions to create an OIDC policy on your Vercel team and configure your TURBO_TEAM variable. Then add vercel/setup-turborepo-remote-cache-action before any step that runs turbo. It requests a GitHub OIDC token, exchanges it for a short-lived Turborepo access token, and sets TURBO_TOKEN and TURBO_TEAM environment variables for later steps that run turbo:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: vercel/setup-turborepo-remote-cache-action@v1.1.0
with:
team: ${{ vars.TURBO_TEAM }}
Option B: Personal Access Token
Follow these instructions to create a Personal Access Token, configure your TURBO_TOKEN secret, and configure your TURBO_TEAM variable. Then provide them to jobs that run turbo:
jobs:
build:
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
Alternative: actions/cache
If you can't use remote cache, cache Turborepo's local cache directory:
- uses: actions/cache@v4
with:
path: .turbo
key: turbo-${{ runner.os }}-${{ hashFiles('**/turbo.json', '**/package-lock.json') }}
restore-keys: |
turbo-${{ runner.os }}-
Note: This is less effective than remote cache since it's per-branch.
Complete Example
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- uses: pnpm/action-setup@v3
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- uses: vercel/setup-turborepo-remote-cache-action@v1.1.0
with:
team: ${{ vars.TURBO_TEAM }}
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: turbo run build --affected
- name: Test
run: turbo run test --affected
- name: Lint
run: turbo run lint --affectedReferenced from SKILL.md
Source excerpt starting at line 164.SKILL.mdView in source ↗164CI setup?165├─ GitHub Actions → references/ci/github-actions.md166├─ Vercel deployment → references/ci/vercel.md
Source excerpt starting at line 913.913| [ci/RULE.md](./references/ci/RULE.md) | General CI principles |914| [ci/github-actions.md](./references/ci/github-actions.md) | Complete GitHub Actions setup |915| [ci/vercel.md](./references/ci/vercel.md) | Vercel deployment, turbo-ignore |