Downloads the latest feed.json from the autocomplete repository. This ensures official builds have the most up-to-date changelog information. # Errors Prints cargo warnings if: - `curl` command is not available - Network request fails - File write operation fails
()
| 338 | /// - Network request fails |
| 339 | /// - File write operation fails |
| 340 | fn download_feed_json() { |
| 341 | use std::process::Command; |
| 342 | |
| 343 | println!("cargo:warning=Downloading latest feed.json from autocomplete repo..."); |
| 344 | |
| 345 | // Check if curl is available first |
| 346 | let curl_check = Command::new("curl").arg("--version").output(); |
| 347 | |
| 348 | if curl_check.is_err() { |
| 349 | panic!( |
| 350 | "curl command not found. Cannot download latest feed.json. Please install curl or build without FETCH_FEED=1 to use existing feed.json." |
| 351 | ); |
| 352 | } |
| 353 | |
| 354 | let output = Command::new("curl") |
| 355 | .args([ |
| 356 | "-H", |
| 357 | "Accept: application/vnd.github.v3.raw", |
| 358 | "-f", // fail on HTTP errors |
| 359 | "-s", // silent |
| 360 | "-v", // verbose output printed to stderr |
| 361 | "--show-error", // print error message to stderr (since -s is used) |
| 362 | "https://api.github.com/repos/aws/amazon-q-developer-cli-autocomplete/contents/feed.json", |
| 363 | ]) |
| 364 | .output(); |
| 365 | |
| 366 | match output { |
| 367 | Ok(result) if result.status.success() => { |
| 368 | if let Err(e) = std::fs::write("src/cli/feed.json", result.stdout) { |
| 369 | panic!("Failed to write feed.json: {}", e); |
| 370 | } else { |
| 371 | println!("cargo:warning=Successfully downloaded latest feed.json"); |
| 372 | } |
| 373 | }, |
| 374 | Ok(result) => { |
| 375 | let error_msg = if !result.stderr.is_empty() { |
| 376 | format!("{}", String::from_utf8_lossy(&result.stderr)) |
| 377 | } else { |
| 378 | "An unknown error occurred".to_string() |
| 379 | }; |
| 380 | panic!("Failed to download feed.json: {}", error_msg); |
| 381 | }, |
| 382 | Err(e) => { |
| 383 | panic!("Failed to execute curl: {}", e); |
| 384 | }, |
| 385 | } |
| 386 | } |