extract, test and fix path selection to only include files

This commit is contained in:
softprops 2019-08-25 15:13:13 -04:00
parent 061d1abd40
commit 3567b41e45
3 changed files with 31 additions and 9 deletions

3
.dockerignore Normal file
View File

@ -0,0 +1,3 @@
.github
target/rls
tests

View File

@ -47,6 +47,23 @@ where
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(
conf: Config,
releaser: &dyn Releaser,
@ -64,15 +81,7 @@ fn run(
)?;
if let Some(patterns) = conf.input_files {
let paths: Result<Vec<PathBuf>, Box<dyn Error>> =
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? {
for path in paths(patterns)? {
log::info!("⬆️ Uploading asset {}", path.display());
uploader.upload(
conf.github_token.as_str(),
@ -120,4 +129,13 @@ mod tests {
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
View File

@ -0,0 +1 @@
release me