extract, test and fix path selection to only include files
This commit is contained in:
parent
061d1abd40
commit
3567b41e45
3 changed files with 31 additions and 9 deletions
3
.dockerignore
Normal file
3
.dockerignore
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.github
|
||||||
|
target/rls
|
||||||
|
tests
|
36
src/main.rs
36
src/main.rs
|
@ -47,6 +47,23 @@ where
|
||||||
mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM)
|
mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn paths<P>(
|
||||||
|
patterns: impl IntoIterator<Item = P>
|
||||||
|
) -> Result<impl IntoIterator<Item = PathBuf>, Box<dyn Error>>
|
||||||
|
where
|
||||||
|
P: AsRef<str>,
|
||||||
|
{
|
||||||
|
patterns
|
||||||
|
.into_iter()
|
||||||
|
.try_fold(Vec::new(), |mut paths, pattern| {
|
||||||
|
let matched = glob::glob(pattern.as_ref())?
|
||||||
|
.filter_map(Result::ok)
|
||||||
|
.filter(|p| p.is_file());
|
||||||
|
paths.extend(matched);
|
||||||
|
Ok(paths)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn run(
|
fn run(
|
||||||
conf: Config,
|
conf: Config,
|
||||||
releaser: &dyn Releaser,
|
releaser: &dyn Releaser,
|
||||||
|
@ -64,15 +81,7 @@ fn run(
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if let Some(patterns) = conf.input_files {
|
if let Some(patterns) = conf.input_files {
|
||||||
let paths: Result<Vec<PathBuf>, Box<dyn Error>> =
|
for path in paths(patterns)? {
|
||||||
patterns
|
|
||||||
.into_iter()
|
|
||||||
.try_fold(Vec::new(), |mut paths, pattern| {
|
|
||||||
let matched = glob::glob(pattern.as_str())?.filter_map(Result::ok);
|
|
||||||
paths.extend(matched);
|
|
||||||
Ok(paths)
|
|
||||||
});
|
|
||||||
for path in paths? {
|
|
||||||
log::info!("⬆️ Uploading asset {}", path.display());
|
log::info!("⬆️ Uploading asset {}", path.display());
|
||||||
uploader.upload(
|
uploader.upload(
|
||||||
conf.github_token.as_str(),
|
conf.github_token.as_str(),
|
||||||
|
@ -120,4 +129,13 @@ mod tests {
|
||||||
assert_eq!(is_tag(gitref), *expect)
|
assert_eq!(is_tag(gitref), *expect)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn paths_resolves_pattern_to_file_paths() -> Result<(), Box<dyn Error>> {
|
||||||
|
for p in paths(vec!["tests/data/**/*"])? {
|
||||||
|
println!("{}", p.display())
|
||||||
|
}
|
||||||
|
assert_eq!(paths(vec!["tests/data/**/*"])?.into_iter().count(), 1);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1
tests/data/foo/bar.txt
Normal file
1
tests/data/foo/bar.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
release me
|
Loading…
Reference in a new issue