Skip to content

Commit

Permalink
extract, test and fix path selection to only include files
Browse files Browse the repository at this point in the history
  • Loading branch information
softprops committed Aug 25, 2019
1 parent 061d1ab commit 3567b41
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.github
target/rls
tests
36 changes: 27 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions tests/data/foo/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
release me

0 comments on commit 3567b41

Please sign in to comment.