From 56148f7c1a02569a19d0e376f53a454e83598da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 11 Apr 2023 13:29:36 +0200 Subject: [PATCH 1/3] New board test Workflow + script Create boards.yml Update boards.yml Update boards.yml Update boards.yml Add board to test Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml Update boards.yml separate script to file Update board_test.sh edit Update board_test.sh Update board_test.sh Update boards.yml Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh add compilation run Update boards.yml Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh Update board_test.sh Update boards.yml Update boards.yml Update ENV variable Update boards.yml Update boards.yml Update boards.yml Remove dbg job do error in boards.txt and add another one Comments, clear code + new inputs Owner fix Update boards.yml Adjust changed lines by +-3 Update board_test.sh Update board_test.sh Add deletion count for adjusting line number Add failure Rename of script and action --- .github/scripts/find_new_boards.sh | 85 ++++++++++++++++++++++++++++++ .github/workflows/boards.yml | 63 ++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100755 .github/scripts/find_new_boards.sh create mode 100644 .github/workflows/boards.yml diff --git a/.github/scripts/find_new_boards.sh b/.github/scripts/find_new_boards.sh new file mode 100755 index 00000000000..cd78633ffde --- /dev/null +++ b/.github/scripts/find_new_boards.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Get inputs from command +owner_repository=$1 +pr_number=$2 + +url="https://api.github.com/repos/$owner_repository/pulls/$pr_number/files" +echo $url + +# Get changes in boards.txt file from PR +Patch=$(curl $url | jq -r '.[] | select(.filename == "boards.txt") | .patch ') + +# Extract only changed lines number and count +substring_patch=$(echo "$Patch" | grep -o '@@[^@]*@@') + +params_array=() + +IFS=$'\n' read -d '' -ra params <<< $(echo "$substring_patch" | grep -oE '[-+][0-9]+,[0-9]+') + +for param in "${params[@]}" +do + echo "The parameter is $param" + params_array+=("$param") +done + +boards_array=() +previous_board="" +file="boards.txt" + +# Loop through boards.txt file and extract all boards that were added +for (( c=0; c<${#params_array[@]}; c+=2 )) +do + deletion_count=$( echo "${params_array[c]}" | cut -d',' -f2 | cut -d' ' -f1 ) + addition_line=$( echo "${params_array[c+1]}" | cut -d'+' -f2 | cut -d',' -f1 ) + addition_count=$( echo "${params_array[c+1]}" | cut -d'+' -f2 | cut -d',' -f2 | cut -d' ' -f1 ) + addition_end=$(($addition_line+$addition_count)) + + addition_line=$(($addition_line + 3)) + addition_end=$(($addition_end - $deletion_count)) + + echo $addition_line + echo $addition_end + + i=0 + + while read -r line + do + i=$((i+1)) + if [ $i -lt $addition_line ] + then + continue + elif [ $i -gt $addition_end ] + then + break + fi + board_name=$(echo "$line" | cut -d '.' -f1 | cut -d '#' -f1) + if [ "$board_name" != "" ] + then + if [ "$board_name" != "$previous_board" ] + then + boards_array+=("espressif:esp32:$board_name") + previous_board="$board_name" + echo "Added 'espressif:esp32:$board_name' to array" + fi + fi + done < "$file" +done + +# Create JSON like string with all boards found and pass it to env variable +board_count=${#boards_array[@]} + +json_matrix='{"fqbn": [' +for board in ${boards_array[@]} +do + json_matrix+='"'$board'"' + if [ $board_count -gt 1 ] + then + json_matrix+="," + fi + board_count=$(($board_count - 1)) +done +json_matrix+=']}' + +echo $json_matrix +echo "FQBNS=${json_matrix}" >> $GITHUB_ENV diff --git a/.github/workflows/boards.yml b/.github/workflows/boards.yml new file mode 100644 index 00000000000..8a1e0d77fd5 --- /dev/null +++ b/.github/workflows/boards.yml @@ -0,0 +1,63 @@ +name: New Board Test + +# The workflow will run on schedule and labeled pull requests +on: + pull_request: + types: [opened, reopened, synchronize, labeled] + +env: + # It's convenient to set variables for values used multiple times in the workflow + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + +jobs: + find-boards: + if: | + contains(github.event.pull_request.labels.*.name, 'board_test') + runs-on: ubuntu-latest + + outputs: + fqbns: ${{ env.FQBNS }} + + steps: + # This step makes the contents of the repository available to the workflow + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup jq + uses: dcarbone/install-jq-action@v1.0.1 + + - name: Get board name + run: + bash .github/scripts/find_new_boards.sh ${{ github.repository }} ${{github.event.number}} + + test-boards: + needs: find-boards + runs-on: ubuntu-latest + + env: + REPOSITORY: | + - source-path: '.' + name: "espressif:esp32" + + strategy: + matrix: ${{ fromJson(needs.find-boards.outputs.fqbns) }} + + steps: + # This step makes the contents of the repository available to the workflow + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Compile sketch + uses: P-R-O-C-H-Y/compile-sketches@main + with: + platforms: | + ${{ env.REPOSITORY }} + fqbn: ${{ matrix.fqbn }} + use-json-file: false + enable-deltas-report: false + enable-warnings-report: false + cli-compile-flags: | + - --warnings="all" + exit-on-fail: true + sketch-paths: + "- ./libraries/ESP32/examples/ChipID/GetChipID/GetChipID.ino" From cc463534d2a283ef2a973fe820cd35d6fef796e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:33:25 +0200 Subject: [PATCH 2/3] Add check if fqbn is empty --- .github/scripts/find_new_boards.sh | 30 +++++++++++++++++------------- .github/workflows/boards.yml | 4 +--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.github/scripts/find_new_boards.sh b/.github/scripts/find_new_boards.sh index cd78633ffde..858be3d8ad6 100755 --- a/.github/scripts/find_new_boards.sh +++ b/.github/scripts/find_new_boards.sh @@ -69,17 +69,21 @@ done # Create JSON like string with all boards found and pass it to env variable board_count=${#boards_array[@]} -json_matrix='{"fqbn": [' -for board in ${boards_array[@]} -do - json_matrix+='"'$board'"' - if [ $board_count -gt 1 ] - then - json_matrix+="," - fi - board_count=$(($board_count - 1)) -done -json_matrix+=']}' +if [ $board_count -gt 0 ] +then + json_matrix='{"fqbn": [' + for board in ${boards_array[@]} + do + json_matrix+='"'$board'"' + if [ $board_count -gt 1 ] + then + json_matrix+="," + fi + board_count=$(($board_count - 1)) + done + json_matrix+=']}' -echo $json_matrix -echo "FQBNS=${json_matrix}" >> $GITHUB_ENV + echo $json_matrix + echo "FQBNS=${json_matrix}" >> $GITHUB_ENV +else + echo "FQBNS=''" >> $GITHUB_ENV \ No newline at end of file diff --git a/.github/workflows/boards.yml b/.github/workflows/boards.yml index 8a1e0d77fd5..9fda906439d 100644 --- a/.github/workflows/boards.yml +++ b/.github/workflows/boards.yml @@ -3,7 +3,6 @@ name: New Board Test # The workflow will run on schedule and labeled pull requests on: pull_request: - types: [opened, reopened, synchronize, labeled] env: # It's convenient to set variables for values used multiple times in the workflow @@ -11,8 +10,6 @@ env: jobs: find-boards: - if: | - contains(github.event.pull_request.labels.*.name, 'board_test') runs-on: ubuntu-latest outputs: @@ -33,6 +30,7 @@ jobs: test-boards: needs: find-boards runs-on: ubuntu-latest + if: ${{ needs.changes.outputs.services != '' }} env: REPOSITORY: | From 39d7ecb8e5df4d2fcf43680f3461131fc4bcfec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Procha=CC=81zka?= <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Thu, 13 Apr 2023 14:35:38 +0200 Subject: [PATCH 3/3] Update find_new_boards.sh --- .github/scripts/find_new_boards.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/scripts/find_new_boards.sh b/.github/scripts/find_new_boards.sh index 858be3d8ad6..e09a2ae97a7 100755 --- a/.github/scripts/find_new_boards.sh +++ b/.github/scripts/find_new_boards.sh @@ -86,4 +86,5 @@ then echo $json_matrix echo "FQBNS=${json_matrix}" >> $GITHUB_ENV else - echo "FQBNS=''" >> $GITHUB_ENV \ No newline at end of file + echo "FQBNS=''" >> $GITHUB_ENV +fi \ No newline at end of file