-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (143 loc) · 5.31 KB
/
Copy pathdeploy.yml
File metadata and controls
162 lines (143 loc) · 5.31 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: Deploy to HuggingFace Spaces
on:
push:
branches: [main]
workflow_dispatch:
inputs:
force_all:
description: 'Deploy all apps'
type: boolean
default: false
jobs:
detect-changes:
runs-on: ubuntu-latest
outputs:
dashboard: ${{ steps.changes.outputs.dashboard }}
analytics: ${{ steps.changes.outputs.analytics }}
shared: ${{ steps.changes.outputs.shared }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Detect changes
id: changes
run: |
if [ "${{ github.event.inputs.force_all }}" == "true" ]; then
echo "dashboard=true" >> $GITHUB_OUTPUT
echo "analytics=true" >> $GITHUB_OUTPUT
echo "shared=false" >> $GITHUB_OUTPUT
exit 0
fi
CHANGED=$(git diff --name-only HEAD~1 HEAD 2>/dev/null || echo "")
# Check shared code changes
if echo "$CHANGED" | grep -qE "^(apps/shared/|config/|requirements\.txt)"; then
echo "shared=true" >> $GITHUB_OUTPUT
echo "dashboard=true" >> $GITHUB_OUTPUT
echo "analytics=true" >> $GITHUB_OUTPUT
else
echo "shared=false" >> $GITHUB_OUTPUT
echo "dashboard=$(echo "$CHANGED" | grep -q "^apps/dashboard/" && echo true || echo false)" >> $GITHUB_OUTPUT
echo "analytics=$(echo "$CHANGED" | grep -q "^apps/analytics/" && echo true || echo false)" >> $GITHUB_OUTPUT
fi
deploy-dashboard:
needs: detect-changes
if: needs.detect-changes.outputs.dashboard == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Create HF Space if needed
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
pip install huggingface_hub
python -c "
from huggingface_hub import HfApi
api = HfApi()
try:
api.create_repo('lyzr-ai/dashboard', repo_type='space', space_sdk='gradio', exist_ok=True)
print('Space ready: lyzr-ai/dashboard')
except Exception as e:
print(f'Space creation note: {e}')
"
- name: Deploy dashboard
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
TEMP=$(mktemp -d)
# Copy app + shared + config
cp -r apps/dashboard/* $TEMP/
cp -r apps/shared $TEMP/
mkdir -p $TEMP/config && cp -r config/* $TEMP/config/
cp requirements.txt $TEMP/requirements_root.txt
sed -i 's|-r ../../requirements.txt|-r requirements_root.txt|g' $TEMP/requirements.txt
# Push to HF Space
cd $TEMP
git init -b main
git config user.email "action@github.com"
git config user.name "GitHub Action"
git add .
git commit -m "Deploy dashboard from ${{ github.sha }}"
git push --force https://lyzr-ai:$HF_TOKEN@huggingface.co/spaces/lyzr-ai/dashboard main
- name: Summary
run: |
echo "## Dashboard Deployed" >> $GITHUB_STEP_SUMMARY
echo "- HF Space: https://huggingface.co/spaces/lyzr-ai/dashboard" >> $GITHUB_STEP_SUMMARY
echo "- URL: https://dashboard.lyzr.space" >> $GITHUB_STEP_SUMMARY
deploy-analytics:
needs: detect-changes
if: needs.detect-changes.outputs.analytics == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Create HF Space if needed
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
pip install huggingface_hub
python -c "
from huggingface_hub import HfApi
api = HfApi()
try:
api.create_repo('lyzr-ai/analytics', repo_type='space', space_sdk='gradio', exist_ok=True)
print('Space ready: lyzr-ai/analytics')
except Exception as e:
print(f'Space creation note: {e}')
"
- name: Deploy analytics
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
run: |
TEMP=$(mktemp -d)
# Copy app + shared + config
cp -r apps/analytics/* $TEMP/
cp -r apps/shared $TEMP/
mkdir -p $TEMP/config && cp -r config/* $TEMP/config/
cp requirements.txt $TEMP/requirements_root.txt
sed -i 's|-r ../../requirements.txt|-r requirements_root.txt|g' $TEMP/requirements.txt
# Push to HF Space
cd $TEMP
git init -b main
git config user.email "action@github.com"
git config user.name "GitHub Action"
git add .
git commit -m "Deploy analytics from ${{ github.sha }}"
git push --force https://lyzr-ai:$HF_TOKEN@huggingface.co/spaces/lyzr-ai/analytics main
- name: Summary
run: |
echo "## Analytics Deployed" >> $GITHUB_STEP_SUMMARY
echo "- HF Space: https://huggingface.co/spaces/lyzr-ai/analytics" >> $GITHUB_STEP_SUMMARY
echo "- URL: https://analytics.lyzr.space" >> $GITHUB_STEP_SUMMARY