Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
pull_request:
push:
branches:
- main
- master
workflow_dispatch:

permissions:
contents: read

jobs:
build:
name: Build (Node 20)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Install dependencies
run: npm ci

- name: Build app
run: npm run build
111 changes: 111 additions & 0 deletions .github/workflows/deploy-vercel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Deploy to Vercel

on:
pull_request:
push:
branches:
- main
- master
workflow_dispatch:

permissions:
contents: read

concurrency:
group: vercel-${{ github.ref }}
cancel-in-progress: true

env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

jobs:
preview:
name: Vercel Preview
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate required secrets
shell: bash
run: |
if [ -z "${{ secrets.VERCEL_TOKEN }}" ] || [ -z "${{ secrets.VERCEL_ORG_ID }}" ] || [ -z "${{ secrets.VERCEL_PROJECT_ID }}" ]; then
echo "Missing required secrets: VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID"
exit 1
fi

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

- name: Install dependencies
run: npm ci

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel project settings (preview)
run: vercel pull --yes --environment=preview --token="${{ secrets.VERCEL_TOKEN }}"

- name: Build with Vercel
run: vercel build --token="${{ secrets.VERCEL_TOKEN }}"

- name: Deploy preview
id: deploy_preview
run: |
url="$(vercel deploy --prebuilt --token="${{ secrets.VERCEL_TOKEN }}")"
echo "url=$url" >> "$GITHUB_OUTPUT"

- name: Write preview URL to summary
run: |
echo "Preview URL: ${{ steps.deploy_preview.outputs.url }}" >> "$GITHUB_STEP_SUMMARY"

production:
name: Vercel Production
if: github.event_name != 'pull_request' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Validate required secrets
shell: bash
run: |
if [ -z "${{ secrets.VERCEL_TOKEN }}" ] || [ -z "${{ secrets.VERCEL_ORG_ID }}" ] || [ -z "${{ secrets.VERCEL_PROJECT_ID }}" ]; then
echo "Missing required secrets: VERCEL_TOKEN, VERCEL_ORG_ID, VERCEL_PROJECT_ID"
exit 1
fi

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

- name: Install dependencies
run: npm ci

- name: Install Vercel CLI
run: npm install --global vercel@latest

- name: Pull Vercel project settings (production)
run: vercel pull --yes --environment=production --token="${{ secrets.VERCEL_TOKEN }}"

- name: Build with Vercel
run: vercel build --prod --token="${{ secrets.VERCEL_TOKEN }}"

- name: Deploy production
id: deploy_prod
run: |
url="$(vercel deploy --prebuilt --prod --token="${{ secrets.VERCEL_TOKEN }}")"
echo "url=$url" >> "$GITHUB_OUTPUT"

- name: Write production URL to summary
run: |
echo "Production URL: ${{ steps.deploy_prod.outputs.url }}" >> "$GITHUB_STEP_SUMMARY"
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## 🎯 The Problem

Every year, households waste **40% of purchased food**, contributing to 8-10% of global greenhouse gas emissions. If food waste were a country, it would be the third-largest emitter of greenhouse gases globally.
Every year, households waste **40% of purchased food**, contributing to 8-10% of global greenhouse gas emissions. If food waste were a country, it would be the third-largest emitter of greenhouse gases globally..

## 💡 Our Solution

Expand Down Expand Up @@ -61,6 +61,34 @@ npm run dev

The app will open at [http://localhost:5173](http://localhost:5173)

## ⚙️ CI/CD (GitHub Actions)

This repository now includes:

- **CI**: `.github/workflows/ci.yml`
- Runs on `push` and `pull_request`
- Installs dependencies and builds the app
- **CD Vercel**: `.github/workflows/deploy-vercel.yml`
- Preview deploys on Pull Requests
- Production deploy on the default branch (`main` or `master`)

### Vercel setup

Add these repository secrets in GitHub (`Settings > Secrets and variables > Actions`):

- `VERCEL_TOKEN`
- `VERCEL_ORG_ID`
- `VERCEL_PROJECT_ID`

How to get IDs quickly:

```bash
npx vercel link
cat .vercel/project.json
```

Then push to trigger deployment.

## 🛠️ Built With

- **React** - Frontend framework
Expand Down
Loading