Skip to content

feat(tasks): Add environment variable directives for mise tasks#5638

Merged
jdx merged 35 commits intomainfrom
cursor/add-environment-variable-support-for-mise-tasks-a132
Aug 3, 2025
Merged

feat(tasks): Add environment variable directives for mise tasks#5638
jdx merged 35 commits intomainfrom
cursor/add-environment-variable-support-for-mise-tasks-a132

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Jul 14, 2025

Add support for _.file, _.path, _.source directives and false value for removal in [tasks.<name>.env] configurations.

This feature allows loading environment variables from files directly within task definitions, making it easier to synchronize mise tasks with IDE configurations as requested in #4762.

BREAKING CHANGE: there is a minor breaking change. The internal structure of the env key in tasks has to change from an object to array. Unfortunately I don't see a way around this because directives can be specified multiple times so it has to be an array. This is only exposed via mise task info --json so you are only affected if using the env key in that command. If this is an issue for you, please let me know, perhaps we can brainstorm on a solution.

Copilot AI review requested due to automatic review settings July 14, 2025 13:22

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@jdx jdx linked an issue Jul 14, 2025 that may be closed by this pull request
@jdx jdx marked this pull request as draft July 15, 2025 12:59
@jdx jdx changed the title Add environment variable support for mise tasks fix: Add environment variable support for mise tasks Aug 2, 2025
@jdx jdx changed the title fix: Add environment variable support for mise tasks feat(tasks): Add environment variable support for mise tasks Aug 2, 2025
@jdx jdx force-pushed the cursor/add-environment-variable-support-for-mise-tasks-a132 branch from adf1be9 to ccb37cb Compare August 2, 2025 19:57
jdx and others added 4 commits August 2, 2025 20:15
- Add Serialize trait to TaskEnvList, EnvDirective, and EnvDirectiveOptions
- Implement is_empty() method for TaskEnvList
- Refactor task env parsing to properly convert from BTreeMap to TaskEnvList
- Clean up unused imports and variables
- Reuse existing env directive parsing logic from config system
- Fix type mismatch between parse_env return type and TaskEnvList

This resolves compilation errors while maintaining full compatibility
with existing task environment variable functionality and serialization.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Aug 2, 2025

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.8.3 x -- echo 19.2 ± 0.3 18.6 22.8 1.04 ± 0.03
mise x -- echo 18.4 ± 0.5 17.6 22.7 1.00

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.8.3 env 18.8 ± 0.6 18.0 23.6 1.04 ± 0.05
mise env 18.0 ± 0.7 17.0 25.1 1.00

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.8.3 hook-env 18.0 ± 0.2 17.6 18.6 1.05 ± 0.02
mise hook-env 17.2 ± 0.2 16.7 18.4 1.00

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.8.3 ls 15.8 ± 0.2 15.4 19.0 1.00
mise ls 15.9 ± 0.2 15.5 18.6 1.01 ± 0.02

xtasks/test/perf

Command mise-2025.8.3 mise Variance
install (cached) 190ms ✅ 126ms +50%
ls (cached) 80ms 80ms +0%
bin-paths (cached) 64ms 64ms +0%
task-ls (cached) 500ms 468ms +6%

✅ Performance improvement: install cached is 50%

@jdx
Copy link
Owner Author

jdx commented Aug 2, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

@jdx
Copy link
Owner Author

jdx commented Aug 2, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

@jdx jdx marked this pull request as ready for review August 2, 2025 22:19
cursor[bot]

This comment was marked as outdated.

jdx added 3 commits August 2, 2025 22:29
…zation

The task environment parsing was using serde::Deserialize::deserialize(env_value.clone())
with a 	oml::Value, which doesn't work correctly. This caused parsing to silently
fail with a warning instead of properly handling environment directives.

Fixed by converting the toml::Value back to a string and using 	oml::from_str::<EnvList>()
which properly uses the EnvList deserializer designed for the task environment format.

