mirror of
https://github.com/softprops/action-gh-release.git
synced 2024-11-22 15:22:45 +03:00
extract, test and fix path selection to only include files
This commit is contained in:
parent
061d1abd40
commit
3567b41e45
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)
|
||||
}
|
||||
|
||||
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
1
tests/data/foo/bar.txt
Normal file
@ -0,0 +1 @@
|
||||
release me
|
Loading…
Reference in New Issue
Block a user