-
Notifications
You must be signed in to change notification settings - Fork 27
146 lines (124 loc) · 4.44 KB
/
Copy pathchat_app_hf_static_deploy.yml
File metadata and controls
146 lines (124 loc) · 4.44 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
name: Chat App HF Static Deploy
on:
push:
branches: [main]
paths:
- "example/chat_app/**"
- "lib/**"
- "pubspec.yaml"
- "pubspec.lock"
- "scripts/build_chat_app_web.sh"
- "scripts/fetch_webgpu_bridge_assets.sh"
- "scripts/validate_chat_app_web_build.sh"
- "scripts/verify_chat_app_web_deployment.sh"
- ".github/workflows/chat_app_hf_static_deploy.yml"
workflow_dispatch:
inputs:
space_repo:
description: "Hugging Face Space repo (owner/space), optional override"
required: false
deploy_ref:
description: "Git ref to deploy (optional)"
required: false
permissions:
contents: read
concurrency:
group: chat-app-hf-static-deploy
cancel-in-progress: true
jobs:
deploy:
name: Build and deploy chat app
runs-on: ubuntu-latest
timeout-minutes: 45
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_CHAT_APP_SPACE_REPO: ${{ vars.HF_CHAT_APP_SPACE_REPO }}
INPUT_SPACE_REPO: ${{ github.event.inputs.space_repo }}
steps:
- uses: actions/checkout@v6
with:
ref: ${{ github.event.inputs.deploy_ref || github.ref }}
- name: Record deployment source commit
run: echo "DEPLOY_SHA=$(git rev-parse HEAD)" >> "$GITHUB_ENV"
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.47.1
channel: stable
cache: true
- name: Resolve Hugging Face target
id: target
run: |
SPACE_REPO="$INPUT_SPACE_REPO"
if [ -z "$SPACE_REPO" ]; then
SPACE_REPO="$HF_CHAT_APP_SPACE_REPO"
fi
if [ -z "$SPACE_REPO" ]; then
echo "error: set HF_CHAT_APP_SPACE_REPO repo variable or provide workflow input 'space_repo'"
exit 1
fi
if [ -z "$HF_TOKEN" ]; then
echo "error: set HF_TOKEN repository secret with write access to the Space"
exit 1
fi
APP_HOST="$(printf '%s' "$SPACE_REPO" | tr '[:upper:]/' '[:lower:]-')"
echo "space_repo=$SPACE_REPO" >> "$GITHUB_OUTPUT"
echo "app_url=https://${APP_HOST}.static.hf.space" >> "$GITHUB_OUTPUT"
- name: Install dependencies
run: |
(cd example/chat_app && flutter pub get)
- name: Build and validate chat app web
run: CHAT_APP_BUILD_SHA="$DEPLOY_SHA" ./scripts/build_chat_app_web.sh
- name: Install Hugging Face Hub client
run: |
python3 -m pip install --upgrade "huggingface_hub>=0.36.0,<0.37.0"
- name: Deploy to Hugging Face Space
env:
SPACE_REPO: ${{ steps.target.outputs.space_repo }}
run: |
rm -rf hf-space-sync
mkdir -p hf-space-sync
rsync -a --delete \
"example/chat_app/build/web/" "hf-space-sync/"
{
printf '%s\n' '---'
printf '%s\n' 'title: llamadart chat app'
printf '%s\n' 'sdk: static'
printf '%s\n' 'app_file: index.html'
printf '%s\n' 'custom_headers:'
printf '%s\n' ' cross-origin-embedder-policy: require-corp'
printf '%s\n' ' cross-origin-opener-policy: same-origin'
printf '%s\n' ' cross-origin-resource-policy: cross-origin'
printf '%s\n' '---'
printf '%s\n' ''
printf '%s\n' 'llamadart chat app static deployment.'
} > "hf-space-sync/README.md"
SHORT_SHA="$(printf '%s' "$DEPLOY_SHA" | cut -c1-7)"
export SHORT_SHA
python3 - <<'PY'
import os
from huggingface_hub import HfApi
api = HfApi(token=os.environ["HF_TOKEN"])
space_repo = os.environ["SPACE_REPO"]
short_sha = os.environ["SHORT_SHA"]
api.create_repo(
repo_id=space_repo,
repo_type="space",
space_sdk="static",
exist_ok=True,
)
api.upload_folder(
repo_id=space_repo,
repo_type="space",
folder_path="hf-space-sync",
revision="main",
commit_message=f"chore: deploy chat app {short_sha}",
delete_patterns=["*", "**/*"],
)
PY
- name: Verify deployed production artifact
env:
APP_URL: ${{ steps.target.outputs.app_url }}
run: |
./scripts/verify_chat_app_web_deployment.sh \
"$APP_URL" "$DEPLOY_SHA"