-
Notifications
You must be signed in to change notification settings - Fork 41
127 lines (108 loc) · 3.52 KB
/
Copy pathci.yml
File metadata and controls
127 lines (108 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
name: CI
on:
pull_request:
branches: [main]
push:
branches: [main]
jobs:
frontend-lint:
name: Frontend Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Run ESLint
run: npm run lint
frontend-build:
name: Frontend Build
runs-on: ubuntu-latest
needs: frontend-lint
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20
cache: npm
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
env:
VITE_API_URL: https://karansingh12-freshscan-api.hf.space
VITE_DEV_MODE: false
backend-lint-and-test:
name: Backend Lint and Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
steps:
- uses: actions/checkout@v6
- uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: pip install -r requirements-ci.txt
- name: Lint with Ruff
run: ruff check . --config ruff.toml
- name: Run tests
run: python -m pytest tests/test_ci.py -v
env:
DEV_BYPASS_AUTH: "false"
DEV_BYPASS_TOKEN: ci-test-token
SUPABASE_URL: ""
SUPABASE_KEY: ""
SUPABASE_SERVICE_KEY: ""
FRONTEND_URL: http://localhost:5173
API_BASE_URL: http://localhost:8000
check-backend-changes:
name: Check Backend Changes
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
outputs:
backend: ${{ steps.filter.outputs.backend }}
steps:
- uses: actions/checkout@v6
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
backend:
- 'backend/**'
deploy-backend-to-hf-spaces:
name: Deploy Backend → HF Spaces
# Only deploy on push to main if backend files changed
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.check-backend-changes.outputs.backend == 'true'
needs: [backend-lint-and-test, check-backend-changes]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # full history needed for subtree push
lfs: true
- name: Configure git
run: |
git config user.email "ci@freshscan.ai"
git config user.name "FreshScan CI"
- name: Push backend/ → HF Spaces
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
# Check if HF_TOKEN is set
if [ -z "${HF_TOKEN}" ]; then
echo "ERROR: HF_TOKEN secret is missing!"
echo "Please add your Hugging Face Access Token as a Repository Secret named 'HF_TOKEN' in GitHub."
exit 1
fi
# Since HF Spaces might have auto-generated files (like README.md)
# that aren't in this repo, a normal push gets rejected.
# We need to split the backend directory into its own commit history
# and FORCE push it to HF Spaces, making GitHub the single source of truth.
COMMIT_HASH=$(git subtree split --prefix backend main)
git push https://karansingh12:${HF_TOKEN}@huggingface.co/spaces/karansingh12/freshscan-api ${COMMIT_HASH}:main --force