Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add git remote task provider #4233

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion docs/tasks/toml-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,47 @@ file = 'scripts/release.sh' # execute an external script

### Remote tasks

Task files can be fetched via http:
Task files can be fetched remotely with multiple protocols:

#### HTTP

```toml
[tasks.build]
file = "https://example.com/build.sh"
```

Please note that the file will be downloaded and executed. Make sure you trust the source.

#### Git

::: code-group

```toml [ssh]
[tasks.build]
file = "git::ssh://[email protected]:myorg/example.git//myfile?ref=v1.0.0"
```

```toml [https]
[tasks.build]
file = "git::https://github.com/myorg/example.git//myfile?ref=v1.0.0"
```

:::

Url format must follow these patterns `git::<protocol>://<url>//<path>?<query>`

Required fields:

- `protocol`: The git repository URL.
- `url`: The git repository URL.
- `path`: The path to the file in the repository.

Optional fields:

- `query`: The git reference (branch, tag, commit).

#### Cache

Each task file is cached in the `MISE_CACHE_DIR` directory. If the file is updated, it will not be re-downloaded unless the cache is cleared.

:::tip
Expand Down
35 changes: 31 additions & 4 deletions src/task/task_file_providers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{fmt::Debug, path::PathBuf};

mod local_task;
mod remote_task_git;
mod remote_task_http;

pub use local_task::LocalTask;
use local_task::LocalTask;
use remote_task_git::RemoteTaskGitBuilder;
use remote_task_http::RemoteTaskHttpBuilder;

pub trait TaskFileProvider: Debug {
Expand Down Expand Up @@ -41,6 +43,11 @@ impl TaskFileProviders {

fn get_providers(&self) -> Vec<Box<dyn TaskFileProvider>> {
vec![
Box::new(
RemoteTaskGitBuilder::new()
.with_cache(self.use_cache)
.build(),
),
Box::new(
RemoteTaskHttpBuilder::new()
.with_cache(self.use_cache)
Expand All @@ -64,7 +71,7 @@ mod tests {
fn test_get_providers() {
let task_file_providers = TaskFileProvidersBuilder::new().build();
let providers = task_file_providers.get_providers();
assert_eq!(providers.len(), 2);
assert_eq!(providers.len(), 3);
}

#[test]
Expand All @@ -75,7 +82,8 @@ mod tests {
for file in cases {
let provider = task_file_providers.get_provider(file);
assert!(provider.is_some());
assert!(format!("{:?}", provider.unwrap()).contains("LocalTask"));
let provider_name = format!("{:?}", provider.unwrap());
assert!(provider_name.contains("LocalTask"));
}
}

Expand All @@ -91,7 +99,26 @@ mod tests {
for file in cases {
let provider = task_file_providers.get_provider(file);
assert!(provider.is_some());
assert!(format!("{:?}", provider.unwrap()).contains("RemoteTaskHttp"));
let provider_name = format!("{:?}", provider.unwrap());
assert!(provider_name.contains("RemoteTaskHttp"));
}
}

#[test]
fn test_git_file_match_git_remote_task_provider() {
let task_file_providers = TaskFileProvidersBuilder::new().build();
let cases = vec![
"git::ssh://[email protected]:myorg/example.git//myfile?ref=v1.0.0",
"git::https://github.com/myorg/example.git//myfile?ref=v1.0.0",
"git::ssh://[email protected]/example.git//subfolder/myfile.py",
"git::https://myserver.com/example.git//subfolder/myfile.sh",
];

for file in cases {
let provider = task_file_providers.get_provider(file);
assert!(provider.is_some());
let provider_name = format!("{:?}", provider.unwrap());
assert!(provider_name.contains("RemoteTaskGit"));
}
}
}
Loading
Loading