From e39a02aa920fb774c62c2d7e2c8c1051827ebf36 Mon Sep 17 00:00:00 2001 From: Jiahao XU Date: Sat, 27 Aug 2022 20:45:55 +1000 Subject: [PATCH] Test default `pkg-url` for GitLab and BitBucket (#322) * Test default `pkt-url` for GitLab and BitBucket * Fail if `cargo-build` is called when testing GitLab/BitBucket * Fix use of `remote_exists` in `GhCrateMeta::launch_baseline_find_tasks` If `Method::HEAD` fails, try `Method::GET` since some servers reject `Method::HEAD`, e.g. bbuseruploads.s3.amazonaws.com Signed-off-by: Jiahao XU --- .github/scripts/bitbucket-test-Cargo.toml | 15 +++++++++++++++ .github/scripts/fake-cargo/cargo | 4 ++++ .github/scripts/gitlab-test-Cargo.toml | 15 +++++++++++++++ .github/scripts/tests.sh | 19 +++++++++++++++++++ crates/lib/src/fetchers/gh_crate_meta.rs | 8 +++++--- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 .github/scripts/bitbucket-test-Cargo.toml create mode 100755 .github/scripts/fake-cargo/cargo create mode 100644 .github/scripts/gitlab-test-Cargo.toml diff --git a/.github/scripts/bitbucket-test-Cargo.toml b/.github/scripts/bitbucket-test-Cargo.toml new file mode 100644 index 000000000..dd0ff6bdf --- /dev/null +++ b/.github/scripts/bitbucket-test-Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cargo-binstall" +description = "Rust binary package installer for CI integration" +repository = "https://bitbucket.org/nobodyxusdcdc/hello-world" +version = "0.12.0" +rust-version = "1.61.0" +authors = ["ryan "] +edition = "2021" +license = "GPL-3.0" + +[package.metadata.binstall] +bin-dir = "{ bin }{ binary-ext }" + +[[bin]] +name = "cargo-binstall" diff --git a/.github/scripts/fake-cargo/cargo b/.github/scripts/fake-cargo/cargo new file mode 100755 index 000000000..da30ddf74 --- /dev/null +++ b/.github/scripts/fake-cargo/cargo @@ -0,0 +1,4 @@ +#!/bin/bash + +echo Always returns 1 to prevent use of "cargo-build" +exit 1 diff --git a/.github/scripts/gitlab-test-Cargo.toml b/.github/scripts/gitlab-test-Cargo.toml new file mode 100644 index 000000000..feea2041e --- /dev/null +++ b/.github/scripts/gitlab-test-Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cargo-binstall" +description = "Rust binary package installer for CI integration" +repository = "https://gitlab.kitware.com/NobodyXu/hello-world" +version = "0.2.0" +rust-version = "1.61.0" +authors = ["ryan "] +edition = "2021" +license = "GPL-3.0" + +[package.metadata.binstall] +bin-dir = "{ bin }{ binary-ext }" + +[[bin]] +name = "cargo-binstall" diff --git a/.github/scripts/tests.sh b/.github/scripts/tests.sh index d2ee228dd..e5b476548 100755 --- a/.github/scripts/tests.sh +++ b/.github/scripts/tests.sh @@ -58,3 +58,22 @@ cargo binstall --help >/dev/null "./$1" binstall --no-confirm cargo-binstall@0.11.0 "./$1" binstall --no-confirm cargo-binstall@0.11.0 | grep -q 'cargo-binstall v0.11.0 is already installed' "./$1" binstall --no-confirm cargo-binstall@^0.11.0 | grep -q -v 'cargo-binstall v0.11.0 is already installed' + +# Test default GitLab pkg-url templates +test_resources=".github/scripts" +PATH="$test_resources/fake-cargo:$PATH" + +"./$1" binstall \ + --force \ + --manifest-path "$test_resources/gitlab-test-Cargo.toml" \ + --log-level debug \ + --no-confirm \ + cargo-binstall + +# Test default BitBucket pkg-url templates +"./$1" binstall \ + --force \ + --manifest-path "$test_resources/bitbucket-test-Cargo.toml" \ + --log-level debug \ + --no-confirm \ + cargo-binstall diff --git a/crates/lib/src/fetchers/gh_crate_meta.rs b/crates/lib/src/fetchers/gh_crate_meta.rs index 29c22f7bc..532d40601 100644 --- a/crates/lib/src/fetchers/gh_crate_meta.rs +++ b/crates/lib/src/fetchers/gh_crate_meta.rs @@ -59,9 +59,11 @@ impl GhCrateMeta { AutoAbortJoinHandle::spawn(async move { debug!("Checking for package at: '{url}'"); - remote_exists(client, url.clone(), Method::HEAD) - .await - .map(|exists| exists.then_some((url, pkg_fmt))) + Ok( + (remote_exists(client.clone(), url.clone(), Method::HEAD).await? + || remote_exists(client, url.clone(), Method::GET).await?) + .then_some((url, pkg_fmt)), + ) }) }) }