CI pipline
// folder structure
rootDirectory
| -.git
|- .github/workflow/buld.yml //write here that pipeline code
|- .gitignore
//๐pipeline code
// adjust you dir accordingly. in this ci pipline code the folder structure is like this
dataanalyst
|- .git
| frontend /
| |-src /
│ ├── package.json
│ ├── vite.config.js
│ └── ...
│ ├── vite.config.js
│ └── ...
| -.gitignore
|- .github/workflow/build.yml
```
name: React (Vite) CI/CD
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1️⃣ Checkout repo
- name: Checkout repository
uses: actions/checkout@v4
# 2️⃣ Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
# 3️⃣ Install dependencies (inside frontend)
- name: Install dependencies
working-directory: ./frontend
run: npm ci
# 4️⃣ Run ESLint (optional but recommended)
- name: Run ESLint
working-directory: ./frontend
run: npm run lint
# 5️⃣ Build Vite React app
- name: Build project
working-directory: ./frontend
run: npm run build
# 6️⃣ Deploy (example: GitHub Pages)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./frontend/dist
```
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
# 1️⃣ Checkout repo
- name: Checkout repository
uses: actions/checkout@v4
# 2️⃣ Setup Node.js
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
# 3️⃣ Install dependencies (inside frontend)
- name: Install dependencies
working-directory: ./frontend
run: npm ci
# 4️⃣ Run ESLint (optional but recommended)
- name: Run ESLint
working-directory: ./frontend
run: npm run lint
# 5️⃣ Build Vite React app
- name: Build project
working-directory: ./frontend
run: npm run build
# 6️⃣ Deploy (example: GitHub Pages)
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./frontend/dist
```
Comments