From 8da59021d533cb1b6b1e0c8159c99bc9846329a7 Mon Sep 17 00:00:00 2001 From: Yousaf Nabi Date: Tue, 13 Feb 2024 22:18:20 +0000 Subject: [PATCH] feat: fallback to non musl variants if not found and warn user --- cli/Cargo.lock | 4 +- cli/Cargo.toml | 2 +- cli/release.sh | 12 +--- .../pact/plugins/jvm/core/PluginDownloader.kt | 69 ++++++++++++++++--- drivers/rust/driver/src/download.rs | 69 ++++++++++++++++--- 5 files changed, 123 insertions(+), 33 deletions(-) diff --git a/cli/Cargo.lock b/cli/Cargo.lock index 45634657..0b2222d2 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -1479,9 +1479,7 @@ dependencies = [ [[package]] name = "pact-plugin-driver" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26e63ffe3c61b92258856a9b0558d1526dfc4313a84280a452eec684513251b2" +version = "0.5.2" dependencies = [ "anyhow", "async-trait", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8fa85e70..75b06dee 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -14,7 +14,7 @@ exclude = [ ] [dependencies] -pact-plugin-driver = { version = "0.5.1" } +pact-plugin-driver = { version = "0.5.2", path = "../drivers/rust/driver" } clap = { version = "4.4.11", features = [ "derive", "cargo" ] } comfy-table = "7.1.0" home = "0.5.5" diff --git a/cli/release.sh b/cli/release.sh index ce249e2f..017e424c 100755 --- a/cli/release.sh +++ b/cli/release.sh @@ -17,13 +17,13 @@ case "$1" in Linux) echo "Building for Linux" cargo install cross@0.2.5 - echo -- Build the musl x86_64 release artifacts -- + echo -- Build the x86_64 release artifacts -- cargo clean cross build --target x86_64-unknown-linux-gnu --release gzip -c target/x86_64-unknown-linux-gnu/release/pact-plugin-cli > release_artifacts/pact-plugin-cli-linux-x86_64.gz openssl dgst -sha256 -r release_artifacts/pact-plugin-cli-linux-x86_64.gz > release_artifacts/pact-plugin-cli-linux-x86_64.gz.sha256 - echo -- Build the musl aarch64 release artifacts -- + echo -- Build the aarch64 release artifacts -- cargo clean cross build --target aarch64-unknown-linux-gnu --release gzip -c target/aarch64-unknown-linux-gnu/release/pact-plugin-cli > release_artifacts/pact-plugin-cli-linux-aarch64.gz @@ -35,14 +35,6 @@ case "$1" in gzip -c target/x86_64-unknown-linux-musl/release/pact-plugin-cli > release_artifacts/pact-plugin-cli-linux-x86_64-musl.gz openssl dgst -sha256 -r release_artifacts/pact-plugin-cli-linux-x86_64-musl.gz > release_artifacts/pact-plugin-cli-linux-x86_64-musl.gz.sha256 - - echo -- Build the musl aarch64 release artifacts -- - cargo clean - cross build --target aarch64-unknown-linux-gnu --release - gzip -c target/aarch64-unknown-linux-gnu/release/pact-plugin-cli > release_artifacts/pact-plugin-cli-linux-aarch64.gz - openssl dgst -sha256 -r release_artifacts/pact-plugin-cli-linux-aarch64.gz > release_artifacts/pact-plugin-cli-linux-aarch64.gz.sha256 - - echo -- Build the musl aarch64 release artifacts -- cargo clean cross build --release --target=aarch64-unknown-linux-musl diff --git a/drivers/jvm/core/src/main/kotlin/io/pact/plugins/jvm/core/PluginDownloader.kt b/drivers/jvm/core/src/main/kotlin/io/pact/plugins/jvm/core/PluginDownloader.kt index fdf58da8..21a5b1a5 100644 --- a/drivers/jvm/core/src/main/kotlin/io/pact/plugins/jvm/core/PluginDownloader.kt +++ b/drivers/jvm/core/src/main/kotlin/io/pact/plugins/jvm/core/PluginDownloader.kt @@ -96,8 +96,20 @@ object DefaultPluginDownloader: PluginDownloader, KLogging() { // Check for a single exec .gz file val ext = if (os == "windows") ".exe" else "" - val gzFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt$ext.gz" - val shaFileName = "pact-${manifest.name}-plugin-$os-$arch$muslExt$ext.gz.sha256" + val gzFile = "pact-${manifest.name}-plugin-$os-$arch$ext.gz" + val shaFileName = "pact-${manifest.name}-plugin-$os-$arch$ext.gz.sha256" + + if (isMusl()){ + val gzFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt$ext.gz" + val shaFileNameMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt$ext.gz.sha256" + + if (githubFileExists(url, tag, gzFileMusl)){ + val gzFile = gzFileMusl + val shaFileName = shaFileNameMusl + } else { + logger.warn { "musl detected, but no musl specific plugin implementation found - you may experience issues" } + } + } if (githubFileExists(url, tag, gzFile)) { logger.debug { "Found a GZipped file $gzFile" } when (val fileResult = downloadFileFromGithub(url, tag, gzFile, pluginDir)) { @@ -131,8 +143,21 @@ object DefaultPluginDownloader: PluginDownloader, KLogging() { } // Check for an arch specific Zip file - val archZipFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.zip" - val archZipShaFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.zip.sha256" + val archZipFile = "pact-${manifest.name}-plugin-$os-$arch.zip" + val archZipShaFile = "pact-${manifest.name}-plugin-$os-$arch.zip.sha256" + + if (isMusl()){ + val archZipFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.zip" + val archZipShaFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.zip.sha256" + + if (githubFileExists(url, tag, archZipFileMusl)){ + val archZipFile = archZipFileMusl + val archZipShaFile = archZipShaFileMusl + } else { + logger.warn { "musl detected, but no musl specific plugin implementation found - you may experience issues" } + } + } + if (githubFileExists(url, tag, archZipFile)) { return downloadZipFile(pluginDir, url, tag, archZipFile, archZipShaFile) } @@ -150,9 +175,23 @@ object DefaultPluginDownloader: PluginDownloader, KLogging() { if (githubFileExists(url, tag, tarGzFile)) { return downloadTarGzfile(pluginDir, url, tag, tarGzFile, tarGzShaFile) } + // Check for an arch specific tar.gz file - val archTarGzFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tar.gz" - val archTarGzShaFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tag.gz.sha256" + val archTarGzFile = "pact-${manifest.name}-plugin-$os-$arch.tar.gz" + val archTarGzShaFile = "pact-${manifest.name}-plugin-$os-$arch.tag.gz.sha256" + + if (isMusl()){ + val archTarGzFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tar.gz" + val archTarGzShaFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tag.gz.sha256" + + if (githubFileExists(url, tag, archTarGzFileMusl)){ + val archTarGzFile = archTarGzFileMusl + val archTarGzShaFile = archTarGzShaFileMusl + } else { + logger.warn { "musl detected, but no musl specific plugin implementation found - you may experience issues" } + } + } + if (githubFileExists(url, tag, archTarGzFile)) { return downloadTarGzfile(pluginDir, url, tag, archTarGzFile, archTarGzShaFile) } @@ -162,9 +201,23 @@ object DefaultPluginDownloader: PluginDownloader, KLogging() { if (githubFileExists(url, tag, tgzFile)) { return downloadTarGzfile(pluginDir, url, tag, tgzFile, tgzShaFile) } + // Check for an arch specific tgz file - val archTgzFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tgz" - val archTgzShaFile = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tgz.sha256" + val archTgzFile = "pact-${manifest.name}-plugin-$os-$arch.tgz" + val archTgzShaFile = "pact-${manifest.name}-plugin-$os-$arch.tgz.sha256" + + if (isMusl()){ + val archTgzFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tgz" + val archTgzShaFileMusl = "pact-${manifest.name}-plugin-$os-$arch$muslExt.tgz.sha256" + + if (githubFileExists(url, tag, archTgzFileMusl)){ + val archTgzFile = archTgzFileMusl + val archTgzShaFileMusl = archTgzShaFileMusl + } else { + logger.warn { "musl detected, but no musl specific plugin implementation found - you may experience issues" } + } + } + if (githubFileExists(url, tag, archTgzFile)) { return downloadTarGzfile(pluginDir, url, tag, archTgzFile, archTgzShaFile) } diff --git a/drivers/rust/driver/src/download.rs b/drivers/rust/driver/src/download.rs index 0950bae3..6be75ad2 100644 --- a/drivers/rust/driver/src/download.rs +++ b/drivers/rust/driver/src/download.rs @@ -14,7 +14,7 @@ use indicatif::{ProgressBar, ProgressStyle}; use reqwest::Client; use serde_json::Value; use sha2::{Digest, Sha256}; -use tracing::{debug, info}; +use tracing::{debug, info, warn}; use futures_util::StreamExt; @@ -62,10 +62,21 @@ pub async fn download_plugin_executable( let (os, arch, musl) = os_and_arch()?; // Check for a single exec .gz file - let ext = if os == "windows" { ".exe" } else { "" }; - let gz_file = format!("pact-{}-plugin-{}-{}{}{}.gz", manifest.name, os, arch,musl, ext); - let sha_file = format!("pact-{}-plugin-{}-{}{}{}.gz.sha256", manifest.name, os, arch,musl, ext); - if github_file_exists(http_client, base_url, tag, gz_file.as_str()).await? { + let ext = if os == "windows" { ".exe" } else { "" }; + let mut gz_file = format!("pact-{}-plugin-{}-{}{}.gz", manifest.name, os, arch, ext); + let mut sha_file = format!("pact-{}-plugin-{}-{}{}.gz.sha256", manifest.name, os, arch, ext); + if musl != "" { + let gz_file_musl = format!("pact-{}-plugin-{}-{}{}{}.gz", manifest.name, os, arch, musl, ext); + let sha_file_musl = format!("pact-{}-plugin-{}-{}{}{}.gz.sha256", manifest.name, os, arch, musl, ext); + if github_file_exists(http_client, base_url, tag, gz_file_musl.as_str()).await? { + gz_file = gz_file_musl; + sha_file = sha_file_musl; + } else { + warn!("musl detected, but no musl specific plugin implementation found - you may experience issues"); + } + } + + if github_file_exists(http_client, base_url, tag, gz_file.as_str()).await? { debug!(file = %gz_file, "Found a GZipped file"); let file = download_file_from_github(http_client, base_url, tag, gz_file.as_str(), plugin_dir, display_progress).await?; @@ -87,8 +98,20 @@ pub async fn download_plugin_executable( } // Check for an arch specific Zip file - let zip_file = format!("pact-{}-plugin-{}-{}{}.zip", manifest.name, os, arch, musl); - let zip_sha_file = format!("pact-{}-plugin-{}-{}{}.zip.sha256", manifest.name, os, arch, musl); + let mut zip_file = format!("pact-{}-plugin-{}-{}.zip", manifest.name, os, arch); + let mut zip_sha_file = format!("pact-{}-plugin-{}-{}.zip.sha256", manifest.name, os, arch); + + if musl != "" { + let zip_file_musl = format!("pact-{}-plugin-{}-{}{}.zip", manifest.name, os, arch, musl); + let zip_sha_file_musl = format!("pact-{}-plugin-{}-{}{}.zip.sha256", manifest.name, os, arch, musl); + if github_file_exists(http_client, base_url, tag, zip_file_musl.as_str()).await? { + zip_file = zip_file_musl; + zip_sha_file = zip_sha_file_musl; + } else { + warn!("musl detected, but no musl specific plugin implementation found - you may experience issues"); + } + } + if github_file_exists(http_client, base_url, tag, zip_file.as_str()).await? { return download_zip_file(plugin_dir, http_client, base_url, tag, zip_file, zip_sha_file, display_progress).await; } @@ -108,15 +131,39 @@ pub async fn download_plugin_executable( } // Check for an arch specific tar.gz file - let tar_gz_file = format!("pact-{}-plugin-{}-{}{}.tar.gz", manifest.name, os, arch, musl); - let tar_gz_sha_file = format!("pact-{}-plugin-{}-{}{}.tar.gz.sha256", manifest.name, os, arch, musl); + let mut tar_gz_file = format!("pact-{}-plugin-{}-{}{}.tar.gz", manifest.name, os, arch, musl); + let mut tar_gz_sha_file = format!("pact-{}-plugin-{}-{}{}.tar.gz.sha256", manifest.name, os, arch, musl); + + if musl != "" { + let tar_gz_file_musl = format!("pact-{}-plugin-{}-{}{}.tar.gz", manifest.name, os, arch, musl); + let tar_gz_sha_file_musl = format!("pact-{}-plugin-{}-{}{}.tar.gz.sha256", manifest.name, os, arch, musl); + if github_file_exists(http_client, base_url, tag, tar_gz_file_musl.as_str()).await? { + tar_gz_file = tar_gz_file_musl; + tar_gz_sha_file = tar_gz_sha_file_musl; + } else { + warn!("musl detected, but no musl specific plugin implementation found - you may experience issues"); + } + } + if github_file_exists(http_client, base_url, tag, tar_gz_file.as_str()).await? { return download_tar_gz_file(plugin_dir, http_client, base_url, tag, tar_gz_file, tar_gz_sha_file, display_progress).await; } // Check for an arch specific tgz file - let tgz_file = format!("pact-{}-plugin-{}-{}{}.tgz", manifest.name, os, arch, musl); - let tgz_sha_file = format!("pact-{}-plugin-{}-{}{}.tgz.sha256", manifest.name, os, arch, musl); + let mut tgz_file = format!("pact-{}-plugin-{}-{}{}.tgz", manifest.name, os, arch, musl); + let mut tgz_sha_file = format!("pact-{}-plugin-{}-{}{}.tgz.sha256", manifest.name, os, arch, musl); + + if musl != "" { + let tgz_file_musl = format!("pact-{}-plugin-{}-{}{}.tgz", manifest.name, os, arch, musl); + let tgz_sha_file_musl = format!("pact-{}-plugin-{}-{}{}.tgz.sha256", manifest.name, os, arch, musl); + if github_file_exists(http_client, base_url, tag, tgz_file_musl.as_str()).await? { + tgz_file = tgz_file_musl; + tgz_sha_file = tgz_sha_file_musl; + } else { + warn!("musl detected, but no musl specific plugin implementation found - you may experience issues"); + } + } + if github_file_exists(http_client, base_url, tag, tgz_file.as_str()).await? { return download_tar_gz_file(plugin_dir, http_client, base_url, tag, tgz_file, tgz_sha_file, display_progress).await; }