Skip to content

Commit 7575218

Browse files
feat(executor): auto-capture ADO build variables in ExecutionContext (#378)
* feat(executor): auto-capture ADO build variables in ExecutionContext Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/814f3245-184d-4610-9c1f-f251b9825eca Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> * refactor(test): simplify env_from helper signature Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/814f3245-184d-4610-9c1f-f251b9825eca Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
1 parent 05fede2 commit 7575218

6 files changed

Lines changed: 234 additions & 17 deletions

File tree

src/execute.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ fn log_execution_context(safe_output_dir: &Path, ctx: &ExecutionContext) {
145145
debug!("ADO project: {}", ctx.ado_project.as_deref().unwrap_or("<not set>"));
146146
debug!("Repository ID: {}", ctx.repository_id.as_deref().unwrap_or("<not set>"));
147147
debug!("Repository name: {}", ctx.repository_name.as_deref().unwrap_or("<not set>"));
148+
debug!(
149+
"Build ID: {}",
150+
ctx.build_id
151+
.map(|id| id.to_string())
152+
.unwrap_or_else(|| "<not set>".to_string())
153+
);
154+
debug!("Build reason: {}", ctx.build_reason.as_deref().unwrap_or("<not set>"));
155+
debug!(
156+
"Triggered by definition: {}",
157+
ctx.triggered_by_definition_name.as_deref().unwrap_or("<not set>")
158+
);
148159
if !ctx.allowed_repositories.is_empty() {
149160
debug!(
150161
"Allowed repositories: {}",
@@ -376,6 +387,7 @@ mod tests {
376387
allowed_repositories: HashMap::new(),
377388
agent_stats: None,
378389
dry_run: false,
390+
..Default::default()
379391
};
380392

381393
let result = execute_safe_output(&entry, &ctx).await;
@@ -410,6 +422,7 @@ mod tests {
410422
allowed_repositories: HashMap::new(),
411423
agent_stats: None,
412424
dry_run: false,
425+
..Default::default()
413426
};
414427

415428
let result = execute_safe_output(&entry, &ctx).await;
@@ -560,6 +573,7 @@ mod tests {
560573
allowed_repositories: HashMap::new(),
561574
agent_stats: None,
562575
dry_run: false,
576+
..Default::default()
563577
};
564578

565579
let result = execute_safe_output(&entry, &ctx).await;
@@ -604,6 +618,7 @@ mod tests {
604618
allowed_repositories: HashMap::new(),
605619
agent_stats: None,
606620
dry_run: false,
621+
..Default::default()
607622
};
608623

609624
let result = execute_safe_output(&entry, &ctx).await;
@@ -648,6 +663,7 @@ mod tests {
648663
allowed_repositories: HashMap::new(),
649664
agent_stats: None,
650665
dry_run: false,
666+
..Default::default()
651667
};
652668

653669
let result = execute_safe_output(&entry, &ctx).await;
@@ -697,6 +713,7 @@ mod tests {
697713
allowed_repositories: HashMap::new(),
698714
agent_stats: None,
699715
dry_run: false,
716+
..Default::default()
700717
};
701718

702719
let results = execute_safe_outputs(temp_dir.path(), &ctx).await;
@@ -907,6 +924,7 @@ mod tests {
907924
allowed_repositories: HashMap::new(),
908925
agent_stats: None,
909926
dry_run: false,
927+
..Default::default()
910928
};
911929

912930
let results = execute_safe_outputs(temp_dir.path(), &ctx).await;
@@ -952,6 +970,7 @@ mod tests {
952970
allowed_repositories: HashMap::new(),
953971
agent_stats: None,
954972
dry_run: false,
973+
..Default::default()
955974
};
956975

957976
let results = execute_safe_outputs(temp_dir.path(), &ctx).await.unwrap();
@@ -1055,6 +1074,7 @@ mod tests {
10551074
allowed_repositories: HashMap::new(),
10561075
agent_stats: None,
10571076
dry_run: false,
1077+
..Default::default()
10581078
};
10591079

10601080
let result = execute_safe_output(&entry, &ctx).await;
@@ -1084,6 +1104,7 @@ mod tests {
10841104
allowed_repositories: HashMap::new(),
10851105
agent_stats: None,
10861106
dry_run: true,
1107+
..Default::default()
10871108
};
10881109

10891110
let result = execute_safe_output(&entry, &ctx).await;

src/safeoutputs/add_build_tag.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,11 @@ impl Executor for AddBuildTagResult {
135135

136136
// 2b. Scope check: by default only the current build can be tagged
137137
if !config.allow_any_build {
138-
let current_build_id: Option<i32> = std::env::var("BUILD_BUILDID")
139-
.ok()
140-
.and_then(|s| s.parse().ok());
138+
// Pulled from ctx (sourced from BUILD_BUILDID); narrowed to i32 to
139+
// match the agent-supplied build_id type.
140+
let current_build_id: Option<i32> = ctx
141+
.build_id
142+
.and_then(|id| i32::try_from(id).ok());
141143
if let Some(current_id) = current_build_id {
142144
if self.build_id != current_id {
143145
return Ok(ExecutionResult::failure(format!(
@@ -147,7 +149,7 @@ impl Executor for AddBuildTagResult {
147149
)));
148150
}
149151
}
150-
// If BUILD_BUILDID is not set (e.g. local execution), allow any build
152+
// If build_id is not set (e.g. local execution), allow any build
151153
}
152154

153155
// 3. Apply tag prefix if configured

src/safeoutputs/create_wiki_page.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ wiki-name: "MyProject.wiki"
701701
allowed_repositories: std::collections::HashMap::new(),
702702
agent_stats: None,
703703
dry_run: false,
704+
..Default::default()
704705
};
705706

706707
// wiki-name not in config → should return Err
@@ -766,6 +767,7 @@ wiki-name: "MyProject.wiki"
766767
allowed_repositories: HashMap::new(),
767768
agent_stats: None,
768769
dry_run: false,
770+
..Default::default()
769771
};
770772

771773
let outcome = result.execute_impl(&ctx).await.unwrap();
@@ -806,6 +808,7 @@ wiki-name: "MyProject.wiki"
806808
allowed_repositories: HashMap::new(),
807809
agent_stats: None,
808810
dry_run: false,
811+
..Default::default()
809812
};
810813

811814
let outcome = result.execute_impl(&ctx).await.unwrap();
@@ -846,6 +849,7 @@ wiki-name: "MyProject.wiki"
846849
allowed_repositories: HashMap::new(),
847850
agent_stats: None,
848851
dry_run: false,
852+
..Default::default()
849853
};
850854

851855
// The GET will fail (network unreachable with a fake host), so the

0 commit comments

Comments
 (0)