6 # SPDX-license-identifier: Apache-2.0
7 ##############################################################################
8 # Copyright (c) 2016 Linux Foundation and others.
9 # All rights reserved. This program and the accompanying materials
10 # are made available under the terms of the Apache License, Version 2.0
11 # which accompanies this distribution, and is available at
12 # http://www.apache.org/licenses/LICENSE-2.0
13 ##############################################################################
15 # Job Number Formatter
18 if [ $NUMS == 1 ]; then
25 # We expect job_output to exist prior to this being run and contain the
26 # output from jenkins-jobs test
28 echo "> Generating list of previous JJB jobs..."
29 git checkout -q -b previous-commit HEAD^
30 jenkins-jobs -l ERROR test -r jjb -o job_output_prev
31 git checkout -q - && git branch -q -d previous-commit
33 echo "> Finding job changes ..."
34 diff -r -q job_output job_output_prev &> job_diff.txt || true
36 # Only in (job_output) = NEW
37 # Only in (job_output_prev) = DELETED
38 # Files ... differ = MODIFIED
40 declare -a JOBS_ADDED=($(grep 'job_output:' job_diff.txt | cut -d':' -f2- | sed 's/^[ \t]*//;s/[ \t]*$//'))
41 declare -a JOBS_MODIFIED=($(grep 'differ$' job_diff.txt | sed "s/Files job_output\/\(.*\) and.*/\1/g"))
42 declare -a JOBS_REMOVED=($(grep 'job_output_prev:' job_diff.txt | cut -d ':' -f2- | sed 's/^[ \t]*//;s/[ \t]*$//'))
44 NUM_JOBS_ADDED=${#JOBS_ADDED[@]}
45 NUM_JOBS_MODIFIED=${#JOBS_MODIFIED[@]}
46 NUM_JOBS_REMOVED=${#JOBS_REMOVED[@]}
48 echo "> Writing gerrit comment ..."
49 if [ $NUM_JOBS_ADDED -gt 0 ]; then
50 JOB_STRING="$(JOBS $NUM_JOBS_ADDED)"
51 { printf "Added %s %s:\n\n" "${NUM_JOBS_ADDED}" "$JOB_STRING";
52 printf '* %s\n' "${JOBS_ADDED[@]}";
53 printf "\n"; } >> gerrit_comment.txt
56 if [ $NUM_JOBS_MODIFIED -gt 0 ]; then
57 JOB_STRING="$(JOBS $NUM_JOBS_MODIFIED)"
58 { printf "Modified %s %s:\n\n" "${NUM_JOBS_MODIFIED}" "$JOB_STRING";
59 printf '* %s\n' "${JOBS_MODIFIED[@]}";
60 printf "\n"; } >> gerrit_comment.txt
63 if [ $NUM_JOBS_REMOVED -gt 0 ]; then
64 JOB_STRING="$(JOBS $NUM_JOBS_REMOVED)"
65 { printf "Removed %s %s:\n\n" "${NUM_JOBS_REMOVED}" "$JOB_STRING";
66 printf '* %s\n' "${JOBS_REMOVED[@]}";
67 printf "\n"; } >> gerrit_comment.txt