This ensures that task environment directives like _.file, _.path, _.source work correctly
and boolean false values properly unset variables instead of being ignored.
Replace the custom parse_task_env function with a proper parse_env method
on TomlParser, making it consistent with other parsing methods like
parse_array and parse_table. This provides a cleaner API and better
separation of concerns.
cursor[bot]

This comment was marked as outdated.

Add parsing support for _.file, _.path, and _.source syntax in task
environment sections, matching the syntax used in global environments.

Previously only the nested syntax (_ = { file = "...", path = "..." })
was supported in tasks, but the e2e tests expect the flat syntax to work.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
cursor[bot]

This comment was marked as outdated.

jdx and others added 10 commits August 2, 2025 20:14
Changed EnvDirective Display implementation to show the original directive syntax:
- _.file = "path" instead of dotenv path
- _.path = "path" instead of path_add path
- _.source = "path" instead of source path

This makes task info output match the expected TOML directive format,
making it easier for users to understand and copy the syntax.

Fixes task info display format for environment directives.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
…gression

- Replace boolean `tools` field with `ToolsFilter` enum for flexible filtering
- Add Default implementations for ToolsFilter and EnvResolveOptions
- Fix global environment loading regression (vars: false)
- Ensure consistent ToolsFilter usage across all modules
- Fix venv test to use new ToolsFilter::ToolsOnly

This ensures that both global environment directives and task environment
directives work correctly with proper filtering capabilities.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
EnvResolveOptions should be explicitly constructed rather than using defaults
to ensure intentional specification of vars and tools filtering behavior.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
… snapshots

- Fixed path.rs test that was still using EnvResolveOptions::default()
- Updated all snapshot tests to reflect new flat syntax display format
- Unit tests now pass: 233 passed; 0 failed
- E2E tests for task environment directives still pass
- All features working correctly with proper flat syntax support

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Updated the task JSON output to consistently represent empty environment objects as `[]` instead of `{}`. This change ensures uniformity across the task environment directives and aligns with the expected output format.
…ation

- Added handling for flat directive syntax (e.g., _.file, _.path, _.source) in the EnvList deserialization process.
- Improved parsing for path directives to support both string and array formats, ensuring robust error handling for invalid values.
- Removed redundant PATH processing in Toolset, as it is now managed by PathEnv::from_iter(), preventing duplication of paths.

This update ensures that the environment directives are processed correctly and consistently, aligning with the expected TOML format.
if redact {
r.redactions.push(k.clone());
}
r.env_remove.insert(k.clone());
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no idea why this was set but seems like it was wrong

@jdx jdx changed the title feat(tasks): Add environment variable support for mise tasks feat(tasks): Add environment variable directives for mise tasks Aug 3, 2025
@jdx jdx merged commit ed8f122 into main Aug 3, 2025
21 checks passed
@jdx jdx deleted the cursor/add-environment-variable-support-for-mise-tasks-a132 branch August 3, 2025 09:35
jdx pushed a commit that referenced this pull request Aug 3, 2025
### 🚀 Features

