Skip to content

Commit

Permalink
chore: run autofix on windows (#3153)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Nov 23, 2024
1 parent ac38673 commit 89b1a5d
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 38 deletions.
28 changes: 27 additions & 1 deletion .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ env:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: -C link-arg=-fuse-ld=mold

jobs:
autofix:
ubuntu:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- uses: rui314/setup-mold@v1
- uses: Swatinem/rust-cache@v2
with:
shared-key: autofix
- run: |
cargo build --all-features
echo "$PWD/target/debug" >> "$GITHUB_PATH"
Expand All @@ -46,3 +48,27 @@ jobs:
- run: mise run render
- run: mise run lint-fix
- uses: autofix-ci/[email protected]
windows:
runs-on: windows-latest
timeout-minutes: 30
steps:
- run: git config --global core.autocrlf false
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
with:
shared-key: autofix
- run: |
cargo build
Add-Content $env:GITHUB_PATH "$env:GITHUB_WORKSPACE\target\debug"
shell: pwsh
- uses: actions/cache@v4
with:
key: ${{ runner.os }}-mise-tools-${{ hashFiles('mise.lock') }}
path: |
~/.local/share/mise
~/.cache/mise
- run: mise install
- run: mise x -- npm i
#- run: mise run render
- run: mise run lint-fix
- uses: autofix-ci/[email protected]
10 changes: 10 additions & 0 deletions docs/tasks/toml-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,13 @@ run = 'echo {{flag(name=("myflag")}}'
- `name`: The name of the flag. This is used for help/error messages.

The value will be `true` if the flag is passed, and `false` otherwise.

## Windows

You can specify an alternate command to run on Windows by using the `run_windows` key:

```toml
[tasks.test]
run = 'cargo test'
run_windows = 'cargo test --features windows'
```
7 changes: 4 additions & 3 deletions mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@ version = "1.7.4"
[tools.actionlint.checksums]
actionlint-linux-x86_64 = "sha256:39cae525cdb54af5d91dcf27f55e040d37ecea01dd4153490c4dc84f5d251d46"
actionlint-macos-aarch64 = "sha256:f381afca13b39e095e4cee25e2b2abbb39ae8b2848f5ccd2564bf86192c1b661"
"actionlint.exe-windows-aarch64" = "sha256:88c33950ccbd3ba6854d14ffa14071673b8f427d5a5711d9ca68d6e97b8a523f"
"actionlint.exe-windows-x86_64" = "sha256:04ca117d9f33b77731fd3ef6a3670bd6b11b40c1b1cc5b7aaf6c28392d74d2e2"

[tools.bun]
version = "1.1.36"

[tools.bun.checksums]
"bun-darwin-aarch64.zip" = "sha256:f299aaf467ec8e610bbefef8b91664ab3b199a174ceb2f5a97d624c96dfde068"
"bun-linux-x64-baseline.zip" = "sha256:515666143dbda58ed0b90cf3ae0ade7178b0d705d7576f62bedf66c709740eb3"
"bun-windows-x64-baseline.zip" = "sha256:fd47551a001e998eb5161e61a3f64ccbabf46cf978782310bab75f1a71cbbd29"

[tools.cargo-binstall]
version = "1.10.13"

[tools.cargo-binstall.checksums]
cargo-binstall-linux-x86_64 = "sha256:53a7157f56e1698d42d3cd50b1d08f02159638e3a73edf362e14215337942e86"
cargo-binstall-macos-aarch64 = "sha256:f67dd4fc8ea01b4c55fe041a0fbd6d81a361947f1dbf2bd226490c641cc167b3"
"cargo-binstall.exe-windows-aarch64" = "sha256:78d3289aee231c1ddaeb520c82576f622a7e202a3a4884ad9f8c206b6c17b25c"
"cargo-binstall.exe-windows-x86_64" = "sha256:32a28a1e98ad23e2c7ac360b815001181d7feffd1283a20c6ef92c3c032d6ba6"

[tools."cargo:cargo-edit"]
version = "0.13.0"
Expand Down Expand Up @@ -85,4 +86,4 @@ version = "2.6.0"
[tools.slsa-verifier.checksums]
slsa-verifier-linux-x86_64 = "sha256:1c9c0d6a272063f3def6d233fa3372adbaff1f5a3480611a07c744e73246b62d"
slsa-verifier-macos-aarch64 = "sha256:8740e66832fd48bbaa479acd5310986b876ff545460add0cb4a087aec056189c"
"slsa-verifier.exe-windows-aarch64" = "sha256:6235daec8037a2e8f6aa11c583eed6b09b2cd36b61b43b9e5898281b39416d2f"
"slsa-verifier.exe-windows-x86_64" = "sha256:37ca29ad748e8ea7be76d3ae766e8fa505362240431f6ea7f0648c727e2f2507"
16 changes: 16 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,22 @@
}
]
},
"run_windows": {
"oneOf": [
{
"description": "script to run on windows",
"type": "string"
},
{
"description": "script to run on windows",
"items": {
"description": "script to run on windows",
"type": "string"
},
"type": "array"
}
]
},
"file": {
"description": "Execute an external script",
"type": "string"
Expand Down
31 changes: 20 additions & 11 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,13 @@ impl Run {
) -> (String, Vec<String>) {
let display = file.display().to_string();
if file::is_executable(file) && !SETTINGS.use_file_shell_for_executable_tasks {
if cfg!(windows) && file.extension().map_or(false, |e| e == "ps1") {
let args = vec!["-File".to_string(), display]
.into_iter()
.chain(args.iter().cloned())
.collect_vec();
return ("pwsh".to_string(), args);
}
return (display, args.to_vec());
}
let default_shell = self.clone_default_file_shell();
Expand Down Expand Up @@ -666,17 +673,19 @@ impl Run {
.map(|d| d.join(name))
.find(|d| d.is_file() && !file::is_executable(d));
if let Some(path) = path {
warn!(
"no task {} found, but a non-executable file exists at {}",
style::ered(name),
display_path(&path)
);
let yn = prompt::confirm(
"Mark this file as executable to allow it to be run as a task?",
)?;
if yn {
file::make_executable(&path)?;
info!("marked as executable, try running this task again");
if !cfg!(windows) {
warn!(
"no task {} found, but a non-executable file exists at {}",
style::ered(name),
display_path(&path)
);
let yn = prompt::confirm(
"Mark this file as executable to allow it to be run as a task?",
)?;
if yn {
file::make_executable(&path)?;
info!("marked as executable, try running this task again");
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/cli/tasks/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ impl TasksInfo {
if let Some(file) = &task.file {
info::inline_section("File", display_path(file))?;
}
if !task.run.is_empty() {
info::section("Run", task.run.join("\n"))?;
if !task.run().is_empty() {
info::section("Run", task.run().join("\n"))?;
}
if !task.env.is_empty() {
info::section("Environment Variables", toml::to_string_pretty(&task.env)?)?;
Expand All @@ -97,7 +97,7 @@ impl TasksInfo {
"raw": task.raw,
"sources": task.sources,
"outputs": task.outputs,
"run": task.run,
"run": task.run(),
"file": task.file,
"usage_spec": spec,
});
Expand Down
10 changes: 5 additions & 5 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,11 @@ impl Debug for Config {

fn default_task_includes() -> Vec<PathBuf> {
vec![
"mise-tasks".into(),
".mise-tasks".into(),
".mise/tasks".into(),
".config/mise/tasks".into(),
"mise/tasks".into(),
PathBuf::from("mise-tasks"),
PathBuf::from(".mise-tasks"),
PathBuf::from(".mise").join("tasks"),
PathBuf::from(".config").join("mise").join("tasks"),
PathBuf::from("mise").join("tasks"),
]
}

Expand Down
15 changes: 7 additions & 8 deletions src/env.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use std::collections::{HashMap, HashSet};
pub use std::env::*;
use std::path::PathBuf;
use std::string::ToString;
use std::sync::RwLock;
use std::{path, process};

use crate::cli::args::PROFILE_ARG;
use crate::env_diff::{EnvDiff, EnvDiffOperation, EnvDiffPatches};
use crate::file::replace_path;
use crate::hook_env::{deserialize_watches, HookEnvWatches};
use itertools::Itertools;
use log::LevelFilter;
use once_cell::sync::Lazy;
use std::collections::{HashMap, HashSet};
pub use std::env::*;
use std::path::PathBuf;
use std::string::ToString;
use std::sync::RwLock;
use std::{path, process};

pub static ARGS: RwLock<Vec<String>> = RwLock::new(vec![]);
#[cfg(unix)]
Expand All @@ -37,7 +36,7 @@ pub static XDG_CACHE_HOME: Lazy<PathBuf> =
pub static XDG_CACHE_HOME: Lazy<PathBuf> = Lazy::new(|| {
var_path("XDG_CACHE_HOME")
.or_else(|| var_path("TEMP"))
.unwrap_or_else(|| temp_dir())
.unwrap_or_else(temp_dir)
});
#[cfg(all(not(windows), not(macos)))]
pub static XDG_CACHE_HOME: Lazy<PathBuf> =
Expand Down
4 changes: 2 additions & 2 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,12 @@ pub fn is_executable(path: &Path) -> bool {
path.extension().map_or(
SETTINGS
.windows_executable_extensions
.contains(&String::from("")),
.contains(&String::new()),
|ext| {
if let Some(str_val) = ext.to_str() {
return SETTINGS
.windows_executable_extensions
.contains(&str_val.to_string());
.contains(&str_val.to_lowercase().to_string());
}
false
},
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/core/ruby_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl RubyPlugin {
}

fn verify(&self, ctx: &InstallContext, tv: &ToolVersion) -> Result<()> {
self.test_ruby(&tv, ctx.pr.as_ref())
self.test_ruby(tv, ctx.pr.as_ref())
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub struct Task {
#[serde(default, deserialize_with = "deserialize_arr")]
pub run: Vec<String>,

#[serde(default, deserialize_with = "deserialize_arr")]
pub run_windows: Vec<String>,

// command type
// pub command: Option<String>,
#[serde(default)]
Expand Down Expand Up @@ -103,7 +106,7 @@ impl Task {
.filter_map(|line| {
regex!(r"^(#|//) mise ([a-z_]+=.+)$")
.captures(line)
.or_else(|| regex!(r"^(#|//)MISE ([a-z_]+=.+)$").captures(line))
.or_else(|| regex!(r"^(#|//|::)MISE ([a-z_]+=.+)$").captures(line))
})
.map(|captures| captures.extract().1)
.flat_map(|[_, toml]| {
Expand Down Expand Up @@ -169,6 +172,14 @@ impl Task {
format!("[{}]", self.name)
}

pub fn run(&self) -> &Vec<String> {
if cfg!(windows) && !self.run_windows.is_empty() {
&self.run_windows
} else {
&self.run
}
}

pub fn all_depends<'a>(&self, config: &'a Config) -> Result<Vec<&'a Task>> {
let tasks = config.tasks_with_aliases()?;
let mut depends: Vec<&Task> = self
Expand Down Expand Up @@ -215,7 +226,7 @@ impl Task {
(spec, vec![])
} else {
let (scripts, spec) =
TaskScriptParser::new(cwd).parse_run_scripts(&self.config_root, &self.run)?;
TaskScriptParser::new(cwd).parse_run_scripts(&self.config_root, self.run())?;
(spec, scripts)
};
spec.name = self.name.clone();
Expand Down Expand Up @@ -254,7 +265,7 @@ impl Task {
.enumerate()
.map(|(i, script)| {
// only pass args to the last script if no formal args are defined
match i == self.run.len() - 1 {
match i == self.run().len() - 1 {
true => (script.clone(), args.iter().cloned().collect_vec()),
false => (script.clone(), vec![]),
}
Expand Down Expand Up @@ -355,6 +366,7 @@ impl Default for Task {
outputs: vec![],
shell: None,
run: vec![],
run_windows: vec![],
args: vec![],
file: None,
}
Expand All @@ -363,7 +375,7 @@ impl Default for Task {

impl Display for Task {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let cmd = if let Some(command) = self.run.first() {
let cmd = if let Some(command) = self.run().first() {
Some(command.to_string())
} else {
self.file.as_ref().map(display_path)
Expand Down
1 change: 1 addition & 0 deletions tasks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ lint = { depends = ["lint:*"] }
[build]
alias = "b"
run = "cargo build --all-features"
run_windows = "cargo build --features clap_mangen"
#sources = ["Cargo.*", "src/**/*.rs"]
#outputs = ["target/debug/mise"]

Expand Down
8 changes: 8 additions & 0 deletions tasks/lint-fix.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#MISE alias=["format"]
#MISE wait_for=["build", "render:settings"]
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true

cargo clippy --fix --allow-staged --allow-dirty -- -Dwarnings
prettier -w .
cargo fmt --all
1 change: 1 addition & 0 deletions tasks/show-output-on-failure.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
%*

0 comments on commit 89b1a5d

Please sign in to comment.