chore: exclude maintainer doc/ from the published package (#429) #121
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | |
| 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" |