Fix API breakage caused by OS Plugin version scan
[releng/global-jjb.git] / jjb-compare-xml.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2017 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11
12 # This script tests jjb templates by comparing the result with expected output
13 # from global-jjb's origin/master branch.
14
15 test_dir=$(mktemp -d)
16 script_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
17 expected_xml_dir="$(mktemp -d -t gjjb-XXXXXXXX)"
18
19 echo "Script Directory: $script_dir"
20 echo "Test Directory: $test_dir"
21 echo "Expected XML Directory: $expected_xml_dir"
22
23 git fetch origin
24 gittmp="$(mktemp -d)"
25 git worktree add --detach "$gittmp" origin/master
26 pushd "$gittmp" || exit
27 echo "Generating expected XML."
28 jenkins-jobs test --recursive -o "$expected_xml_dir" "$gittmp":.jjb-test > /dev/null 2>&1
29 popd || exit
30 rm -r "$gittmp"
31
32 echo "Generating test XML."
33 jenkins-jobs test --recursive -o "$test_dir" "$script_dir":.jjb-test
34
35 fail=false
36 for xml in "$test_dir"/*; do
37     job=$(basename "$xml")
38     if ! cmp "$expected_xml_dir/$job" "$xml"; then
39         echo "Differences detected in $job"
40         diff "$expected_xml_dir/$job" "$xml"
41         fail=true
42     fi
43 done
44
45 echo "Checking for double curly braces..."
46 mapfile -t xml_files < <(find "$test_dir" -type f)
47 for xml in "${xml_files[@]}"; do
48     if grep '{{' "$xml"; then
49         echo "ERROR: Double curly braces discovered in output XML."
50         exit 1
51     fi
52 done
53 echo "No double curly braces found."
54
55 # Cleanup
56 rm -rf "$test_dir" "$expected_xml_dir"
57
58 if $fail; then
59     echo "WARN: Differences detected. Check above for jobs that have been changed."
60     exit 0
61 fi