Skip to content

Commit

Permalink
fix: hide file tasks starting with "." (jdx#2466)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored and triarius committed Sep 18, 2024
1 parent 3617130 commit 1a5ff6d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .mise/tasks/.hidden-executable
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euxo pipefail

echo "this should not show as a task"
15 changes: 15 additions & 0 deletions .mise/tasks/.hidden/bar/baz/hidden-executable
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euxo pipefail

# Used for shellcheck which needs explicit args
scripts=("$PWD"/scripts/*.sh "$PWD"/e2e/{test_,run_}* "$PWD"/e2e/*.sh)
# Used for shfmt which will run only on files it can
scripts_dirs=("$PWD"/scripts "$PWD"/e2e)

cargo clippy -- -Dwarnings
cargo fmt --all -- --check
shellcheck -x "${scripts[@]}"
shfmt -d -i 2 -ci -bn "${scripts_dirs[@]}"
prettier -c $(git ls-files '*.yml' '*.yaml')
markdownlint .
actionlint
14 changes: 12 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use indexmap::IndexMap;
use itertools::Itertools;
use once_cell::sync::{Lazy, OnceCell};
use rayon::prelude::*;

pub use settings::Settings;
use walkdir::WalkDir;

use crate::backend::Backend;
use crate::cli::args::BackendArg;
Expand Down Expand Up @@ -309,7 +309,17 @@ impl Config {
}

fn load_tasks_includes(&self, root: &Path) -> Result<Vec<Task>> {
file::recursive_ls(root)?
if !root.is_dir() {
return Ok(vec![]);
}
let files: Vec<PathBuf> = WalkDir::new(root)
.follow_links(true)
.into_iter()
.filter_entry(|e| !e.file_name().to_string_lossy().starts_with('.'))
.filter_ok(|e| e.file_type().is_file())
.map_ok(|e| e.path().to_path_buf())
.try_collect()?;
files
.into_par_iter()
.filter(|p| file::is_executable(p))
.map(|path| Task::from_path(&path))
Expand Down
42 changes: 29 additions & 13 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,38 @@ pub fn reset() {
env::remove_var("MISE_FAILURE");
file::remove_all(&*dirs::TRUSTED_CONFIGS).unwrap();
file::remove_all(&*dirs::TRACKED_CONFIGS).unwrap();
file::create_dir_all(".mise/tasks").unwrap();
file::create_dir_all(".mise/tasks/.hidden").unwrap();
file::write(
".mise/tasks/.hidden/executable",
indoc! {r#"#!/usr/bin/env bash
echo "this should not be a task"
"#},
)
.unwrap();
file::make_executable(".mise/tasks/.hidden/executable").unwrap();
file::write(
".mise/tasks/.hidden-executable",
indoc! {r#"#!/usr/bin/env bash
echo "this should not be a task"
"#},
)
.unwrap();
file::make_executable(".mise/tasks/.hidden-executable").unwrap();
file::write(
".mise/tasks/filetask",
indoc! {r#"#!/usr/bin/env bash
# mise alias=["ft"]
# mise description="This is a test build script"
# mise depends=["lint", "test"]
# mise sources=[".test-tool-versions"]
# mise outputs=["$MISE_PROJECT_ROOT/test/test-build-output.txt"]
# mise env={TEST_BUILDSCRIPT_ENV_VAR = "VALID"}
set -euxo pipefail
cd "$MISE_PROJECT_ROOT" || exit 1
echo "running test-build script"
echo "TEST_BUILDSCRIPT_ENV_VAR: $TEST_BUILDSCRIPT_ENV_VAR" > test-build-output.txt
"#},
# mise alias=["ft"]
# mise description="This is a test build script"
# mise depends=["lint", "test"]
# mise sources=[".test-tool-versions"]
# mise outputs=["$MISE_PROJECT_ROOT/test/test-build-output.txt"]
# mise env={TEST_BUILDSCRIPT_ENV_VAR = "VALID"}
set -euxo pipefail
cd "$MISE_PROJECT_ROOT" || exit 1
echo "running test-build script"
echo "TEST_BUILDSCRIPT_ENV_VAR: $TEST_BUILDSCRIPT_ENV_VAR" > test-build-output.txt
"#},
)
.unwrap();
file::make_executable(".mise/tasks/filetask").unwrap();
Expand Down

0 comments on commit 1a5ff6d

Please sign in to comment.