- **(tasks)** **breaking** Add environment variable directives for mise
tasks by [@jdx](https://github.com/jdx) in
[#5638](#5638)
@glasser
Copy link
Contributor

glasser commented Aug 4, 2025

This appears to cause a regression using _.path with node.
#5913

@joshbode
Copy link
Contributor

joshbode commented Aug 6, 2025

I believe this also causes a regression for mise-poetry, which uses MISE_ADD_PATH. The PATH is no longer being updated to add ${VIRTUAL_ENV}/bin

mise 2025.8.3 works, but everything after doesn't update the PATH.

As a workaround, adding _.python.venv explicitly will update the PATH:

[tools]
python = "3.12"
poetry = { version = "2.1", pyproject = "{{ config_root }}/pyproject.toml" }

[env]
_.python.venv = ".venv"

@ssbarnea
Copy link
Contributor

ssbarnea commented Sep 1, 2025

@jdx I think that this change introduced a regression that breaks even the documentation example from https://mise.jdx.dev/environments/ for loading multiple env files.

[env]
_.file = [
    # Load env from the json file relative to this config file
    '.env.json',
    # Load env from the dotenv file at an absolute path
    '/User/bob/.env',
    # Load env from the yaml file relative to this config file and redacts the values
    { path = ".secrets.yaml", redact = true }
]
> mise config
mise ERROR TOML parse error at line 19, column 5
   |
19 |     { path = ".env.secrets", redact = true }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
invalid type: map, expected a string

I have no idea how to make it work now. I only want to redact only entries from one of the env files.

@risu729
Copy link
Contributor

risu729 commented Sep 8, 2025

I think that this change introduced a regression that breaks even the documentation example from https://mise.jdx.dev/environments/ for loading multiple env files.

[env]
_.file = [
    # Load env from the json file relative to this config file
    '.env.json',
    # Load env from the dotenv file at an absolute path
    '/User/bob/.env',
    # Load env from the yaml file relative to this config file and redacts the values
    { path = ".secrets.yaml", redact = true }
]
> mise config
mise ERROR TOML parse error at line 19, column 5
   |
19 |     { path = ".env.secrets", redact = true }
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
invalid type: map, expected a string

I have no idea how to make it work now. I only want to redact only entries from one of the env files.

Fixed in #6148

Its-Just-Nans added a commit to Its-Just-Nans/mise that referenced this pull request Sep 19, 2025
jdx pushed a commit that referenced this pull request Sep 19, 2025
@jdx jdx mentioned this pull request Sep 19, 2025
jdx added a commit that referenced this pull request Sep 19, 2025
### 📦 Registry

- remove deprecated virtualos by @jdx in
[166379f](166379f)
- add trufflehog
([aqua:trufflesecurity/trufflehog](https://github.com/trufflesecurity/trufflehog))
by @risu729 in [#6316](#6316)

### 🚀 Features

- **(aqua)** integrate native sigstore-verification for security
verification by @jdx in [#6332](#6332)
- **(docs)** improve search result readability with lighter teal
background by @jdx in [#6328](#6328)
- **(ui)** update logo as favicon and fix hover transitions by @jdx in
[#6325](#6325)
- **(vfox)** add file.read lua function by @malept in
[#6333](#6333)
- add documentation for "Environment in tasks" #5134 #5638 by
@Its-Just-Nans in [#6329](#6329)

### 🐛 Bug Fixes

- **(github)** correctly paginate releases/tags for private repos by
@malept in [#6318](#6318)
- **(hk)** exclude aqua-registry from prettier linting by @jdx in
[#6327](#6327)
- **(ui)** improve GitHub star badge layout and alignment by @jdx in
[#6326](#6326)

### 📚 Documentation

- change 'hello.py' to 'main.py' in python.md by @my1e5 in
[#6319](#6319)
- customize VitePress theme with unique branding by @jdx in
[#6324](#6324)

### 📦️ Dependency Updates

- update taiki-e/install-action digest to 0aa4f22 by @renovate[bot] in
[#6334](#6334)
- update rust crate comfy-table to v7.2.1 by @renovate[bot] in
[#6335](#6335)
- update rust crate console to v0.16.1 by @renovate[bot] in
[#6336](#6336)
- update rust crate indexmap to v2.11.4 by @renovate[bot] in
[#6337](#6337)

### Chore

- fixing typos by @Its-Just-Nans in
[#6331](#6331)

### New Contributors

- @Its-Just-Nans made their first contribution in
[#6331](#6331)
- @my1e5 made their first contribution in
[#6319](#6319)

---------

Co-authored-by: mise-en-dev <release@mise.jdx.dev>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: allow setting a .env file(s) in a task-specific env

7 participants