Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/PR_PREVIEW_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# PR Preview Setup Guide

This repository includes workflows for deploying PR previews to either Netlify or Vercel. Choose one and follow the setup instructions below.

## Option 1: Netlify (Recommended)

Netlify offers a generous free tier and is easy to set up.

### Setup Steps:

1. **Create a Netlify account** at https://netlify.com

2. **Create a new site**:
- Go to your Netlify dashboard
- Click "Add new site" → "Configure manually"
- Note the Site ID

3. **Get your auth token**:
- Go to User Settings → Applications → Personal Access Tokens
- Create a new token and save it

4. **Add GitHub Secrets**:
- Go to your GitHub repository settings
- Navigate to Secrets and Variables → Actions
- Add these secrets:
- `NETLIFY_AUTH_TOKEN`: Your personal access token
- `NETLIFY_SITE_ID`: Your site ID

5. **Enable the workflow**:
- Keep `pr-preview-netlify.yml`
- Delete `pr-preview-vercel.yml` if not using Vercel

## Option 2: Vercel

Vercel is also free for open source projects and offers excellent performance.

### Setup Steps:

1. **Create a Vercel account** at https://vercel.com

2. **Install Vercel CLI** locally:
```bash
npm i -g vercel
```

3. **Link your project**:
```bash
vercel link
```
This will create a `.vercel` folder with your project settings

4. **Get your tokens**:
- Create a token at: https://vercel.com/account/tokens
- Get your Org ID and Project ID from `.vercel/project.json`

5. **Add GitHub Secrets**:
- Go to your GitHub repository settings
- Navigate to Secrets and Variables → Actions
- Add these secrets:
- `VERCEL_TOKEN`: Your access token
- `VERCEL_ORG_ID`: Your organization ID
- `VERCEL_PROJECT_ID`: Your project ID

6. **Enable the workflow**:
- Keep `pr-preview-vercel.yml`
- Delete `pr-preview-netlify.yml` if not using Netlify

## Security Benefits

Using Netlify or Vercel for PR previews instead of GitHub Pages provides:

- **Isolation**: PR previews are completely separate from your production site
- **No write access**: PRs cannot modify your main GitHub Pages deployment
- **Automatic cleanup**: Previews are automatically removed after PRs are merged
- **Access control**: You can add password protection if needed (paid feature)

## Choosing Between Services

| Feature | Netlify | Vercel |
|---------|---------|--------|
| Free tier | 100GB bandwidth/month | 100GB bandwidth/month |
| Build minutes | 300 min/month | 6000 min/month |
| Setup complexity | Simple | Moderate |
| Preview URLs | Custom aliases | Automatic unique URLs |
| Comments on PR | ✅ Automatic | ✅ Automatic |

Both services work great for PR previews. Choose based on your preference and existing infrastructure.
20 changes: 12 additions & 8 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ jobs:
steps:
- uses: actions/checkout@v4

# Install dependencies
- name: Set up Python 3.11
uses: actions/setup-python@v5
# Install uv for faster dependency management
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.11'
cache: pip # Implicitly uses requirements.txt for cache key
enable-cache: true

# Set up Python using uv
- name: Set up Python
run: uv python install 3.11

# Install dependencies using uv
- name: Install dependencies
run: pip install -r requirements.txt
run: uv sync

# (optional) Cache your executed notebooks between runs
# if you have config:
Expand All @@ -41,12 +45,12 @@ jobs:
uses: actions/cache@v4
with:
path: _build/.jupyter_cache
key: jupyter-book-cache-${{ hashFiles('requirements.txt') }}
key: jupyter-book-cache-${{ hashFiles('uv.lock') }}

# Build the book
- name: Build the book
run: |
jupyter-book build .
uv run jupyter-book build .

# Upload the book's HTML as an artifact
- name: Upload artifact
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/pr-preview-netlify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Deploy PR Preview to Netlify

on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build-and-deploy:
runs-on: ubuntu-latest
permissions:
pull-requests: write # To comment on the PR
steps:
- uses: actions/checkout@v4

# Install uv for faster dependency management
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true

# Set up Python using uv
- name: Set up Python
run: uv python install 3.11

# Install dependencies using uv
- name: Install dependencies
run: uv sync

# Cache executed notebooks between runs
- name: Cache executed notebooks
uses: actions/cache@v4
with:
path: _build/.jupyter_cache
key: jupyter-book-cache-${{ hashFiles('uv.lock') }}

# Build the book
- name: Build the book
run: |
uv run jupyter-book build .

# Deploy to Netlify
- name: Deploy to Netlify
uses: nwtgck/[email protected]
with:
publish-dir: './_build/html'
production-deploy: false
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Deploy PR ${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}"
enable-pull-request-comment: true
enable-commit-comment: false
overwrites-pull-request-comment: true
alias: pr-${{ github.event.pull_request.number }}
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
timeout-minutes: 5
62 changes: 62 additions & 0 deletions .github/workflows/pr-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: PR Preview

# Build the book on pull requests for preview
on:
pull_request:
branches:
- main
- master

jobs:
build-preview:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Install uv for faster dependency management
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true

# Set up Python using uv
- name: Set up Python
run: uv python install 3.11

# Install dependencies using uv
- name: Install dependencies
run: uv sync

# Cache executed notebooks between runs
- name: Cache executed notebooks
uses: actions/cache@v4
with:
path: _build/.jupyter_cache
key: jupyter-book-cache-${{ hashFiles('uv.lock') }}

# Build the book
- name: Build the book
run: |
uv run jupyter-book build .

# Upload the book's HTML as an artifact
- name: Upload book artifact
uses: actions/upload-artifact@v4
with:
name: book-html-${{ github.event.pull_request.number }}
path: "_build/html"
retention-days: 7

# Post comment with artifact link
- name: Comment PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `📚 Book preview build completed! [Download the artifact](${artifactUrl}) to view the HTML locally.`
})
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[project]
name = "xarray-for-biology"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = [
"flox>=0.10.6",
"jupyter-book>=1.0.4.post1",
"jupyterlab>=4.4.7",
"matplotlib>=3.10.6",
"numpy>=2.3.2",
"xarray>=2025.8.0",
]
1 change: 1 addition & 0 deletions test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Testing Netlify
Loading
Loading