Skip to content

Commit

Permalink
fix: not allow install inexistent artifact download url
Browse files Browse the repository at this point in the history
  • Loading branch information
innobead committed Dec 11, 2022
1 parent abc1b29 commit 71f4f79
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 79 deletions.
36 changes: 18 additions & 18 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = ["crates/app", "crates/common", "crates/procmacro", "crates/generator"
default-members = ["crates/app"]

[profile.release]
opt-level = 'z'
strip = true
opt-level = "z"
lto = true
codegen-units = 1
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ HUBER_ARTIFACT := $(shell $(CURDIR)/hack/huber-artifact-name.sh)
MANAGED_PKG_ROOT_DIR := $(CURDIR)/generated
PLATFORMS ?= linux/arm64 # for multi arch
HUBER_BIN=$(CURDIR)/target/debug/huber
FORCE_GENERATE ?= false

.PHONY: help
help:
Expand All @@ -18,7 +19,7 @@ setup-dev: ## Setup development environment
$(CURDIR)/hack/setup-dev.sh

.PHONY: build
build: fmt ## Build binaries
build: fix fmt ## Build binaries
cargo build $(CARGO_OPTS)

.PHONY: test
Expand Down Expand Up @@ -50,12 +51,14 @@ clean: ## Clean build caches
fix: ## Fix code
cargo fix --allow-dirty || cargo fix --allow-staged

# Examples:
# FORCE_GENERATE=true|false make generate
.PHONY: generate
generate: ## Generate managed package list
@echo "! Must have GITHUB_TOKEN to automatically generate package description"
GITHUB_TOKEN=$(GITHUB_TOKEN) cargo build -vv --package=huber-generator
GITHUB_KEY=$(GITHUB_KEY) $(MAKE) build && \
(MANAGED_PKG_ROOT_DIR=$(CURDIR)/generated $(HUBER_BIN) search | xargs -0 $(CURDIR)/hack/generate-packages.md.sh)
(MANAGED_PKG_ROOT_DIR=$(CURDIR)/generated FORCE_GENERATE=$(FORCE_GENERATE) $(HUBER_BIN) search | xargs -0 $(CURDIR)/hack/generate-packages.md.sh)

.PHONY: checksum
checksum: ## Generate checksum files for built executables
Expand All @@ -66,10 +69,14 @@ udep: ## Check unused dependencies
cargo install cargo-udeps --locked
cargo +nightly udeps

# Examples:
# PLATFORMS=linux/arm64 make build-multiarch
.PHONY: build-multiarch
build-multiarch: ## Build binaries for linux multiple architectures
PLATFORMS=$(PLATFORMS) BUILD_TARGET=debug MAKE_TARGET="test build" $(CURDIR)/hack/build-multiarch.sh

# Examples:
# PLATFORMS=linux/arm64 make release-multiarch
.PHONY: release-multiarch
release-multiarch: ## Release binaries for linux multiple archite
PLATFORMS=$(PLATFORMS) BUILD_TARGET=release OUTPUT_DIR=$(OUTPUT_DIR) MAKE_TARGET=release $(CURDIR)/hack/build-multiarch.sh
Expand All @@ -80,8 +87,10 @@ release-multiarch: ## Release binaries for linux multiple archite
verify: ## Verify Huber commands via the local package generated folder
MANAGED_PKG_ROOT_DIR=$(MANAGED_PKG_ROOT_DIR) $(HUBER_BIN) $(CMD)

# Examples:
# CMD=search make verify-compatible
.PHONY: verify-compatible
verify-compatible: ## Verify the current Huber commands via the local package generated folder
verify-compatible: ## Verify the installed Huber commands compatible with the new local package generated folder
MANAGED_PKG_ROOT_DIR=$(MANAGED_PKG_ROOT_DIR) $(shell which huber) $(CMD)

.PHONY: publish
Expand Down
10 changes: 5 additions & 5 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ log = "0.4"
pretty_env_logger = "0.4"
lazy_static = "1.4.0"
anyhow = "1.0"
dirs = "3.0.1"
semver = "0.11.0"
dirs = "4.0.0"
semver = "1.0.14"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.8.13"
serde_yaml = "~0.8.26"
reqwest = { version = "0.11", features = ["json"] }
tokio = { version = "1.16", features = ["full"] } # reqwest 0.10, hubcaps 0.6 does not support tokio 0.3/1.0 yet, ref: https://github.com/seanmonstar/reqwest/issues/1060
#hubcaps = { git = "https://github.com/softprops/hubcaps", rev = "324d02fbb371782c82e9a13b839b86894475c91f" } # wait for hubcaps formal release > 0.6
Expand All @@ -38,11 +38,11 @@ derive_more = "=0.99.17" # remove = until https://github.com/OSSystems/compress-
regex = "1.4.1"
futures = "0.3"
async-trait = "0.1.41"
git2 = "0.13"
git2 = "0.15.0"
chrono = "0.4"
symlink = "0.1.0"
is_executable = "1.0.1"
urlencoding = "1"
urlencoding = "2.1.2"
url = "2"
Inflector = "0.11.4"
fs_extra = "1.1"
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/cmd/reset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use huber_common::result::Result;
use huber_procmacro::process_lock;

use crate::cmd::{CommandAsyncTrait, CommandTrait};
use crate::service::update::{UpdateService, UpdateTrait};
use crate::service::update::{HuberUpdateService, UpdateTrait};

pub(crate) const CMD_NAME: &str = "reset";

Expand Down Expand Up @@ -48,7 +48,7 @@ impl CommandAsyncTrait for ResetCmd {
) -> Result<()> {
process_lock!();

let update_service = container.get::<UpdateService>().unwrap();
let update_service = container.get::<HuberUpdateService>().unwrap();

progress(
"Resetting huber by removing created caches, downloaded files and installed packages",
Expand Down
4 changes: 2 additions & 2 deletions crates/app/src/cmd/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use huber_procmacro::process_lock;

use crate::cmd::{CommandAsyncTrait, CommandTrait};
use crate::service::cache::{CacheAsyncTrait, CacheService};
use crate::service::update::{UpdateAsyncTrait, UpdateService};
use crate::service::update::{HuberUpdateService, UpdateAsyncTrait};

pub(crate) const CMD_NAME: &str = "self-update";

Expand Down Expand Up @@ -48,7 +48,7 @@ impl CommandAsyncTrait for SelfUpdateCmd {
let cache_service = container.get::<CacheService>().unwrap();
let _ = cache_service.update_repositories().await?;

let update_service = container.get::<UpdateService>().unwrap();
let update_service = container.get::<HuberUpdateService>().unwrap();

let r = update_service.has_update().await?;
if r.0 {
Expand Down
6 changes: 3 additions & 3 deletions crates/app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use crate::service::config::ConfigService;
use crate::service::package::PackageService;
use crate::service::release::ReleaseService;
use crate::service::repo::RepoService;
use crate::service::update::UpdateService;
use crate::service::update::HuberUpdateService;

mod cmd;
mod component;
Expand Down Expand Up @@ -117,7 +117,7 @@ fn init_services(mut container: DIContainer) -> Arc<DIContainer> {
create_dep!(PackageService::new(), container);
create_dep!(ReleaseService::new(), container);
create_dep!(CacheService::new(), container);
create_dep!(UpdateService::new(), container);
create_dep!(HuberUpdateService::new(), container);
create_dep!(RepoService::new(), container);
create_dep!(ConfigService::new(), container);

Expand All @@ -127,7 +127,7 @@ fn init_services(mut container: DIContainer) -> Arc<DIContainer> {
inject_dep!(PackageService, container.clone());
inject_dep!(ReleaseService, container.clone());
inject_dep!(CacheService, container.clone());
inject_dep!(UpdateService, container.clone());
inject_dep!(HuberUpdateService, container.clone());
inject_dep!(RepoService, container.clone());
inject_dep!(ConfigService, container.clone());

Expand Down
40 changes: 24 additions & 16 deletions crates/app/src/service/release.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use array_tool::vec::Uniq;
use std::collections::HashMap;
use std::fs::{read_dir, read_link, remove_dir_all, remove_file, File};
use std::io::Write;
Expand Down Expand Up @@ -468,44 +467,53 @@ impl ReleaseAsyncTrait for ReleaseService {
})
.collect();

let mut download_urls: Vec<String> = vec![];
let mut asset_urls: Vec<String> = asset_names
let mut asset_download_urls: Vec<String> = vec![];
let mut ext_asset_urls: Vec<String> = asset_names // external assets not on github
.iter()
.filter(|it| Url::parse(it).is_ok() && it.starts_with("https"))
.map(|it| it.clone())
.collect();
download_urls.append(&mut asset_urls);
asset_download_urls.append(&mut ext_asset_urls);

if !asset_urls.is_empty() {
asset_names = asset_names
if !ext_asset_urls.is_empty() {
asset_names = asset_names // assets on github
.into_iter()
.filter(|it| !asset_urls.contains(it))
.filter(|it| !ext_asset_urls.contains(it))
.collect();
}

// prepare download urls
for a in package_github.assets.iter() {
let decoded_download_url = decode(&a.browser_download_url)?;
for asset in package_github.assets.iter() {
let asset_download_url = decode(&asset.browser_download_url)?;

if !asset_names.contains(&a.name)
if !asset_names.contains(&asset.name) // assets not mentioned in assert names, just ignored
&& !asset_names
.iter()
.any(|it| decoded_download_url.ends_with(it))
.iter()
.any(|it| asset_download_url.ends_with(it))
{
debug!(
"Ignored {}, not mentioned or not right arch type defined in the package artifact config",
asset.name
);
continue;
}

download_urls.push(decoded_download_url);
asset_download_urls.push(asset_download_url.to_string());
}

if download_urls.len() < asset_names.len() {
return Err(anyhow!("{:?} not found", asset_names.uniq(download_urls)));
if asset_download_urls.is_empty() {
return Err(anyhow!(
"No available artifacts for {} to download, \
so probably the download path in package artifact config outdated. \
Please report issue to https://github.com/innobead/huber",
package.name
));
}

// download
let mut tasks = vec![];

for download_url in download_urls {
for download_url in asset_download_urls {
// download
info!("Downloading {}", &download_url);

Expand Down
Loading

0 comments on commit 71f4f79

Please sign in to comment.