|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 |
|
3 |
| -# This script downloads the wasm file from the go-feature-flag repository and adds it to the build. |
4 |
| - |
5 |
| -wasm_version="v1.45.0" # {{wasm_version}} |
6 |
| - |
7 |
| -# Set the repository owner and name |
8 |
| -repo_owner="thomaspoignant" |
9 |
| -repo_name="go-feature-flag" |
10 |
| -file_suffix=".wasi" |
11 |
| -target_dir="./src/main/resources/wasm/" |
12 |
| - |
13 |
| -# Function to find the download URL |
14 |
| -find_download_url() { |
15 |
| - local release_tag=$1 |
16 |
| - local file_suffix=$2 |
17 |
| - |
18 |
| - # Get the assets for the specific release |
19 |
| - assets=$(curl -s "https://api.github.com/repos/$repo_owner/$repo_name/releases/tags/$wasm_version" | jq -r '.assets') |
20 |
| - |
21 |
| - if [ -z "$assets" ]; then |
22 |
| - echo "Error: No assets found for release $wasm_version" |
23 |
| - return 1 |
24 |
| - fi |
25 |
| - |
26 |
| - # Find the asset that matches the file prefix |
27 |
| - download_url=$(echo "$assets" | jq -r ".[] | select(.name | endswith(\"$file_suffix\")) | .browser_download_url") |
28 |
| - |
29 |
| - if [ -z "$download_url" ]; then |
30 |
| - echo "Error: No asset found with prefix '$file_suffix' in release $wasm_version" |
31 |
| - return 1 |
32 |
| - fi |
33 |
| - echo "$download_url" |
34 |
| -} |
35 |
| - |
36 |
| -# Function to download the file |
37 |
| -download_file() { |
38 |
| - local url=$1 |
39 |
| - local target_dir=$2 |
40 |
| - |
41 |
| - if [ -z "$url" ]; then |
42 |
| - echo "Error: Download URL is empty." |
43 |
| - return 1 |
44 |
| - fi |
45 |
| - |
46 |
| - if [ -z "$target_dir" ]; then |
47 |
| - echo "Error: Target directory is empty." |
48 |
| - return 1 |
49 |
| - fi |
50 |
| - |
51 |
| - # Extract the filename from the URL |
52 |
| - local filename=$(basename "$url") |
53 |
| - |
54 |
| - # Check if the directory exists |
55 |
| - if [ ! -d "$target_dir" ]; then |
56 |
| - mkdir -p "$target_dir" # Create the directory if it doesn't exist |
57 |
| - fi |
58 |
| - |
59 |
| - # Use curl to download the file with progress |
60 |
| - echo "Downloading $filename to $target_dir..." |
61 |
| - curl -L -o "$target_dir/$filename" "$url" |
62 |
| - if [ $? -ne 0 ]; then |
63 |
| - echo "Error: Download failed." |
64 |
| - return 1 |
65 |
| - fi |
66 |
| - echo "Download successful!" |
67 |
| -} |
68 |
| - |
69 |
| -# Main script logic |
70 |
| -download_url=$(find_download_url "$latest_release" "$file_suffix") |
71 |
| -if [ $? -ne 0 ]; then |
72 |
| - echo "Error: Failed to find the download URL for release $latest_release." |
73 |
| - exit 1 |
74 |
| -fi |
75 |
| - |
76 |
| -download_file "$download_url" "$target_dir" |
77 |
| -if [ $? -ne 0 ]; then |
78 |
| - echo "Error: Failed to download the file. $download_url" |
79 |
| - exit 1 |
80 |
| -fi |
81 |
| - |
82 |
| -ls "$target_dir" |
83 |
| - |
84 |
| -echo "Done." |
| 3 | +# This script copy the wasm module from the git submodule repository and adds it to the build. |
| 4 | +wasm_version="v1.45.4" # {{wasm_version}} |
| 5 | +mv ./wasm-releases/evaluation/gofeatureflag-evaluation_$wasm_version.wasi ./src/main/resources/wasm/gofeatureflag-evaluation_$wasm_version.wasi |
0 commit comments