File size: 1,223 Bytes
903c838
 
 
 
 
 
 
 
 
 
 
 
3f70154
 
903c838
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
831a83f
903c838
 
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
#!/bin/bash
# Add safety measures
set -e
set -o pipefail

# Check if all required environment variables are set
if [ -z "$HF_TOKEN" ] || [ -z "$HF_SPACE_NAME" ] || [ -z "$BUILD_COMMAND" ] || [ -z "$OUTPUT_PATH" ]; then
    echo "Missing required environment variables"
    exit 1
fi

# Download the space
# git clone --depth 1 https://:[email protected]/spaces/$HF_SPACE_NAME space
huggingface-cli download $HF_SPACE_NAME --repo-type space --local-dir space --token $HF_TOKEN

# Change directory to the space's directory
cd space

# Determine which package manager to use
if [ -f "package.json" ]; then
    if [ -f "pnpm-lock.yaml" ]; then
        pnpm install
    elif [ -f "yarn.lock" ]; then
        yarn install
    else
        npm install
    fi
else
    echo "No package.json found. Assuming no package manager is needed."
fi

echo "Running the build command: $BUILD_COMMAND"

# Run the build command
eval $BUILD_COMMAND

echo "Build completed successfully, uploading the build output..."

# Upload the build output to the Hugging Face space
huggingface-cli upload $HF_SPACE_NAME $OUTPUT_PATH / --repo-type space --revision refs/convert/build --token $HF_TOKEN

echo "Build and upload completed successfully."