Skip to content

Commit

Permalink
feat: fallback to non musl variants if not found and warn user
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 13, 2024
1 parent 22451e1 commit 8da5902
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 33 deletions.
4 changes: 1 addition & 3 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 2 additions & 10 deletions cli/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
69 changes: 58 additions & 11 deletions drivers/rust/driver/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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?;

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 8da5902

Please sign in to comment.