@@ -59,15 +59,35 @@ jobs:
5959 sudo apt-get update
6060 sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libayatana-appindicator3-dev librsvg2-dev patchelf pkg-config libssl-dev libsoup-3.0-dev
6161
62- - name : Install wasm-bindgen-cli
62+ - name : Install wasm-bindgen-cli and wasm-opt
6363 if : ${{ matrix.platform == 'web' }}
64- run : cargo install wasm-bindgen-cli
64+ run : |
65+ cargo install wasm-bindgen-cli
66+ # Install wasm-opt via binaryen
67+ curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xz
68+ sudo cp binaryen-version_117/bin/wasm-opt /usr/local/bin/
69+ wasm-opt --version
6570
6671 - name : Build for Web
6772 if : ${{ matrix.platform == 'web' }}
6873 run : |
6974 cd opensvm-dioxus
7075 cargo build --target wasm32-unknown-unknown --features web --release --no-default-features
76+
77+ # Optimize WASM binary with wasm-opt
78+ echo "Original WASM size:"
79+ ls -lh target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
80+
81+ wasm-opt -Oz --enable-mutable-globals \
82+ target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm \
83+ -o target/wasm32-unknown-unknown/release/opensvm_dioxus_opt.wasm
84+
85+ # Replace original with optimized version
86+ mv target/wasm32-unknown-unknown/release/opensvm_dioxus_opt.wasm \
87+ target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
88+
89+ echo "Optimized WASM size:"
90+ ls -lh target/wasm32-unknown-unknown/release/opensvm_dioxus.wasm
7191
7292 - name : Build for Desktop (macOS)
7393 if : ${{ matrix.platform == 'desktop' && matrix.os == 'macos-latest' }}
@@ -187,12 +207,84 @@ jobs:
187207 VERSION=${GITHUB_REF#refs/tags/v}
188208 DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/opensvm-dioxus-macos.zip"
189209
190- # Wait for release to be available
191- sleep 30
210+ # Function to retry downloading with exponential backoff
211+ download_with_retry() {
212+ local url="$1"
213+ local output="$2"
214+ local max_attempts=5
215+ local attempt=1
216+ local delay=10
217+
218+ while [ $attempt -le $max_attempts ]; do
219+ echo "Attempt $attempt/$max_attempts: Downloading $url"
220+
221+ if curl -L --fail --retry 3 --retry-delay 5 -o "$output" "$url"; then
222+ echo "Download successful on attempt $attempt"
223+ return 0
224+ fi
225+
226+ echo "Download failed on attempt $attempt"
227+
228+ if [ $attempt -eq $max_attempts ]; then
229+ echo "All download attempts failed"
230+ return 1
231+ fi
232+
233+ echo "Waiting ${delay} seconds before next attempt..."
234+ sleep $delay
235+ delay=$((delay * 2)) # Exponential backoff
236+ attempt=$((attempt + 1))
237+ done
238+ }
239+
240+ # Wait for release to be available with health check
241+ echo "Checking if release is available..."
242+ HEALTH_CHECK_URL="https://api.github.com/repos/${{ github.repository }}/releases/tags/v${VERSION}"
243+ max_wait_attempts=12 # 12 * 10 seconds = 2 minutes max wait
244+ wait_attempt=1
245+
246+ while [ $wait_attempt -le $max_wait_attempts ]; do
247+ echo "Health check attempt $wait_attempt/$max_wait_attempts"
248+
249+ if curl -s --fail "$HEALTH_CHECK_URL" > /dev/null; then
250+ echo "Release found in GitHub API"
251+ break
252+ fi
253+
254+ if [ $wait_attempt -eq $max_wait_attempts ]; then
255+ echo "Release not found after waiting, proceeding anyway..."
256+ break
257+ fi
258+
259+ echo "Release not yet available, waiting 10 seconds..."
260+ sleep 10
261+ wait_attempt=$((wait_attempt + 1))
262+ done
263+
264+ # Download the release asset with retry logic
265+ if ! download_with_retry "$DOWNLOAD_URL" "opensvm-dioxus-macos.zip"; then
266+ echo "Failed to download release asset after all retries"
267+ echo "URL: $DOWNLOAD_URL"
268+ echo "Checking available assets..."
269+ curl -s "https://api.github.com/repos/${{ github.repository }}/releases/tags/v${VERSION}" | jq '.assets[].name' || true
270+ exit 1
271+ fi
272+
273+ # Verify the downloaded file
274+ if [ ! -f "opensvm-dioxus-macos.zip" ] || [ ! -s "opensvm-dioxus-macos.zip" ]; then
275+ echo "Downloaded file is missing or empty"
276+ exit 1
277+ fi
192278
193- # Calculate SHA256 of the released asset
194- curl -L -o opensvm-dioxus-macos.zip "$DOWNLOAD_URL" || exit 1
279+ # Calculate SHA256 of the downloaded asset
195280 SHA256=$(shasum -a 256 opensvm-dioxus-macos.zip | awk '{print $1}')
281+ echo "Calculated SHA256: $SHA256"
282+
283+ # Validate SHA256 format
284+ if ! echo "$SHA256" | grep -q '^[a-f0-9]\{64\}$'; then
285+ echo "Invalid SHA256 format: $SHA256"
286+ exit 1
287+ fi
196288
197289 # Create formula directory if it doesn't exist
198290 mkdir -p Formula
@@ -213,16 +305,33 @@ jobs:
213305 end
214306 EOF
215307
308+ # Validate the generated formula syntax
309+ if ! ruby -c Formula/opensvm-dioxus.rb; then
310+ echo "Generated formula has syntax errors"
311+ exit 1
312+ fi
313+
314+ echo "Generated formula:"
315+ cat Formula/opensvm-dioxus.rb
316+
216317 # Create a new branch for the formula update
217318 git checkout -b update-homebrew-formula-v$VERSION
218319
219- # Commit and push changes
320+ # Commit and push changes with error handling
220321 git add Formula/opensvm-dioxus.rb
221322 git commit -m "Update Homebrew formula to v$VERSION"
222- git push origin update-homebrew-formula-v$VERSION
323+
324+ if ! git push origin update-homebrew-formula-v$VERSION; then
325+ echo "Failed to push branch, may already exist"
326+ git push --force origin update-homebrew-formula-v$VERSION
327+ fi
223328
224- # Create pull request using GitHub CLI
225- gh pr create --title "Update Homebrew formula to v$VERSION" --body "Updates the Homebrew formula for opensvm-dioxus to version $VERSION" --base main --head update-homebrew-formula-v$VERSION
329+ # Create pull request using GitHub CLI with error handling
330+ if ! gh pr create --title "Update Homebrew formula to v$VERSION" --body "Updates the Homebrew formula for opensvm-dioxus to version $VERSION" --base main --head update-homebrew-formula-v$VERSION; then
331+ echo "Failed to create PR, it may already exist"
332+ echo "Checking existing PRs..."
333+ gh pr list --head update-homebrew-formula-v$VERSION || true
334+ fi
226335 env :
227336 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
228337
0 commit comments