-
Notifications
You must be signed in to change notification settings - Fork 626
ci(prcheck): use 'azldev component changed' for affected-component detection #17065
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
Merged
christopherco
merged 1 commit into
microsoft:tomls/base/main
from
dmcilvaney:damcilva/4.0/pipelines/delta_2_changed_detection
May 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.github/workflows/scripts/control-tower/compute_changed.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #!/usr/bin/env bash | ||
| # Compute the set of changed components between source and target commits. | ||
| # | ||
| # Writes the JSON to <output-file> and copies it into <publish-dir>/changed-components/ | ||
| # for triage artifact publication. | ||
| # | ||
| # 'azldev component changed' compares the source and target commits and emits | ||
| # one entry per component with its 'changeType' ('added', 'changed', | ||
| # 'unchanged', or 'deleted') plus a 'sourcesChange' flag indicating whether | ||
| # the rendered 'sources' file differs between commits. | ||
| # | ||
| # azldev hard-fails if any component has sourcesChange == true without a | ||
| # corresponding identity change (added/changed/deleted) -- supply-chain | ||
| # drift protection. | ||
| # | ||
| # Only components with sourcesChange == true AND changeType in {added, changed} | ||
| # are forwarded to Control Tower for upload. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| usage() { echo "Usage: $0 --output-file FILE --publish-dir DIR --source-commit SHA --target-commit SHA" >&2; exit 1; } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --output-file) output_file="$2"; shift 2 ;; | ||
| --publish-dir) publish_dir="$2"; shift 2 ;; | ||
| --source-commit) source_commit="$2"; shift 2 ;; | ||
| --target-commit) target_commit="$2"; shift 2 ;; | ||
| *) usage ;; | ||
| esac | ||
| done | ||
| [[ -z "${output_file:-}" || -z "${publish_dir:-}" || -z "${source_commit:-}" || -z "${target_commit:-}" ]] && usage | ||
|
|
||
| mkdir -p "$(dirname "$output_file")" | ||
|
|
||
| # Publish the changed-components JSON for post-mortem triage on EVERY exit | ||
| # path, not just success -- if azldev hard-fails on a consistency tripwire | ||
| # the partial JSON is exactly what an operator needs to investigate. | ||
| publish_artifact() { | ||
| if [[ -s "$output_file" ]]; then | ||
| mkdir -p "$publish_dir/changed-components" | ||
| cp "$output_file" "$publish_dir/changed-components/" || true | ||
| fi | ||
| } | ||
| trap publish_artifact EXIT | ||
|
christopherco marked this conversation as resolved.
|
||
|
|
||
| echo "##[group]Computing changed components" | ||
| AZLDEV_ALLOW_ROOT=1 azldev component changed --from "$target_commit" --to "$source_commit" -a --include-unchanged -O json > "$output_file" | ||
| echo "##[endgroup]" | ||
|
|
||
| echo "##[group]Changed components (non-unchanged only)" | ||
| jq '[.[] | select(.changeType != "unchanged")]' "$output_file" | ||
| echo "##[endgroup]" | ||
|
|
||
| echo "##[group]Upload set (sourcesChange == true, changeType in {added, changed})" | ||
| upload_count=$(jq -r '[.[] | select(.sourcesChange == true and (.changeType | IN("added", "changed")))] | length' "$output_file") | ||
| jq -r '.[] | select(.sourcesChange == true and (.changeType | IN("added", "changed"))) | .component' "$output_file" | sort | ||
| echo "Total: $upload_count component(s) to upload." | ||
| echo "##[endgroup]" | ||
86 changes: 86 additions & 0 deletions
86
.github/workflows/scripts/control-tower/compute_render_set.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Compute the render set: components flagged by `azldev component changed` | ||
| plus components whose spec tree was touched directly in the PR. | ||
|
|
||
| Emits one component name per line on stdout (azldev dedupes internally). | ||
| """ | ||
|
|
||
| import argparse | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| def _load_entries(path: Path) -> list[dict]: | ||
| """Load the changed-components JSON.""" | ||
| return json.loads(path.read_text(encoding="utf-8")) | ||
|
|
||
|
|
||
|
dmcilvaney marked this conversation as resolved.
|
||
| def _renderable_components(entries: list[dict]) -> set[str]: | ||
| """Component names that azldev can still render (everything except deleted).""" | ||
| return {e["component"] for e in entries if e.get("changeType") != "deleted"} | ||
|
|
||
|
|
||
| def from_changed(entries: list[dict]) -> list[str]: | ||
| """Components from `azldev component changed` JSON. | ||
|
|
||
| Includes anything that is not 'deleted' and either has a non-'unchanged' | ||
| changeType or has sourcesChange=true (safety net). | ||
| """ | ||
| out = [] | ||
| for e in entries: | ||
| change_type = e.get("changeType") | ||
| sources_change = e.get("sourcesChange") is True | ||
| if change_type == "deleted": | ||
| continue | ||
| if change_type == "unchanged" and not sources_change: | ||
| continue | ||
| out.append(e["component"]) | ||
|
dmcilvaney marked this conversation as resolved.
|
||
| return out | ||
|
|
||
|
|
||
| def from_specs_diff(path: Path, specs_dir: Path, renderable: set[str]) -> list[str]: | ||
| """Components with any modified file under specs_dir. | ||
|
|
||
| Spec layout is rigid: <specs_dir>/<first-char>/<component>/... | ||
| so the component name is the second segment under specs_dir. | ||
|
|
||
| Only components in ``renderable`` are included -- a deleted component's | ||
| .comp.toml is gone so ``azldev component render`` would fail, and a | ||
| path that doesn't map to any known component is noise. | ||
| """ | ||
| prefix = str(specs_dir).rstrip("/") + "/" | ||
| out = [] | ||
| for line in path.read_text(encoding="utf-8").splitlines(): | ||
| if not line.startswith(prefix): | ||
| continue | ||
| parts = line[len(prefix) :].split("/", 2) | ||
| if len(parts) >= 2 and parts[1]: | ||
| name = parts[1] | ||
| if name in renderable: | ||
| out.append(name) | ||
| return out | ||
|
|
||
|
|
||
| def main() -> None: | ||
| p = argparse.ArgumentParser() | ||
| p.add_argument("--changed-components-file", type=Path, required=True) | ||
| p.add_argument("--specs-diff-file", type=Path, required=True) | ||
| p.add_argument("--specs-dir", type=Path, required=True) | ||
| args = p.parse_args() | ||
|
|
||
| entries = _load_entries(args.changed_components_file) | ||
| renderable = _renderable_components(entries) | ||
|
|
||
| # Dedupe across both sources -- a component appearing in azldev's | ||
| # changed list AND with hand-edited specs would otherwise print twice, | ||
| # and a component with N modified spec files would print N times. | ||
| # dict.fromkeys preserves first-seen order. | ||
| names = dict.fromkeys([ | ||
| *from_changed(entries), | ||
| *from_specs_diff(args.specs_diff_file, args.specs_dir, renderable), | ||
| ]) | ||
| for name in names: | ||
| print(name) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
58 changes: 58 additions & 0 deletions
58
.github/workflows/scripts/control-tower/render_and_verify.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| # Render changed specs and verify the rendered tree is clean. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| usage() { echo "Usage: $0 --output-dir DIR --changed-components-file FILE --source-commit SHA --target-commit SHA" >&2; exit 1; } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| case "$1" in | ||
| --output-dir) output_dir="$2"; shift 2 ;; | ||
| --changed-components-file) changed_components_file="$2"; shift 2 ;; | ||
| --source-commit) source_commit="$2"; shift 2 ;; | ||
| --target-commit) target_commit="$2"; shift 2 ;; | ||
| *) usage ;; | ||
| esac | ||
| done | ||
| [[ -z "${output_dir:-}" || -z "${changed_components_file:-}" || -z "${source_commit:-}" || -z "${target_commit:-}" ]] && usage | ||
|
|
||
| # azldev's renderedSpecsDir is absolute. Translate to repo-relative | ||
| # so it matches git's output ('git diff --name-only' always emits | ||
| # repo-relative paths regardless of the path arg form). | ||
| specs_dir_abs="$(AZLDEV_ALLOW_ROOT=1 azldev config dump -q -f json | jq -r '.project.renderedSpecsDir')" | ||
|
christopherco marked this conversation as resolved.
|
||
| specs_dir="$(realpath --relative-to="$(pwd)" "$specs_dir_abs")" | ||
|
|
||
| # Capture git diff under the specs tree so the render set can | ||
| # include components whose specs were edited directly (which | ||
| # azldev's input-fingerprint view of "changed" would miss). | ||
| # --no-renames prevents collapse of delete+add into a rename | ||
| # entry which would lose the old path. The Python script | ||
| # filters out deleted/unknown components using the full | ||
| # changed-components JSON. | ||
| mkdir -p "$output_dir" | ||
| specs_diff_file="$output_dir/specs-diff.txt" | ||
| git diff --no-renames --name-only "$target_commit" "$source_commit" -- "$specs_dir" > "$specs_diff_file" | ||
|
dmcilvaney marked this conversation as resolved.
|
||
|
|
||
| # Render set is the union of: | ||
| # - components flagged by 'azldev component changed' (inputs differ) | ||
| # - components whose spec tree was touched directly in the PR | ||
| changed=$(python3 .github/workflows/scripts/control-tower/compute_render_set.py \ | ||
| --changed-components-file "$changed_components_file" \ | ||
| --specs-diff-file "$specs_diff_file" \ | ||
| --specs-dir "$specs_dir") | ||
|
|
||
| if [[ -z "$changed" ]]; then | ||
| echo "No changed components -- skipping render." | ||
| else | ||
| changed_count=$(echo "$changed" | wc -l) | ||
| echo "Rendering $changed_count component(s) (azldev dedupes internally)..." | ||
| echo "##[group]Render set" | ||
| # shellcheck disable=SC2001 | ||
| echo "$changed" | sed 's/^/ - /' | ||
| echo "##[endgroup]" | ||
| echo "##[group]Specs rendering + verification" | ||
| # --check-only renders to a staging area and diffs against on-disk specs. | ||
| # Exits nonzero if any rendered file differs from what's committed. | ||
| printf '%s\n' "$changed" | xargs -d '\n' env AZLDEV_ALLOW_ROOT=1 azldev component render --check-only -- | ||
|
dmcilvaney marked this conversation as resolved.
|
||
| echo "##[endgroup]" | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.