Skip to content

Commit ca0352c

Browse files
docs(site): document typed task helpers in ir.mdx and extending.mdx (#1069)
- Add tasks.rs to the Module Layout section in ir.mdx - Add new 'Typed task helpers' section to ir.mdx documenting all 9 factory functions (CopyFiles@2, DockerInstaller@0, DotNetCoreCLI@2, ArchiveFiles@2, ExtractFiles@1, PublishTestResults@2, NuGetCommand@2, PowerShell@2 file+inline modes), including required-param table, usage examples, and contributor guidance for adding new helpers - Update 'Task steps' section in extending.mdx to surface the typed helpers as the preferred pattern over raw TaskStep::new() calls, with cross-link to the ir.mdx reference Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5b648c0 commit ca0352c

2 files changed

Lines changed: 87 additions & 0 deletions

File tree

site/src/content/docs/guides/extending.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,29 @@ let step = Step::Bash(
118118

119119
### Task steps
120120

121+
When a typed factory helper exists for the ADO task you need, use it — it sets the required inputs and makes the call site self-documenting:
122+
123+
```rust
124+
use crate::compile::ir::step::Step;
125+
use crate::compile::ir::tasks::{copy_files_step, dot_net_core_cli_step};
126+
127+
// Use a typed helper — required inputs are positional, optional inputs chain on
128+
let build = Step::Task(
129+
dot_net_core_cli_step("build")
130+
.with_input("projects", "**/*.csproj")
131+
.with_input("arguments", "--configuration Release"),
132+
);
133+
134+
let copy = Step::Task(
135+
copy_files_step("**/*.nupkg", "$(Build.ArtifactStagingDirectory)")
136+
.with_input("SourceFolder", "$(Build.SourcesDirectory)/out"),
137+
);
138+
```
139+
140+
The full set of typed helpers lives in `src/compile/ir/tasks.rs` and is documented in the [IR reference](/ado-aw/reference/ir/#typed-task-helpers). Helpers cover: `CopyFiles@2`, `DockerInstaller@0`, `DotNetCoreCLI@2`, `ArchiveFiles@2`, `ExtractFiles@1`, `PublishTestResults@2`, `NuGetCommand@2`, and `PowerShell@2` (file and inline modes).
141+
142+
When no typed helper exists for your task, fall back to `TaskStep::new`:
143+
121144
```rust
122145
use crate::compile::ir::step::{Step, TaskStep};
123146

site/src/content/docs/reference/ir.mdx

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Those wrappers are the only place per-target shape (top-level `PipelineShape`, t
2222

2323
- `ids.rs` — typed `StageId`, `JobId`, and `StepId` newtypes. Constructors validate the ADO identifier grammar (`^[A-Za-z_][A-Za-z0-9_]*$`) so invalid names fail at compile time.
2424
- `step.rs``Step` and concrete step structs: `BashStep`, `TaskStep`, `CheckoutStep`, `DownloadStep`, and `PublishStep`.
25+
- `tasks.rs` — typed factory helpers for built-in ADO task steps (`CopyFiles@2`, `DockerInstaller@0`, `DotNetCoreCLI@2`, `ArchiveFiles@2`, `ExtractFiles@1`, `PublishTestResults@2`, `NuGetCommand@2`, `PowerShell@2`). Prefer these over hand-crafted `TaskStep::new()` calls — see [Typed task helpers](#typed-task-helpers) below.
2526
- `job.rs``Job`, `Pool`, job variables, 1ES `templateContext` support, and target-job external `dependsOn` / `condition` wrapping.
2627
- `stage.rs``Stage` plus target-stage external `dependsOn` / `condition` wrapping.
2728
- `env.rs` — typed environment values (`EnvValue`) including ADO macros, pipeline variables, secrets, `OutputRef`s, `Coalesce`, and macro-form `Concat`.
@@ -114,6 +115,69 @@ let synth = Step::Bash(
114115
);
115116
```
116117

118+
## Typed task helpers
119+
120+
`src/compile/ir/tasks.rs` contains typed factory functions for common ADO built-in tasks. Each function returns a pre-configured `TaskStep` with required inputs already set; optional inputs are layered on with `.with_input("key", "value")` chaining.
121+
122+
These helpers eliminate hand-crafted `TaskStep::new(…)` + raw string inputs at every call site, making task usage self-documenting and the required/optional input boundary explicit.
123+
124+
### Available helpers
125+
126+
| Function | ADO task | Required parameters |
127+
|----------|----------|---------------------|
128+
| `copy_files_step(contents, target_folder)` | `CopyFiles@2` | glob pattern; destination folder |
129+
| `docker_installer_step(docker_version)` | `DockerInstaller@0` | engine version (e.g. `"26.1.4"`) |
130+
| `dot_net_core_cli_step(command)` | `DotNetCoreCLI@2` | sub-command (`"build"`, `"test"`, `"publish"`, …) |
131+
| `archive_files_step(root_folder_or_file, archive_file)` | `ArchiveFiles@2` | source path; output archive path |
132+
| `extract_files_step(archive_file_patterns, destination_folder)` | `ExtractFiles@1` | archive glob; destination folder |
133+
| `publish_test_results_step(test_results_format, test_results_files)` | `PublishTestResults@2` | format (`"JUnit"`, `"NUnit"`, `"VSTest"`, `"XUnit"`, `"CTest"`); result file glob |
134+
| `nuget_command_step(command)` | `NuGetCommand@2` | operation (`"restore"`, `"push"`, `"pack"`, `"custom"`) |
135+
| `powershell_file_step(file_path)` | `PowerShell@2` (file mode) | path to `.ps1` script |
136+
| `powershell_inline_step(script)` | `PowerShell@2` (inline mode) | inline script body |
137+
138+
### Usage example
139+
140+
```rust
141+
use crate::compile::ir::step::Step;
142+
use crate::compile::ir::tasks::{
143+
dot_net_core_cli_step, powershell_inline_step, publish_test_results_step,
144+
};
145+
146+
// Build a .NET project — required input only
147+
let build = Step::Task(dot_net_core_cli_step("build"));
148+
149+
// Run tests with optional inputs chained on
150+
let test = Step::Task(
151+
dot_net_core_cli_step("test")
152+
.with_input("projects", "**/*Tests.csproj")
153+
.with_input("arguments", "--no-build --configuration Release")
154+
.with_input("publishTestResults", "true"),
155+
);
156+
157+
// Publish test results (required inputs set; no optional inputs needed)
158+
let publish = Step::Task(
159+
publish_test_results_step("VSTest", "**/*.trx")
160+
.with_input("failTaskOnFailedTests", "true"),
161+
);
162+
163+
// Inline PowerShell (cross-platform)
164+
let ps = Step::Task(
165+
powershell_inline_step("Write-Output 'hello'")
166+
.with_input("pwsh", "true"),
167+
);
168+
```
169+
170+
### Adding a new helper
171+
172+
When you need an ADO task that doesn't have a typed helper yet, add one to `tasks.rs`:
173+
174+
1. Write a `pub fn <name>_step(…) -> TaskStep` that sets the ADO task identifier and all **required** inputs as positional parameters.
175+
2. Document required vs. optional inputs with the `/// | Input key | Type | Default | Description |` table pattern used by existing helpers.
176+
3. Add a link to the ADO task reference at `learn.microsoft.com`.
177+
4. Write a unit test that asserts the task name, display name, and that required inputs are set with the correct keys.
178+
179+
Do **not** use `Step::RawYaml` for tasks that the IR can model. Typed helpers preserve all compiler-owned fields (`condition`, `env`, `timeout`, `continue_on_error`) and participate correctly in the graph pass.
180+
117181
## Output declarations and references
118182

119183
A producer declares a step output with `OutputDecl`:

0 commit comments

Comments
 (0)