-
Notifications
You must be signed in to change notification settings - Fork 628
Expand file tree
/
Copy pathrender_and_verify.sh
More file actions
executable file
·58 lines (51 loc) · 2.56 KB
/
render_and_verify.sh
File metadata and controls
executable file
·58 lines (51 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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')"
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"
# 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/components/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 --
echo "##[endgroup]"
fi