Skip to content

Commit

Permalink
Add example of Turborepo, Vercel CLI, and GitHub Actions. (#940)
Browse files Browse the repository at this point in the history
### Description

# GitHub Actions + Turborepo + Vercel CLI

This demo is based on the [Turborepo
starter](https://github.com/vercel/turbo/tree/main/examples/basic).

It uses a GitHub Actions workflow to build and deploy the `docs`
application.

Additionally, a `foo` internal package has been added to demonstrate how
to use the `turbo` CLI to build internal dependencies prior to building
the `docs` application with the Vercel CLI.

### Type of Change

- [x] New Example
- [ ] Example updates (Bug fixes, new features, etc.)
- [ ] Other (changes to the codebase, but not to examples)
  • Loading branch information
anthonyshew authored Jul 25, 2024
1 parent 000376c commit 3884856
Show file tree
Hide file tree
Showing 66 changed files with 7,308 additions and 0 deletions.
54 changes: 54 additions & 0 deletions ci-cd/with-github-actions/.github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
# For Remote Caching
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

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

jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest

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

- uses: pnpm/action-setup@v3
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Globally install Turborepo
run: pnpm install -g turbo@^2

- name: Build
run: |
# Builds the dependencies of the docs target
# https://turbo.build/repo/docs/reference/run#microsyntaxes-for-filtering
# We need to do this since `vc build` does not currently
# follow the package or task graph (like Turborepo can).
turbo build --filter=docs^...
# Pull environment info
vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy
run: |
vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
53 changes: 53 additions & 0 deletions ci-cd/with-github-actions/.github/workflows/production.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
# For Remote Caching
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}

on:
push:
branches: ["main"]

jobs:
build:
name: Build and Deploy
runs-on: ubuntu-latest

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

- uses: pnpm/action-setup@v3
with:
version: 8

- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install

- name: Globally install Turborepo
run: pnpm install -g turbo@^2

- name: Build
run: |
# Builds the dependencies of the docs target
# https://turbo.build/repo/docs/reference/run#microsyntaxes-for-filtering
# We need to do this since `vc build` does not currently
# follow the package or task graph (like Turborepo can).
turbo build --filter=docs^...
# Pull environment info
vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
- name: Deploy
run: |
vercel deploy --prod --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
39 changes: 39 additions & 0 deletions ci-cd/with-github-actions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# Dependencies
node_modules
.pnp
.pnp.js

# Local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# Testing
coverage

# Turbo
.turbo

# Vercel
.vercel

# Build Outputs
.next/
out/
build
dist


# Debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Misc
.DS_Store
*.pem
.env*.local
Empty file.
7 changes: 7 additions & 0 deletions ci-cd/with-github-actions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# GitHub Actions + Turborepo + Vercel CLI

This demo is based on the [Turborepo starter](https://github.com/vercel/turbo/tree/main/examples/basic).

It uses a GitHub Actions workflow to build and deploy the `docs` application.

Additionally, a `foo` internal package has been added to demonstrate how to use the `turbo` CLI to build internal dependencies prior to building the `docs` application with the Vercel CLI.
9 changes: 9 additions & 0 deletions ci-cd/with-github-actions/apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["@repo/eslint-config/next.js"],
parser: "@typescript-eslint/parser",
parserOptions: {
project: true,
},
};
36 changes: 36 additions & 0 deletions ci-cd/with-github-actions/apps/docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# env files (can opt-in for commiting if needed)
.env*

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
36 changes: 36 additions & 0 deletions ci-cd/with-github-actions/apps/docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.

This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 39 additions & 0 deletions ci-cd/with-github-actions/apps/docs/app/globals.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
:root {
--background: #ffffff;
--foreground: #171717;
}

@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}

html,
body {
max-width: 100vw;
overflow-x: hidden;
}

body {
color: var(--foreground);
background: var(--background);
}

* {
box-sizing: border-box;
padding: 0;
margin: 0;
}

a {
color: inherit;
text-decoration: none;
}

@media (prefers-color-scheme: dark) {
html {
color-scheme: dark;
}
}
31 changes: 31 additions & 0 deletions ci-cd/with-github-actions/apps/docs/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { Metadata } from "next";
import localFont from "next/font/local";
import "./globals.css";

const geistSans = localFont({
src: "./fonts/GeistVF.woff",
variable: "--font-geist-sans",
});
const geistMono = localFont({
src: "./fonts/GeistMonoVF.woff",
variable: "--font-geist-mono",
});

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
};

export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
return (
<html lang="en">
<body className={`${geistSans.variable} ${geistMono.variable}`}>
{children}
</body>
</html>
);
}
Loading

0 comments on commit 3884856

Please sign in to comment.