|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
| 3 | +# Enable exit on error |
| 4 | +set -e |
| 5 | + |
| 6 | +# Function for logging |
| 7 | +log_error() { |
| 8 | + echo "ERROR: $1" >&2 |
| 9 | +} |
| 10 | + |
| 11 | +log_info() { |
| 12 | + echo "INFO: $1" |
| 13 | +} |
| 14 | + |
3 | 15 | # Get output directory or default to index/whl/cpu
|
4 | 16 | output_dir=${1:-"index/whl/cpu"}
|
5 | 17 |
|
6 |
| -# Create output directory |
7 |
| -mkdir -p $output_dir |
8 |
| - |
9 |
| -# Change to output directory |
10 |
| -pushd $output_dir |
| 18 | +# Get pattern from second arg or default to valid python package version pattern |
| 19 | +pattern=${2:-"^[v]?[0-9]+\.[0-9]+\.[0-9]+$"} |
11 | 20 |
|
12 |
| -# Create an index html file |
13 |
| -echo "<!DOCTYPE html>" > index.html |
14 |
| -echo "<html>" >> index.html |
15 |
| -echo " <head></head>" >> index.html |
16 |
| -echo " <body>" >> index.html |
17 |
| -echo " <a href=\"llama-cpp-python/\">llama-cpp-python</a>" >> index.html |
18 |
| -echo " <br>" >> index.html |
19 |
| -echo " </body>" >> index.html |
20 |
| -echo "</html>" >> index.html |
21 |
| -echo "" >> index.html |
| 21 | +# Get the current directory (where the script is run from) |
| 22 | +current_dir="$(pwd)" |
22 | 23 |
|
23 |
| -# Create llama-cpp-python directory |
24 |
| -mkdir -p llama-cpp-python |
| 24 | +# Check if all_releases.txt exists |
| 25 | +if [ ! -f "$current_dir/all_releases.txt" ]; then |
| 26 | + log_error "all_releases.txt not found in the current directory." |
| 27 | + exit 1 |
| 28 | +fi |
25 | 29 |
|
26 |
| -# Change to llama-cpp-python directory |
27 |
| -pushd llama-cpp-python |
| 30 | +# Create output directory |
| 31 | +mkdir -p "$output_dir" |
28 | 32 |
|
29 | 33 | # Create an index html file
|
30 |
| -echo "<!DOCTYPE html>" > index.html |
31 |
| -echo "<html>" >> index.html |
32 |
| -echo " <body>" >> index.html |
33 |
| -echo " <h1>Links for llama-cpp-python</h1>" >> index.html |
| 34 | +cat << EOF > "$output_dir/index.html" |
| 35 | +<!DOCTYPE html> |
| 36 | +<html> |
| 37 | + <head></head> |
| 38 | + <body> |
| 39 | + <a href="llama-cpp-python/">llama-cpp-python</a> |
| 40 | + <br> |
| 41 | + </body> |
| 42 | +</html> |
34 | 43 |
|
35 |
| -# Get all releases |
36 |
| -releases=$(curl -s https://api.github.com/repos/abetlen/llama-cpp-python/releases | jq -r .[].tag_name) |
| 44 | +EOF |
37 | 45 |
|
38 |
| -# Get pattern from second arg or default to valid python package version pattern |
39 |
| -pattern=${2:-"^[v]?[0-9]+\.[0-9]+\.[0-9]+$"} |
| 46 | +# Create llama-cpp-python directory |
| 47 | +mkdir -p "$output_dir/llama-cpp-python" |
| 48 | + |
| 49 | +# Create an index html file in llama-cpp-python directory |
| 50 | +cat << EOF > "$output_dir/llama-cpp-python/index.html" |
| 51 | +<!DOCTYPE html> |
| 52 | +<html> |
| 53 | + <body> |
| 54 | + <h1>Links for llama-cpp-python</h1> |
| 55 | +EOF |
40 | 56 |
|
41 | 57 | # Filter releases by pattern
|
42 |
| -releases=$(echo $releases | tr ' ' '\n' | grep -E $pattern) |
| 58 | +releases=$(grep -E "$pattern" "$current_dir/all_releases.txt") |
| 59 | + |
| 60 | +# Prepare curl headers |
| 61 | +headers=('--header' 'Accept: application/vnd.github.v3+json') |
| 62 | +if [ -n "$GITHUB_TOKEN" ]; then |
| 63 | + headers+=('--header' "authorization: Bearer $GITHUB_TOKEN") |
| 64 | +fi |
| 65 | +headers+=('--header' 'content-type: application/json') |
43 | 66 |
|
44 | 67 | # For each release, get all assets
|
45 | 68 | for release in $releases; do
|
46 |
| - assets=$(curl -s https://api.github.com/repos/abetlen/llama-cpp-python/releases/tags/$release | jq -r .assets) |
| 69 | + log_info "Processing release: $release" |
| 70 | + response=$(curl -s "${headers[@]}" \ |
| 71 | + "https://api.github.com/repos/abetlen/llama-cpp-python/releases/tags/$release") |
| 72 | + |
| 73 | + if [ -z "$response" ]; then |
| 74 | + log_error "Empty response from GitHub API for release $release" |
| 75 | + continue |
| 76 | + fi |
| 77 | + |
| 78 | + if ! echo "$response" | jq -e '.assets' > /dev/null 2>&1; then |
| 79 | + log_error "Invalid or unexpected response from GitHub API for release $release" |
| 80 | + log_error "Response: $response" |
| 81 | + continue |
| 82 | + fi |
| 83 | + |
47 | 84 | # Get release version from release ie v0.1.0-cu121 -> v0.1.0
|
48 |
| - release_version=$(echo $release | grep -oE "^[v]?[0-9]+\.[0-9]+\.[0-9]+") |
49 |
| - echo " <h2>$release_version</h2>" >> index.html |
50 |
| - for asset in $(echo $assets | jq -r .[].browser_download_url); do |
51 |
| - if [[ $asset == *".whl" ]]; then |
52 |
| - echo " <a href=\"$asset\">$asset</a>" >> index.html |
53 |
| - echo " <br>" >> index.html |
54 |
| - fi |
| 85 | + release_version=$(echo "$release" | grep -oE "^[v]?[0-9]+\.[0-9]+\.[0-9]+") |
| 86 | + echo " <h2>$release_version</h2>" >> "$output_dir/llama-cpp-python/index.html" |
| 87 | + |
| 88 | + wheel_urls=$(echo "$response" | jq -r '.assets[] | select(.name | endswith(".whl")) | .browser_download_url') |
| 89 | + if [ -z "$wheel_urls" ]; then |
| 90 | + log_error "No wheel files found for release $release" |
| 91 | + continue |
| 92 | + fi |
| 93 | + |
| 94 | + echo "$wheel_urls" | while read -r asset; do |
| 95 | + echo " <a href=\"$asset\">$asset</a>" >> "$output_dir/llama-cpp-python/index.html" |
| 96 | + echo " <br>" >> "$output_dir/llama-cpp-python/index.html" |
55 | 97 | done
|
56 | 98 | done
|
57 | 99 |
|
58 |
| -echo " </body>" >> index.html |
59 |
| -echo "</html>" >> index.html |
60 |
| -echo "" >> index.html |
| 100 | +echo " </body>" >> "$output_dir/llama-cpp-python/index.html" |
| 101 | +echo "</html>" >> "$output_dir/llama-cpp-python/index.html" |
| 102 | +echo "" >> "$output_dir/llama-cpp-python/index.html" |
| 103 | + |
| 104 | +log_info "Index generation complete. Output directory: $output_dir" |
0 commit comments