2
2
3
3
# Get inputs from command
4
4
owner_repository=$1
5
- pr_number =$2
5
+ base_ref =$2
6
6
7
- url= " https://api.github.com/repos/ $owner_repository /pulls/ $pr_number /files "
8
- echo $url
7
+ # Download the boards.txt file from the base branch
8
+ curl -L -o boards_base.txt https://raw.githubusercontent.com/ " $owner_repository " / " $base_ref " /boards.txt
9
9
10
- # Get changes in boards.txt file from PR
11
- Patch =$( curl $url | jq -r ' .[] | select(.filename == " boards.txt") | .patch ' )
10
+ # Compare boards.txt file in the repo with the modified file from PR
11
+ diff =$( diff -u boards_base.txt boards.txt)
12
12
13
- # Extract only changed lines number and count
14
- substring_patch=$( echo " $Patch " | grep -o ' @@[^@]*@@' )
13
+ # Check if the diff is empty
14
+ if [ -z " $diff " ]; then
15
+ echo " No changes in boards.txt file"
16
+ echo " FQBNS="
17
+ exit 0
18
+ fi
15
19
16
- params_array=()
20
+ # Extract added or modified lines (lines starting with '+' or '-')
21
+ modified_lines=$( echo " $diff " | grep -E ' ^[+-][^+-]' )
17
22
18
- IFS=$' \n ' read -d ' ' -ra params <<< $( echo " $substring_patch " | grep -oE ' [-+][0-9]+,[0-9]+' )
19
-
20
- for param in " ${params[@]} "
21
- do
22
- echo " The parameter is $param "
23
- params_array+=(" $param " )
24
- done
23
+ # Print the modified lines for debugging
24
+ echo " Modified lines:"
25
+ echo " $modified_lines "
25
26
26
27
boards_array=()
27
28
previous_board=" "
28
- file=" boards.txt"
29
-
30
- # Loop through boards.txt file and extract all boards that were added
31
- for (( c= 0 ; c< ${# params_array[@]} ; c+= 2 ))
32
- do
33
- deletion_count=$( echo " ${params_array[c]} " | cut -d' ,' -f2 | cut -d' ' -f1 )
34
- addition_line=$( echo " ${params_array[c+1]} " | cut -d' +' -f2 | cut -d' ,' -f1 )
35
- addition_count=$( echo " ${params_array[c+1]} " | cut -d' +' -f2 | cut -d' ,' -f2 | cut -d' ' -f1 )
36
- addition_end=$(( $addition_line + $addition_count ))
37
-
38
- addition_line=$(( $addition_line + 3 ))
39
- addition_end=$(( $addition_end - $deletion_count ))
40
-
41
- echo $addition_line
42
- echo $addition_end
43
29
44
- i=0
45
-
46
- while read -r line
47
- do
48
- i=$(( i+ 1 ))
49
- if [ $i -lt $addition_line ]
50
- then
51
- continue
52
- elif [ $i -gt $addition_end ]
53
- then
54
- break
55
- fi
30
+ # Extract board names from the modified lines, and add them to the boards_array
31
+ while read -r line; do
56
32
board_name=$( echo " $line " | cut -d ' .' -f1 | cut -d ' #' -f1)
57
- if [ " $board_name " != " " ] && [ " $board_name " != " esp32_family " ]
58
- then
59
- if [ " $board_name " != " $previous_board " ]
60
- then
33
+ # remove + or - from the board name at the beginning
34
+ board_name= ${board_name # [-+]}
35
+ if [ " $board_name " != " " ] && [ " $board_name " != " + " ] && [ " $board_name " != " - " ] && [ " $board_name " != " esp32_family " ] ; then
36
+ if [ " $board_name " != " $previous_board " ] ; then
61
37
boards_array+=(" espressif:esp32:$board_name " )
62
38
previous_board=" $board_name "
63
39
echo " Added 'espressif:esp32:$board_name ' to array"
64
40
fi
65
41
fi
66
- done < " $file "
67
- done
42
+ done <<< " $modified_lines"
68
43
69
44
# Create JSON like string with all boards found and pass it to env variable
70
45
board_count=${# boards_array[@]}
71
46
72
- if [ $board_count -gt 0 ]
73
- then
47
+ if [ " $board_count " -gt 0 ]; then
74
48
json_matrix=' {"fqbn": ['
75
- for board in ${boards_array[@]}
76
- do
49
+ for board in " ${boards_array[@]} " ; do
77
50
json_matrix+=' "' $board ' "'
78
- if [ $board_count -gt 1 ]
79
- then
51
+ if [ " $board_count " -gt 1 ]; then
80
52
json_matrix+=" ,"
81
53
fi
82
- board_count=$(( $ board_count - 1 ))
54
+ board_count=$(( board_count - 1 ))
83
55
done
84
56
json_matrix+=' ]}'
85
57
86
- echo $json_matrix
87
- echo " FQBNS=${json_matrix} " >> $GITHUB_ENV
58
+ echo " $json_matrix "
59
+ echo " FQBNS=${json_matrix} " >> " $GITHUB_ENV "
88
60
else
89
- echo " FQBNS=" >> $GITHUB_ENV
90
- fi
61
+ echo " FQBNS=" >> " $GITHUB_ENV "
62
+ fi
0 commit comments