Skip to content

Commit 7df7dc3

Browse files
committed
ci(scripts): move shared azldev helpers to scripts/components/
The 'compute_changed.sh' and 'compute_render_set.py' helpers are about to be reused by the GH Actions Check Rendered Specs gate. Move them out of the CT-only directory and trim CT-specific behavior: - Drop --publish-dir + trap (callers handle artifact publication). - Drop ADO ##[group] log markers (callers add their own per-pipeline). - Drop baked-in AZLDEV_ALLOW_ROOT step-env. azldev calls inside the helper retain an inline 'AZLDEV_ALLOW_ROOT=1' prefix per .github/instructions/ado-pipeline.instructions.md, so callers do not need to lift the restriction at step scope. - Drop the 'Upload set' jq report (CT-flow specific; moved inline to the CT pipeline YAML alongside the artifact-publish wrapper). CT pipeline call sites are updated to point at the new paths and to re-wrap the call with the log groups and publish-dir cp that used to live in the script.
1 parent 8a96471 commit 7df7dc3

5 files changed

Lines changed: 61 additions & 62 deletions

File tree

.github/workflows/ado/templates/sources-upload-stages.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,34 @@ stages:
138138
- script: |
139139
set -euo pipefail
140140
json_file="$(Build.ArtifactStagingDirectory)/changed-components/changed-components.json"
141-
.github/workflows/scripts/control-tower/compute_changed.sh \
141+
# Publish the changed-components JSON for post-mortem triage on
142+
# EVERY exit path, not just success -- if azldev hard-fails on a
143+
# consistency tripwire the partial JSON is exactly what an
144+
# operator needs to investigate.
145+
publish_artifact() {
146+
if [[ -s "$json_file" ]]; then
147+
mkdir -p "$(ob_outputDirectory)/changed-components"
148+
cp "$json_file" "$(ob_outputDirectory)/changed-components/" || true
149+
fi
150+
}
151+
trap publish_artifact EXIT
152+
153+
echo "##[group]Computing changed components"
154+
.github/workflows/scripts/components/compute_changed.sh \
142155
--output-file "$json_file" \
143-
--publish-dir "$(ob_outputDirectory)" \
144156
--source-commit "$(sourceCommit)" \
145157
--target-commit "$(targetCommit)"
158+
echo "##[endgroup]"
159+
160+
echo "##[group]Upload set (sourcesChange == true, changeType in {added, changed})"
161+
upload_count=$(jq -r '[.[] | select(.sourcesChange == true and (.changeType | IN("added", "changed")))] | length' "$json_file")
162+
jq -r '.[] | select(.sourcesChange == true and (.changeType | IN("added", "changed"))) | .component' "$json_file" | sort
163+
echo "Total: $upload_count component(s) to upload."
164+
echo "##[endgroup]"
165+
146166
echo "##vso[task.setvariable variable=changedComponentsFile;isreadonly=true]$json_file"
167+
env:
168+
AZLDEV_ALLOW_ROOT: "1"
147169
displayName: "Compute changed components"
148170
149171
# Render the components that need re-rendering (azldev-flagged plus
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
# Compute the set of changed components between source and target commits.
3+
#
4+
# Writes one JSON entry per component to <output-file>, with fields:
5+
# - component: name
6+
# - changeType: 'added' | 'changed' | 'unchanged' | 'deleted'
7+
# - sourcesChange: bool (rendered 'sources' file differs across commits)
8+
#
9+
# azldev hard-fails if any component has sourcesChange == true without a
10+
# corresponding identity change (added/changed/deleted) -- supply-chain
11+
# drift protection.
12+
#
13+
# Callers are responsible for log grouping and artifact publication. If the
14+
# host runs azldev as root (CI containers), set AZLDEV_ALLOW_ROOT=1 in the
15+
# environment.
16+
17+
set -euo pipefail
18+
19+
usage() { echo "Usage: $0 --output-file FILE --source-commit SHA --target-commit SHA" >&2; exit 1; }
20+
21+
while [[ $# -gt 0 ]]; do
22+
case "$1" in
23+
--output-file) output_file="$2"; shift 2 ;;
24+
--source-commit) source_commit="$2"; shift 2 ;;
25+
--target-commit) target_commit="$2"; shift 2 ;;
26+
*) usage ;;
27+
esac
28+
done
29+
[[ -z "${output_file:-}" || -z "${source_commit:-}" || -z "${target_commit:-}" ]] && usage
30+
31+
mkdir -p "$(dirname "$output_file")"
32+
33+
azldev component changed --from "$target_commit" --to "$source_commit" -a --include-unchanged -O json > "$output_file"
34+
35+
echo "Changed components (non-unchanged):"
36+
jq -r '.[] | select(.changeType != "unchanged") | " \(.changeType)\t\(.component)"' "$output_file" | sort

.github/workflows/scripts/control-tower/compute_render_set.py renamed to .github/workflows/scripts/components/compute_render_set.py

File renamed without changes.

.github/workflows/scripts/control-tower/compute_changed.sh

Lines changed: 0 additions & 59 deletions
This file was deleted.

.github/workflows/scripts/control-tower/render_and_verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ git diff --no-renames --name-only "$target_commit" "$source_commit" -- "$specs_d
3636
# Render set is the union of:
3737
# - components flagged by 'azldev component changed' (inputs differ)
3838
# - components whose spec tree was touched directly in the PR
39-
changed=$(python3 .github/workflows/scripts/control-tower/compute_render_set.py \
39+
changed=$(python3 .github/workflows/scripts/components/compute_render_set.py \
4040
--changed-components-file "$changed_components_file" \
4141
--specs-diff-file "$specs_diff_file" \
4242
--specs-dir "$specs_dir")

0 commit comments

Comments
 (0)