|
| 1 | +#!/usr/bin/env bash |
| 2 | +: ' |
| 3 | + Compares contents of `env/Version.Details.xml` between HEAD and difftarget, and emits variables named for |
| 4 | + dependencies that satisfy either of: |
| 5 | + 1. version, or sha changed |
| 6 | + 2. it is missing from one of the xmls |
| 7 | +
|
| 8 | + The dependency names have `.` replaced with `_`. |
| 9 | +
|
| 10 | + In order to consume these variables in a yaml pipeline, reference them via: $[ dependencies.<JobName>.outputs["<StepName>.<DependencyName>"] ] |
| 11 | +
|
| 12 | + Example: |
| 13 | + -difftarget ''HEAD^1'' |
| 14 | +' |
| 15 | + |
| 16 | +# Disable globbing in this bash script since we iterate over path patterns |
| 17 | +set -f |
| 18 | + |
| 19 | +# Stop script if unbound variable found (use ${var:-} if intentional) |
| 20 | +set -u |
| 21 | + |
| 22 | +# Stop script if command returns non-zero exit code. |
| 23 | +# Prevents hidden errors caused by missing error code propagation. |
| 24 | +set -e |
| 25 | + |
| 26 | +usage() |
| 27 | +{ |
| 28 | + echo "Script that emits an azure devops variable with all the dependencies that changed in 'eng/Version.Details.xml' contained in the current HEAD against the difftarget" |
| 29 | + echo " --difftarget <value> SHA or branch to diff against. (i.e: HEAD^1, origin/main, 0f4hd36, etc.)" |
| 30 | + echo " --azurevariableprefix Name of azure devops variable to create if change meets filter criteria" |
| 31 | + echo "" |
| 32 | + |
| 33 | + echo "Arguments can also be passed in with a single hyphen." |
| 34 | +} |
| 35 | + |
| 36 | +source="${BASH_SOURCE[0]}" |
| 37 | + |
| 38 | +# resolve $source until the file is no longer a symlink |
| 39 | +while [[ -h "$source" ]]; do |
| 40 | + scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" |
| 41 | + source="$(readlink "$source")" |
| 42 | + # if $source was a relative symlink, we need to resolve it relative to the path where the |
| 43 | + # symlink file was located |
| 44 | + [[ $source != /* ]] && source="$scriptroot/$source" |
| 45 | +done |
| 46 | + |
| 47 | +scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" |
| 48 | +eng_root=`cd -P "$scriptroot/.." && pwd` |
| 49 | + |
| 50 | +azure_variable_prefix='' |
| 51 | +diff_target='' |
| 52 | + |
| 53 | +while [[ $# > 0 ]]; do |
| 54 | + opt="$(echo "${1/#--/-}" | tr "[:upper:]" "[:lower:]")" |
| 55 | + case "$opt" in |
| 56 | + -help|-h) |
| 57 | + usage |
| 58 | + exit 0 |
| 59 | + ;; |
| 60 | + -difftarget) |
| 61 | + diff_target=$2 |
| 62 | + shift |
| 63 | + ;; |
| 64 | + -azurevariableprefix) |
| 65 | + azure_variable_prefix=$2 |
| 66 | + shift |
| 67 | + ;; |
| 68 | + esac |
| 69 | + |
| 70 | + shift |
| 71 | +done |
| 72 | + |
| 73 | +if [[ -z "$diff_target" ]]; then |
| 74 | + echo "Argument -difftarget is required" |
| 75 | + usage |
| 76 | + exit 1 |
| 77 | +fi |
| 78 | + |
| 79 | +oldXmlPath=`mktemp` |
| 80 | + |
| 81 | +ci=true # Needed in order to use pipeline-logging-functions.sh |
| 82 | +. "$eng_root/common/pipeline-logging-functions.sh" |
| 83 | + |
| 84 | +git show $diff_target:eng/Version.Details.xml > $oldXmlPath |
| 85 | +# FIXME: errors? |
| 86 | +changed_deps=$(python3 "$eng_root/pipelines/get-changed-darc-deps.py" $oldXmlPath eng/Version.Details.xml) |
| 87 | +rm -f $oldXmlPath |
| 88 | + |
| 89 | +if [[ -n "$azure_variable_prefix" ]]; then |
| 90 | + azure_variable_prefix="${azure_variable_prefix}_" |
| 91 | +fi |
| 92 | + |
| 93 | +for dep in $changed_deps; do |
| 94 | + dep=`echo $dep | tr \. _` |
| 95 | + var_name=${azure_variable_prefix}${dep} |
| 96 | + echo "Setting pipeline variable $var_name=true" |
| 97 | + Write-PipelineSetVariable -name $var_name -value true |
| 98 | +done |
0 commit comments