From e04633fb8fc50756033a0597ab1481e103058be1 Mon Sep 17 00:00:00 2001
From: me-no-dev <hristo@espressif.com>
Date: Mon, 30 Sep 2019 00:29:06 +0300
Subject: [PATCH 1/7] Add new builder scripts

---
 .travis.yml                            |  10 +-
 tools/ci/build-tests.sh                |  64 --------
 tools/ci/check-cmakelists.sh           |   2 -
 tools/ci/install-arduino-core-esp32.sh |  41 +++++
 tools/ci/install-arduino-ide.sh        | 210 +++++++++++++++++++++++++
 tools/ci/install-platformio-esp32.sh   | 142 +++++++++++++++++
 tools/ci/on-push.sh                    |  69 ++++++++
 7 files changed, 467 insertions(+), 71 deletions(-)
 delete mode 100755 tools/ci/build-tests.sh
 create mode 100644 tools/ci/install-arduino-core-esp32.sh
 create mode 100644 tools/ci/install-arduino-ide.sh
 create mode 100644 tools/ci/install-platformio-esp32.sh
 create mode 100755 tools/ci/on-push.sh

diff --git a/.travis.yml b/.travis.yml
index 906beec981d..0acb289d64e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,27 +21,27 @@ jobs:
     - name: "Build Arduino 0"
       if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
       stage: build
-      script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 0 4
+      script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 0 4
 
     - name: "Build Arduino 1"
       if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
       stage: build
-      script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 1 4
+      script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 1 4
 
     - name: "Build Arduino 2"
       if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
       stage: build
-      script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 2 4
+      script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 2 4
 
     - name: "Build Arduino 3"
       if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
       stage: build
-      script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 3 4
+      script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 3 4
 
     - name: "Build PlatformIO"
       if: tag IS blank AND (type = pull_request OR (type = push AND branch = master))
       stage: build
-      script: $TRAVIS_BUILD_DIR/tools/ci/build-tests.sh 4 4
+      script: $TRAVIS_BUILD_DIR/tools/ci/on-push.sh 4 4
 
     - name: "Package & Deploy"
       if: tag IS present
diff --git a/tools/ci/build-tests.sh b/tools/ci/build-tests.sh
deleted file mode 100755
index 6ec5e2feac8..00000000000
--- a/tools/ci/build-tests.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/bash
-
-if [ ! -z "$TRAVIS_TAG" ]; then
-	echo "Skipping Test: Tagged build"
-	exit 0
-fi
-
-CHUNK_INDEX=$1
-CHUNKS_CNT=$2
-BUILD_PIO=0
-if [ "$#" -lt 2 ]; then
-	echo "Building all sketches"
-	CHUNK_INDEX=0
-	CHUNKS_CNT=1
-	BUILD_PIO=1
-fi
-if [ "$CHUNKS_CNT" -le 0 ]; then
-	CHUNK_INDEX=0
-	CHUNKS_CNT=1
-	BUILD_PIO=1
-fi
-if [ "$CHUNK_INDEX" -gt "$CHUNKS_CNT" ]; then
-	CHUNK_INDEX=$CHUNKS_CNT
-fi
-if [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
-	BUILD_PIO=1
-fi
-
-# CMake Test
-if [ "$CHUNK_INDEX" -eq 0 ]; then
-	echo -e "travis_fold:start:check_cmakelists"
-	tools/ci/check-cmakelists.sh
-	if [ $? -ne 0 ]; then exit 1; fi
-	echo -e "travis_fold:end:check_cmakelists"
-fi
-
-if [ "$BUILD_PIO" -eq 0 ]; then
-	# ArduinoIDE Test
-	echo -e "travis_fold:start:prep_arduino_ide"
-	tools/ci/prep-arduino-ide.sh
-	if [ $? -ne 0 ]; then exit 1; fi
-	echo -e "travis_fold:end:prep_arduino_ide"
-
-	echo -e "travis_fold:start:test_arduino_ide"
-	tools/ci/test-arduino-ide.sh $CHUNK_INDEX $CHUNKS_CNT
-	if [ $? -ne 0 ]; then exit 1; fi
-	echo -e "travis_fold:end:test_arduino_ide"
-
-	echo -e "travis_fold:start:size_report"
-	cat size.log
-	echo -e "travis_fold:end:size_report"
-else
-	# PlatformIO Test
-	echo -e "travis_fold:start:prep_platformio"
-	cd tools && python get.py && cd ..
-	tools/ci/prep-platformio.sh
-	if [ $? -ne 0 ]; then exit 1; fi
-	echo -e "travis_fold:end:prep_platformio"
-
-	echo -e "travis_fold:start:test_platformio"
-	tools/ci/test-platformio.sh
-	if [ $? -ne 0 ]; then exit 1; fi
-	echo -e "travis_fold:end:test_platformio"
-fi
\ No newline at end of file
diff --git a/tools/ci/check-cmakelists.sh b/tools/ci/check-cmakelists.sh
index 4d11359cf80..88eb3dfbc4b 100755
--- a/tools/ci/check-cmakelists.sh
+++ b/tools/ci/check-cmakelists.sh
@@ -8,8 +8,6 @@
 
 set -e
 
-cd "`dirname $0`/.."  # cd to arduino-esp32 root
-
 # pull all submodules
 git submodule update --init --recursive
 
diff --git a/tools/ci/install-arduino-core-esp32.sh b/tools/ci/install-arduino-core-esp32.sh
new file mode 100644
index 00000000000..fb90e3bf194
--- /dev/null
+++ b/tools/ci/install-arduino-core-esp32.sh
@@ -0,0 +1,41 @@
+#!/bin/bash
+
+if [ ! -d "$ARDUINO_USR_PATH/hardware/espressif/esp32" ]; then
+	echo "Installing ESP32 Arduino Core in '$ARDUINO_USR_PATH/hardware/espressif/esp32'..."
+	script_init_path="$PWD"
+	mkdir -p "$ARDUINO_USR_PATH/hardware/espressif" && \
+	cd "$ARDUINO_USR_PATH/hardware/espressif"
+	if [ $? -ne 0 ]; then exit 1; fi
+
+	if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ];  then
+		echo "Linking Core..." && \
+		ln -s $GITHUB_WORKSPACE esp32
+	else
+		echo "Cloning Core Repository..." && \
+		git clone https://github.com/espressif/arduino-esp32.git esp32 > /dev/null 2>&1
+		if [ $? -ne 0 ]; then echo "ERROR: GIT clone failed"; exit 1; fi
+	fi
+
+	cd esp32 && \
+	echo "Updating submodules..." && \
+	git submodule update --init --recursive > /dev/null 2>&1
+	if [ $? -ne 0 ]; then echo "ERROR: Submodule update failed"; exit 1; fi
+
+	echo "Installing Python Serial..." && \
+	pip install pyserial > /dev/null
+	if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
+
+	if [ "$OS_IS_WINDOWS" == "1" ]; then
+		echo "Installing Python Requests..."
+		pip install requests > /dev/null
+		if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
+	fi
+
+	echo "Downloading the tools and the toolchain..."
+	cd tools && python get.py > /dev/null
+	if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
+	cd $script_init_path
+
+	echo "ESP32 Arduino has been installed in '$ARDUINO_USR_PATH/hardware/espressif/esp32'"
+	echo ""
+fi
diff --git a/tools/ci/install-arduino-ide.sh b/tools/ci/install-arduino-ide.sh
new file mode 100644
index 00000000000..e0979b231b4
--- /dev/null
+++ b/tools/ci/install-arduino-ide.sh
@@ -0,0 +1,210 @@
+#!/bin/bash
+
+#OSTYPE: 'linux-gnu', ARCH: 'x86_64' => linux64
+#OSTYPE: 'msys', ARCH: 'x86_64' => win32
+#OSTYPE: 'darwin18', ARCH: 'i386' => macos
+
+OSBITS=`arch`
+if [[ "$OSTYPE" == "linux"* ]]; then
+	export OS_IS_LINUX="1"
+	ARCHIVE_FORMAT="tar.xz"
+	if [[ "$OSBITS" == "i686" ]]; then
+		OS_NAME="linux32"
+	elif [[ "$OSBITS" == "x86_64" ]]; then
+		OS_NAME="linux64"
+	elif [[ "$OSBITS" == "armv7l" ]]; then
+		OS_NAME="linuxarm"
+	else
+		OS_NAME="$OSTYPE-$OSBITS"
+		echo "Unknown OS '$OS_NAME'"
+		exit 1
+	fi
+elif [[ "$OSTYPE" == "darwin"* ]]; then
+	export OS_IS_MACOS="1"
+	ARCHIVE_FORMAT="zip"
+	OS_NAME="macosx"
+elif [[ "$OSTYPE" == "cygwin" ]] || [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
+	export OS_IS_WINDOWS="1"
+	ARCHIVE_FORMAT="zip"
+	OS_NAME="windows"
+else
+	OS_NAME="$OSTYPE-$OSBITS"
+	echo "Unknown OS '$OS_NAME'"
+	exit 1
+fi
+export OS_NAME
+
+ARDUINO_BUILD_DIR="$HOME/.arduino/build.tmp"
+ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
+
+if [ "$OS_IS_MACOS" == "1" ]; then
+	export ARDUINO_IDE_PATH="/Applications/Arduino.app/Contents/Java"
+	export ARDUINO_USR_PATH="$HOME/Documents/Arduino"
+else
+	export ARDUINO_IDE_PATH="$HOME/arduino_ide"
+	export ARDUINO_USR_PATH="$HOME/Arduino"
+fi
+
+echo "Installing Arduino IDE on $OS_NAME..."
+
+if [ ! -d "$ARDUINO_IDE_PATH" ]; then
+	echo "Downloading 'arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT' to 'arduino.$ARCHIVE_FORMAT'..."
+	if [ "$OS_IS_LINUX" == "1" ]; then
+		wget -O "arduino.$ARCHIVE_FORMAT" "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
+		if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
+		echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
+		tar xf "arduino.$ARCHIVE_FORMAT" > /dev/null
+		if [ $? -ne 0 ]; then exit 1; fi
+		mv arduino-nightly "$ARDUINO_IDE_PATH"
+	else
+		curl -o "arduino.$ARCHIVE_FORMAT" -L "https://www.arduino.cc/download.php?f=/arduino-nightly-$OS_NAME.$ARCHIVE_FORMAT" > /dev/null 2>&1
+		if [ $? -ne 0 ]; then echo "ERROR: Download failed"; exit 1; fi
+		echo "Extracting 'arduino.$ARCHIVE_FORMAT'..."
+		unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
+		if [ $? -ne 0 ]; then exit 1; fi
+		if [ "$OS_IS_MACOS" == "1" ]; then
+			mv "Arduino.app" "$HOME/Arduino.app"
+		else
+			mv arduino-nightly "$ARDUINO_IDE_PATH"
+		fi
+	fi
+	if [ $? -ne 0 ]; then exit 1; fi
+	rm -rf "arduino.$ARCHIVE_FORMAT"
+fi
+
+mkdir -p "$ARDUINO_USR_PATH/libraries"
+mkdir -p "$ARDUINO_USR_PATH/hardware"
+
+function build_sketch(){ # build_sketch <fqbn> <path-to-ino> [extra-options]
+	local fqbn="$1"
+	local sketch="$2"
+	local xtra_opts="$3"
+	local win_opts=""
+	if [ "$OS_IS_WINDOWS" == "1" ]; then
+		local ctags_version=`ls "$ARDUINO_IDE_PATH/tools-builder/ctags/"`
+		local preprocessor_version=`ls "$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/"`
+		win_opts="-prefs=runtime.tools.ctags.path=$ARDUINO_IDE_PATH/tools-builder/ctags/$ctags_version -prefs=runtime.tools.arduino-preprocessor.path=$ARDUINO_IDE_PATH/tools-builder/arduino-preprocessor/$preprocessor_version"
+	fi
+
+	echo ""
+	echo "Compiling '"$(basename "$sketch")"'..."
+	mkdir -p "$ARDUINO_BUILD_DIR"
+	mkdir -p "$ARDUINO_CACHE_DIR"
+	$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=10810 \
+		-fqbn=$fqbn \
+		-warnings="all" \
+		-tools "$ARDUINO_IDE_PATH/tools-builder" \
+		-tools "$ARDUINO_IDE_PATH/tools" \
+		-built-in-libraries "$ARDUINO_IDE_PATH/libraries" \
+		-hardware "$ARDUINO_IDE_PATH/hardware" \
+		-hardware "$ARDUINO_USR_PATH/hardware" \
+		-libraries "$ARDUINO_USR_PATH/libraries" \
+		-build-cache "$ARDUINO_CACHE_DIR" \
+		-build-path "$ARDUINO_BUILD_DIR" \
+		$win_opts $xtra_opts "$sketch"
+}
+
+function count_sketches() # count_sketches <examples-path>
+{
+	local examples="$1"
+    local sketches=$(find $examples -name *.ino)
+    local sketchnum=0
+    rm -rf sketches.txt
+    for sketch in $sketches; do
+        local sketchdir=$(dirname $sketch)
+        local sketchdirname=$(basename $sketchdir)
+        local sketchname=$(basename $sketch)
+        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
+            continue
+        fi;
+        if [[ -f "$sketchdir/.test.skip" ]]; then
+            continue
+        fi
+        echo $sketch >> sketches.txt
+        sketchnum=$(($sketchnum + 1))
+    done
+    return $sketchnum
+}
+
+function build_sketches() # build_sketches <examples-path> <fqbn> <chunk> <total-chunks> [extra-options]
+{
+    local examples=$1
+    local fqbn=$2
+    local chunk_idex=$3
+    local chunks_num=$4
+    local xtra_opts=$5
+
+	if [ "$chunks_num" -le 0 ]; then
+		echo "ERROR: Chunks count must be positive number"
+		return 1
+	fi
+	if [ "$chunk_idex" -ge "$chunks_num" ]; then
+		echo "ERROR: Chunk index must be less than chunks count"
+		return 1
+	fi
+
+    count_sketches "$examples"
+    local sketchcount=$?
+    local sketches=$(cat sketches.txt)
+
+    local chunk_size=$(( $sketchcount / $chunks_num ))
+    local all_chunks=$(( $chunks_num * $chunk_size ))
+    if [ "$all_chunks" -lt "$sketchcount" ]; then
+    	chunk_size=$(( $chunk_size + 1 ))
+    fi
+
+    local start_index=$(( $chunk_idex * $chunk_size ))
+    if [ "$sketchcount" -le "$start_index" ]; then
+    	echo "Skipping job"
+    	return 0
+    fi
+
+    local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
+    if [ "$end_index" -gt "$sketchcount" ]; then
+    	end_index=$sketchcount
+    fi
+
+    local start_num=$(( $start_index + 1 ))
+    echo "Found $sketchcount Sketches";
+    echo "Chunk Count : $chunks_num"
+    echo "Chunk Size  : $chunk_size"
+    echo "Start Sketch: $start_num"
+    echo "End Sketch  : $end_index"
+
+    local sketchnum=0
+    for sketch in $sketches; do
+        local sketchdir=$(dirname $sketch)
+        local sketchdirname=$(basename $sketchdir)
+        local sketchname=$(basename $sketch)
+        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
+            #echo "Skipping $sketch, beacause it is not the main sketch file";
+            continue
+        fi;
+        if [[ -f "$sketchdir/.test.skip" ]]; then
+            #echo "Skipping $sketch marked";
+            continue
+        fi
+        sketchnum=$(($sketchnum + 1))
+        if [ "$sketchnum" -le "$start_index" ]; then
+        	#echo "Skipping $sketch index low"
+        	continue
+        fi
+        if [ "$sketchnum" -gt "$end_index" ]; then
+        	#echo "Skipping $sketch index high"
+        	continue
+        fi
+        build_sketch "$fqbn" "$sketch" "$xtra_opts"
+        local result=$?
+        if [ $result -ne 0 ]; then
+            return $result
+        fi
+    done
+    return 0
+}
+
+echo "Arduino IDE Installed in '$ARDUINO_IDE_PATH'"
+# echo "You can install boards in '$ARDUINO_IDE_PATH/hardware' or in '$ARDUINO_USR_PATH/hardware'"
+# echo "User libraries should be installed in '$ARDUINO_USR_PATH/libraries'"
+# echo "Then you can call 'build_sketch <fqbn> <path-to-ino> [extra-options]' to build your sketches"
+echo ""
+
diff --git a/tools/ci/install-platformio-esp32.sh b/tools/ci/install-platformio-esp32.sh
new file mode 100644
index 00000000000..b7761b33841
--- /dev/null
+++ b/tools/ci/install-platformio-esp32.sh
@@ -0,0 +1,142 @@
+#!/bin/bash
+
+echo "Installing Python Wheel..."
+pip install wheel > /dev/null 2>&1
+if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
+
+echo "Installing PlatformIO..."
+pip install -U https://github.com/platformio/platformio/archive/develop.zip > /dev/null 2>&1
+if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
+
+echo "Installing Platform ESP32..."
+python -m platformio platform install https://github.com/platformio/platform-espressif32.git#feature/stage > /dev/null 2>&1
+if [ $? -ne 0 ]; then echo "ERROR: Install failed"; exit 1; fi
+
+echo "Replacing the framework version..."
+if [[ "$OSTYPE" == "darwin"* ]]; then
+	sed 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json" > "platform.json" && \
+	mv -f "platform.json" "$HOME/.platformio/platforms/espressif32/platform.json"
+else
+	sed -i 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' "$HOME/.platformio/platforms/espressif32/platform.json"
+fi
+if [ $? -ne 0 ]; then echo "ERROR: Replace failed"; exit 1; fi
+
+if [ "$GITHUB_REPOSITORY" == "espressif/arduino-esp32" ];  then
+	echo "Linking Core..." && \
+	ln -s $GITHUB_WORKSPACE "$HOME/.platformio/packages/framework-arduinoespressif32"
+else
+	echo "Cloning Core Repository..." && \
+	git clone https://github.com/espressif/arduino-esp32.git "$HOME/.platformio/packages/framework-arduinoespressif32" > /dev/null 2>&1
+	if [ $? -ne 0 ]; then echo "ERROR: GIT clone failed"; exit 1; fi
+fi
+
+echo "PlatformIO for ESP32 has been installed"
+echo ""
+
+
+function build_pio_sketch(){ # build_pio_sketch <board> <path-to-ino> [extra-options]
+	local board="$1"
+	local sketch="$2"
+	local sketch_dir=$(dirname "$sketch")
+	echo ""
+	echo "Compiling '"$(basename "$sketch")"'..."
+	python -m platformio ci  --board "$board" "$sketch_dir" --project-option="board_build.partitions = huge_app.csv"
+}
+
+function count_sketches() # count_sketches <examples-path>
+{
+	local examples="$1"
+    local sketches=$(find $examples -name *.ino)
+    local sketchnum=0
+    rm -rf sketches.txt
+    for sketch in $sketches; do
+        local sketchdir=$(dirname $sketch)
+        local sketchdirname=$(basename $sketchdir)
+        local sketchname=$(basename $sketch)
+        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
+            continue
+        fi;
+        if [[ -f "$sketchdir/.test.skip" ]]; then
+            continue
+        fi
+        echo $sketch >> sketches.txt
+        sketchnum=$(($sketchnum + 1))
+    done
+    return $sketchnum
+}
+
+function build_pio_sketches() # build_pio_sketches <examples-path> <board> <chunk> <total-chunks>
+{
+    local examples=$1
+    local board=$2
+    local chunk_idex=$3
+    local chunks_num=$4
+    local xtra_opts=$5
+
+	if [ "$chunks_num" -le 0 ]; then
+		echo "ERROR: Chunks count must be positive number"
+		return 1
+	fi
+	if [ "$chunk_idex" -ge "$chunks_num" ]; then
+		echo "ERROR: Chunk index must be less than chunks count"
+		return 1
+	fi
+
+    count_sketches "$examples"
+    local sketchcount=$?
+    local sketches=$(cat sketches.txt)
+
+    local chunk_size=$(( $sketchcount / $chunks_num ))
+    local all_chunks=$(( $chunks_num * $chunk_size ))
+    if [ "$all_chunks" -lt "$sketchcount" ]; then
+    	chunk_size=$(( $chunk_size + 1 ))
+    fi
+
+    local start_index=$(( $chunk_idex * $chunk_size ))
+    if [ "$sketchcount" -le "$start_index" ]; then
+    	echo "Skipping job"
+    	return 0
+    fi
+
+    local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
+    if [ "$end_index" -gt "$sketchcount" ]; then
+    	end_index=$sketchcount
+    fi
+
+    local start_num=$(( $start_index + 1 ))
+    echo "Found $sketchcount Sketches";
+    echo "Chunk Count : $chunks_num"
+    echo "Chunk Size  : $chunk_size"
+    echo "Start Sketch: $start_num"
+    echo "End Sketch  : $end_index"
+
+    local sketchnum=0
+    for sketch in $sketches; do
+        local sketchdir=$(dirname $sketch)
+        local sketchdirname=$(basename $sketchdir)
+        local sketchname=$(basename $sketch)
+        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
+            #echo "Skipping $sketch, beacause it is not the main sketch file";
+            continue
+        fi;
+        if [[ -f "$sketchdir/.test.skip" ]]; then
+            #echo "Skipping $sketch marked";
+            continue
+        fi
+        sketchnum=$(($sketchnum + 1))
+        if [ "$sketchnum" -le "$start_index" ]; then
+        	#echo "Skipping $sketch index low"
+        	continue
+        fi
+        if [ "$sketchnum" -gt "$end_index" ]; then
+        	#echo "Skipping $sketch index high"
+        	continue
+        fi
+        build_pio_sketch "$board" "$sketch"
+        local result=$?
+        if [ $result -ne 0 ]; then
+            return $result
+        fi
+    done
+    return 0
+}
diff --git a/tools/ci/on-push.sh b/tools/ci/on-push.sh
new file mode 100755
index 00000000000..59424d211a2
--- /dev/null
+++ b/tools/ci/on-push.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+if [ ! -z "$TRAVIS_TAG" ]; then
+	echo "Skipping Test: Tagged build"
+	exit 0
+fi
+
+#GITHUB_REPOSITORY
+#GITHUB_WORKSPACE
+
+if [ ! -z "$GITHUB_WORKSPACE" ]; then
+	export TRAVIS_BUILD_DIR="$GITHUB_WORKSPACE"
+	export TRAVIS_REPO_SLUG="$GITHUB_REPOSITORY"
+elif [ ! -z "$TRAVIS_BUILD_DIR" ]; then
+	export GITHUB_WORKSPACE="$TRAVIS_BUILD_DIR"
+	export GITHUB_REPOSITORY="$TRAVIS_REPO_SLUG"
+else
+	export GITHUB_WORKSPACE="$PWD"
+	export GITHUB_REPOSITORY="espressif/arduino-esp32"
+fi
+
+CHUNK_INDEX=$1
+CHUNKS_CNT=$2
+BUILD_PIO=0
+if [ "$#" -lt 2 ] ||  [ "$CHUNKS_CNT" -le 0 ]; then
+	echo "Building all sketches"
+	CHUNK_INDEX=0
+	CHUNKS_CNT=1
+fi
+if [ "$CHUNK_INDEX" -gt "$CHUNKS_CNT" ]; then
+	CHUNK_INDEX=$CHUNKS_CNT
+fi
+if [ "$CHUNK_INDEX" -eq "$CHUNKS_CNT" ]; then
+	BUILD_PIO=1
+fi
+
+# CMake Test
+if [ "$CHUNK_INDEX" -eq 0 ]; then
+	bash ./tools/ci/check-cmakelists.sh
+	if [ $? -ne 0 ]; then exit 1; fi
+fi
+
+if [ "$BUILD_PIO" -eq 0 ]; then
+	# ArduinoIDE Test
+	# tools/ci/prep-arduino-ide.sh
+	# if [ $? -ne 0 ]; then exit 1; fi
+	# tools/ci/test-arduino-ide.sh $CHUNK_INDEX $CHUNKS_CNT
+	# if [ $? -ne 0 ]; then exit 1; fi
+	# cat size.log
+	source ./tools/ci/install-arduino-ide.sh
+	source ./tools/ci/install-arduino-core-esp32.sh
+	build_sketches "$ARDUINO_USR_PATH/hardware/espressif/esp32/libraries" "espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" "$CHUNK_INDEX" "$CHUNKS_CNT"
+else
+	# PlatformIO Test
+	# cd tools && python get.py && cd ..
+	# tools/ci/prep-platformio.sh
+	# if [ $? -ne 0 ]; then exit 1; fi
+	# tools/ci/test-platformio.sh
+	# if [ $? -ne 0 ]; then exit 1; fi
+	source ./tools/ci/install-platformio-esp32.sh
+	python -m platformio ci  --board esp32dev libraries/WiFi/examples/WiFiClient && \
+	python -m platformio ci  --board esp32dev libraries/WiFiClientSecure/examples/WiFiClientSecure && \
+	python -m platformio ci  --board esp32dev libraries/BluetoothSerial/examples/SerialToSerialBT && \
+	python -m platformio ci  --board esp32dev libraries/BLE/examples/BLE_server && \
+	python -m platformio ci  --board esp32dev libraries/AzureIoT/examples/GetStarted && \
+	python -m platformio ci  --board esp32dev libraries/ESP32/examples/Camera/CameraWebServer --project-option="board_build.partitions = huge_app.csv"
+	#build_pio_sketches libraries "esp32dev" "$CHUNK_INDEX" "$CHUNKS_CNT"
+	if [ $? -ne 0 ]; then exit 1; fi
+fi
\ No newline at end of file

From 83a05e9948bffe9f046febb15d6a5421e2f8f914 Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Mon, 30 Sep 2019 00:47:13 +0300
Subject: [PATCH 2/7] Update main.yml

---
 .github/workflows/main.yml | 380 +++----------------------------------
 1 file changed, 30 insertions(+), 350 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 22130009c64..a5319bc5af3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -9,370 +9,50 @@ on:
 
 jobs:
 
-  build-arduino-0:
-    name: Build Arduino IDE Tests 0
+  build-arduino-linux:
+    name: Build Arduino ${{ matrix.chunk }} on ubuntu-latest
     runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
     
     steps:
     - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Run CMake Check
-      run: ./tools/ci/check-cmakelists.sh
+    - name: Build Sketches
+      run: ./tools/ci/on-push ${{ matrix.chunk }} 11
 
-    - name: Install Arduino IDE
-      env:
-        #ESP32_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 0 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-1:
-    name: Build Arduino IDE Tests 1
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 1 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-2:
-    name: Build Arduino IDE Tests 2
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 2 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-3:
-    name: Build Arduino IDE Tests 3
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 3 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-4:
-    name: Build Arduino IDE Tests 4
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 4 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-5:
-    name: Build Arduino IDE Tests 5
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 5 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-6:
-    name: Build Arduino IDE Tests 6
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 6 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-7:
-    name: Build Arduino IDE Tests 7
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 7 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-8:
-    name: Build Arduino IDE Tests 8
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 8 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-9:
-    name: Build Arduino IDE Tests 9
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 9 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-10:
-    name: Build Arduino IDE Tests 10
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 10 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-11:
-    name: Build Arduino IDE Tests 11
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 11 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-12:
-    name: Build Arduino IDE Tests 12
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 12 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-13:
-    name: Build Arduino IDE Tests 13
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 13 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-14:
-    name: Build Arduino IDE Tests 14
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 14 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-15:
-    name: Build Arduino IDE Tests 15
-    runs-on: ubuntu-latest
-    
-    steps:
-    - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 15 18
-    - name: Sketch Sizes
-      run: cat size.log
-
-  build-arduino-16:
-    name: Build Arduino IDE Tests 16
-    runs-on: ubuntu-latest
+  build-arduino-mac:
+    name: Build Arduino ${{ matrix.chunk }} on macOS-latest
+    runs-on: macOS-latest
+    strategy:
+      matrix:
+        chunk: [5, 10, 15]
     
     steps:
     - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 16 18
-    - name: Sketch Sizes
-      run: cat size.log
+    - name: Build Sketches
+      run: ./tools/ci/on-push ${{ matrix.chunk }} 20
 
-  build-arduino-17:
-    name: Build Arduino IDE Tests 17
-    runs-on: ubuntu-latest
+  build-arduino-win:
+    name: Build Arduino ${{ matrix.chunk }} on windows-latest
+    runs-on: windows-latest
+    strategy:
+      matrix:
+        chunk: [5, 15, 25]
     
     steps:
     - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-arduino-ide.sh
-    - name: Test Arduino IDE
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/test-arduino-ide.sh 17 18
-    - name: Sketch Sizes
-      run: cat size.log
-
+    - name: Build Sketches
+      run: ./tools/ci/on-push ${{ matrix.chunk }} 30
 
   build-platformio:
-    name: Build PlatformIO Tests
-    runs-on: ubuntu-latest
+    name: Build PlatformIO on ${{ matrix.os }}
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ubuntu-latest, windows-latest, macOS-latest]
     
     steps:
     - uses: actions/checkout@v1
-    - name: Pull submodules
-      run: git submodule update --init --recursive
-    - name: Install Python Wheel
-      run: pip install wheel
-    - name: Install GCC Toolchain
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: cd tools && python get.py
-    - name: Install PlatformIO
-      env:
-        TRAVIS_BUILD_DIR: ${{ github.workspace }}
-      run: ./tools/ci/prep-platformio.sh
-    - name: Test PlatformIO
-      run: ./tools/ci/test-platformio.sh
+    - name: Build Sketches
+      run: ./tools/ci/on-push 1 1

From 3794e67c1d38beb62e9b23808492fc3f66125785 Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Mon, 30 Sep 2019 00:49:17 +0300
Subject: [PATCH 3/7] Update main.yml

---
 .github/workflows/main.yml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index a5319bc5af3..23003b97651 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -19,7 +19,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: ./tools/ci/on-push ${{ matrix.chunk }} 11
+      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 11
 
   build-arduino-mac:
     name: Build Arduino ${{ matrix.chunk }} on macOS-latest
@@ -31,7 +31,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: ./tools/ci/on-push ${{ matrix.chunk }} 20
+      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 20
 
   build-arduino-win:
     name: Build Arduino ${{ matrix.chunk }} on windows-latest
@@ -43,7 +43,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: ./tools/ci/on-push ${{ matrix.chunk }} 30
+      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 30
 
   build-platformio:
     name: Build PlatformIO on ${{ matrix.os }}
@@ -55,4 +55,4 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: ./tools/ci/on-push 1 1
+      run: bash ./tools/ci/on-push 1 1

From 8b96be37de29a0ffda79940fbc6c5f537a9e004b Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Mon, 30 Sep 2019 00:51:12 +0300
Subject: [PATCH 4/7] Update main.yml

---
 .github/workflows/main.yml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 23003b97651..de593aabb8e 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -19,7 +19,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 11
+      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 11
 
   build-arduino-mac:
     name: Build Arduino ${{ matrix.chunk }} on macOS-latest
@@ -31,7 +31,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 20
+      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 20
 
   build-arduino-win:
     name: Build Arduino ${{ matrix.chunk }} on windows-latest
@@ -43,7 +43,7 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push ${{ matrix.chunk }} 30
+      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 30
 
   build-platformio:
     name: Build PlatformIO on ${{ matrix.os }}
@@ -55,4 +55,4 @@ jobs:
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push 1 1
+      run: bash ./tools/ci/on-push.sh 1 1

From bb56db639428df6d64503b9a635432d3c71544b1 Mon Sep 17 00:00:00 2001
From: me-no-dev <hristo@espressif.com>
Date: Mon, 30 Sep 2019 01:03:44 +0300
Subject: [PATCH 5/7] fix mac install

---
 tools/ci/install-arduino-ide.sh |   2 +-
 tools/ci/on-push.sh             |  15 +--
 tools/ci/prep-arduino-ide.sh    |  13 ---
 tools/ci/prep-platformio.sh     |   6 --
 tools/ci/test-arduino-ide.sh    | 170 --------------------------------
 tools/ci/test-platformio.sh     |   9 --
 6 files changed, 2 insertions(+), 213 deletions(-)
 delete mode 100755 tools/ci/prep-arduino-ide.sh
 delete mode 100755 tools/ci/prep-platformio.sh
 delete mode 100755 tools/ci/test-arduino-ide.sh
 delete mode 100755 tools/ci/test-platformio.sh

diff --git a/tools/ci/install-arduino-ide.sh b/tools/ci/install-arduino-ide.sh
index e0979b231b4..75d083ddb09 100644
--- a/tools/ci/install-arduino-ide.sh
+++ b/tools/ci/install-arduino-ide.sh
@@ -63,7 +63,7 @@ if [ ! -d "$ARDUINO_IDE_PATH" ]; then
 		unzip "arduino.$ARCHIVE_FORMAT" > /dev/null
 		if [ $? -ne 0 ]; then exit 1; fi
 		if [ "$OS_IS_MACOS" == "1" ]; then
-			mv "Arduino.app" "$HOME/Arduino.app"
+			mv "Arduino.app" "/Applications/Arduino.app"
 		else
 			mv arduino-nightly "$ARDUINO_IDE_PATH"
 		fi
diff --git a/tools/ci/on-push.sh b/tools/ci/on-push.sh
index 59424d211a2..c19e2c2a82c 100755
--- a/tools/ci/on-push.sh
+++ b/tools/ci/on-push.sh
@@ -5,9 +5,6 @@ if [ ! -z "$TRAVIS_TAG" ]; then
 	exit 0
 fi
 
-#GITHUB_REPOSITORY
-#GITHUB_WORKSPACE
-
 if [ ! -z "$GITHUB_WORKSPACE" ]; then
 	export TRAVIS_BUILD_DIR="$GITHUB_WORKSPACE"
 	export TRAVIS_REPO_SLUG="$GITHUB_REPOSITORY"
@@ -42,21 +39,11 @@ fi
 
 if [ "$BUILD_PIO" -eq 0 ]; then
 	# ArduinoIDE Test
-	# tools/ci/prep-arduino-ide.sh
-	# if [ $? -ne 0 ]; then exit 1; fi
-	# tools/ci/test-arduino-ide.sh $CHUNK_INDEX $CHUNKS_CNT
-	# if [ $? -ne 0 ]; then exit 1; fi
-	# cat size.log
 	source ./tools/ci/install-arduino-ide.sh
 	source ./tools/ci/install-arduino-core-esp32.sh
-	build_sketches "$ARDUINO_USR_PATH/hardware/espressif/esp32/libraries" "espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" "$CHUNK_INDEX" "$CHUNKS_CNT"
+	build_sketches "$GITHUB_WORKSPACE/libraries" "espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app" "$CHUNK_INDEX" "$CHUNKS_CNT"
 else
 	# PlatformIO Test
-	# cd tools && python get.py && cd ..
-	# tools/ci/prep-platformio.sh
-	# if [ $? -ne 0 ]; then exit 1; fi
-	# tools/ci/test-platformio.sh
-	# if [ $? -ne 0 ]; then exit 1; fi
 	source ./tools/ci/install-platformio-esp32.sh
 	python -m platformio ci  --board esp32dev libraries/WiFi/examples/WiFiClient && \
 	python -m platformio ci  --board esp32dev libraries/WiFiClientSecure/examples/WiFiClientSecure && \
diff --git a/tools/ci/prep-arduino-ide.sh b/tools/ci/prep-arduino-ide.sh
deleted file mode 100755
index 90c8d397386..00000000000
--- a/tools/ci/prep-arduino-ide.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-pip install pyserial
-wget -O arduino.tar.xz https://www.arduino.cc/download.php?f=/arduino-nightly-linux64.tar.xz
-tar xf arduino.tar.xz
-mv arduino-nightly $HOME/arduino_ide
-mkdir -p $HOME/Arduino/libraries
-mkdir -p $HOME/Arduino/hardware/espressif
-cd $HOME/Arduino/hardware/espressif
-
-ln -s $TRAVIS_BUILD_DIR esp32
-cd esp32/tools
-python get.py
diff --git a/tools/ci/prep-platformio.sh b/tools/ci/prep-platformio.sh
deleted file mode 100755
index dbcb444d25e..00000000000
--- a/tools/ci/prep-platformio.sh
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-
-pip install -U https://github.com/platformio/platformio/archive/develop.zip && \
-python -m platformio platform install https://github.com/platformio/platform-espressif32.git#feature/stage && \
-sed -i 's/https:\/\/github\.com\/espressif\/arduino-esp32\.git/*/' ~/.platformio/platforms/espressif32/platform.json && \
-ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif32
diff --git a/tools/ci/test-arduino-ide.sh b/tools/ci/test-arduino-ide.sh
deleted file mode 100755
index f902ce27214..00000000000
--- a/tools/ci/test-arduino-ide.sh
+++ /dev/null
@@ -1,170 +0,0 @@
-#!/bin/bash
-
-CHUNK_INDEX=$1
-CHUNKS_CNT=$2
-if [ "$#" -lt 2 ]; then
-	echo "Building all sketches"
-	CHUNK_INDEX=0
-	CHUNKS_CNT=1
-fi
-if [ "$CHUNKS_CNT" -le 0 ]; then
-	echo "Chunks count must be positive number"
-	exit 1
-fi
-if [ "$CHUNK_INDEX" -ge "$CHUNKS_CNT" ]; then
-	echo "Chunk index must be less than chunks count"
-	exit 1
-fi
-
-export ARDUINO_BOARD_FQBN="espressif:esp32:esp32:PSRAM=enabled,PartitionScheme=huge_app,CPUFreq=240,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none"
-
-export ARDUINO_IDE_PATH=$HOME/arduino_ide
-export ARDUINO_USR_PATH=$HOME/Arduino
-
-export EXAMPLES_PATH=$TRAVIS_BUILD_DIR/libraries
-export EXAMPLES_BUILD_DIR=$HOME/build.tmp
-export EXAMPLES_CACHE_DIR=$HOME/cache.tmp
-export EXAMPLES_BUILD_CMD="$ARDUINO_IDE_PATH/arduino-builder -compile -logger=human -core-api-version=\"10810\" -hardware \"$ARDUINO_IDE_PATH/hardware\" -hardware \"$ARDUINO_USR_PATH/hardware\" -tools \"$ARDUINO_IDE_PATH/tools-builder\" -built-in-libraries \"$ARDUINO_IDE_PATH/libraries\" -libraries \"$ARDUINO_USR_PATH/libraries\" -fqbn=$ARDUINO_BOARD_FQBN -warnings=\"all\" -build-cache \"$EXAMPLES_CACHE_DIR\" -build-path \"$EXAMPLES_BUILD_DIR\" -verbose"
-export EXAMPLES_SIZE_BIN=$TRAVIS_BUILD_DIR/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-size
-
-function print_size_info()
-{
-    elf_file=$1
-
-    if [ -z "$elf_file" ]; then
-        printf "sketch                           iram0.text flash.text flash.rodata dram0.data dram0.bss    dram     flash\n"
-        return 0
-    fi
-
-    elf_name=$(basename $elf_file)
-    sketch_name="${elf_name%.*}"
-    # echo $sketch_name
-    declare -A segments
-    while read -a tokens; do
-        seg=${tokens[0]}
-        seg=${seg//./}
-        size=${tokens[1]}
-        addr=${tokens[2]}
-        if [ "$addr" -eq "$addr" -a "$addr" -ne "0" ] 2>/dev/null; then
-            segments[$seg]=$size
-        fi
-    done < <($EXAMPLES_SIZE_BIN --format=sysv $elf_file)
-
-    total_ram=$((${segments[dram0data]} + ${segments[dram0bss]}))
-    total_flash=$((${segments[iram0text]} + ${segments[flashtext]} + ${segments[dram0data]} + ${segments[flashrodata]}))
-    printf "%-32s %-8d   %-8d   %-8d     %-8d   %-8d     %-8d %-8d\n" $sketch_name ${segments[iram0text]} ${segments[flashtext]} ${segments[flashrodata]} ${segments[dram0data]} ${segments[dram0bss]} $total_ram $total_flash
-    return 0
-}
-
-function build_sketch()
-{
-	local sketch=$1
-    echo -e "\n------------ Building $sketch ------------\n";
-    rm -rf $EXAMPLES_BUILD_DIR/*
-    time ($EXAMPLES_BUILD_CMD $sketch >build.log)
-    local result=$?
-    if [ $result -ne 0 ]; then
-        echo "Build failed ($1)"
-        echo "Build log:"
-        cat build.log
-        return $result
-    fi
-    rm build.log
-    return 0
-}
-
-function count_sketches()
-{
-    local sketches=$(find $EXAMPLES_PATH -name *.ino)
-    local sketchnum=0
-    rm -rf sketches.txt
-    for sketch in $sketches; do
-        local sketchdir=$(dirname $sketch)
-        local sketchdirname=$(basename $sketchdir)
-        local sketchname=$(basename $sketch)
-        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
-            continue
-        fi;
-        if [[ -f "$sketchdir/.test.skip" ]]; then
-            continue
-        fi
-        echo $sketch >> sketches.txt
-        sketchnum=$(($sketchnum + 1))
-    done
-    return $sketchnum
-}
-
-function build_sketches()
-{
-    mkdir -p $EXAMPLES_BUILD_DIR
-    mkdir -p $EXAMPLES_CACHE_DIR
-    mkdir -p $ARDUINO_USR_PATH/libraries
-    mkdir -p $ARDUINO_USR_PATH/hardware
-    
-    local chunk_idex=$1
-    local chunks_num=$2
-    count_sketches
-    local sketchcount=$?
-    local sketches=$(cat sketches.txt)
-
-    local chunk_size=$(( $sketchcount / $chunks_num ))
-    local all_chunks=$(( $chunks_num * $chunk_size ))
-    if [ "$all_chunks" -lt "$sketchcount" ]; then
-    	chunk_size=$(( $chunk_size + 1 ))
-    fi
-
-    local start_index=$(( $chunk_idex * $chunk_size ))
-    if [ "$sketchcount" -le "$start_index" ]; then
-    	echo "Skipping job"
-    	return 0
-    fi
-
-    local end_index=$(( $(( $chunk_idex + 1 )) * $chunk_size ))
-    if [ "$end_index" -gt "$sketchcount" ]; then
-    	end_index=$sketchcount
-    fi
-
-    local start_num=$(( $start_index + 1 ))
-    #echo -e "Sketches: \n$sketches\n"
-    echo "Found $sketchcount Sketches";
-    echo "Chunk Count : $chunks_num"
-    echo "Chunk Size  : $chunk_size"
-    echo "Start Sketch: $start_num"
-    echo "End Sketch  : $end_index"
-
-    local sketchnum=0
-    print_size_info >size.log
-    for sketch in $sketches; do
-        local sketchdir=$(dirname $sketch)
-        local sketchdirname=$(basename $sketchdir)
-        local sketchname=$(basename $sketch)
-        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
-            #echo "Skipping $sketch, beacause it is not the main sketch file";
-            continue
-        fi;
-        if [[ -f "$sketchdir/.test.skip" ]]; then
-            #echo "Skipping $sketch marked";
-            continue
-        fi
-        sketchnum=$(($sketchnum + 1))
-        if [ "$sketchnum" -le "$start_index" ]; then
-        	#echo "Skipping $sketch index low"
-        	continue
-        fi
-        if [ "$sketchnum" -gt "$end_index" ]; then
-        	#echo "Skipping $sketch index high"
-        	continue
-        fi
-        build_sketch $sketch
-        local result=$?
-        if [ $result -ne 0 ]; then
-            return $result
-        fi
-        print_size_info $EXAMPLES_BUILD_DIR/*.elf >>size.log
-    done
-    return 0
-}
-
-build_sketches $CHUNK_INDEX $CHUNKS_CNT
-
-if [ $? -ne 0 ]; then exit 1; fi
diff --git a/tools/ci/test-platformio.sh b/tools/ci/test-platformio.sh
deleted file mode 100755
index f699595b1c4..00000000000
--- a/tools/ci/test-platformio.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-python -m platformio ci  --board esp32dev libraries/WiFi/examples/WiFiClient && \
-python -m platformio ci  --board esp32dev libraries/WiFiClientSecure/examples/WiFiClientSecure && \
-python -m platformio ci  --board esp32dev libraries/BluetoothSerial/examples/SerialToSerialBT && \
-python -m platformio ci  --board esp32dev libraries/BLE/examples/BLE_server && \
-python -m platformio ci  --board esp32dev libraries/AzureIoT/examples/GetStarted && \
-python -m platformio ci  --board esp32dev libraries/ESP32/examples/Camera/CameraWebServer --project-option="board_build.partitions = huge_app.csv"
-if [ $? -ne 0 ]; then exit 1; fi

From 3ad865cf5c784ac3c4fddd25682dfc2468c02dc4 Mon Sep 17 00:00:00 2001
From: me-no-dev <hristo@espressif.com>
Date: Mon, 30 Sep 2019 01:34:27 +0300
Subject: [PATCH 6/7] script cleanup

---
 tools/ci/install-arduino-ide.sh      | 17 +++++------------
 tools/ci/install-platformio-esp32.sh | 18 +++++-------------
 tools/ci/on-push.sh                  |  2 +-
 3 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/tools/ci/install-arduino-ide.sh b/tools/ci/install-arduino-ide.sh
index 75d083ddb09..05e10edfac8 100644
--- a/tools/ci/install-arduino-ide.sh
+++ b/tools/ci/install-arduino-ide.sh
@@ -146,6 +146,7 @@ function build_sketches() # build_sketches <examples-path> <fqbn> <chunk> <total
     count_sketches "$examples"
     local sketchcount=$?
     local sketches=$(cat sketches.txt)
+    rm -rf sketches.txt
 
     local chunk_size=$(( $sketchcount / $chunks_num ))
     local all_chunks=$(( $chunks_num * $chunk_size ))
@@ -176,21 +177,13 @@ function build_sketches() # build_sketches <examples-path> <fqbn> <chunk> <total
         local sketchdir=$(dirname $sketch)
         local sketchdirname=$(basename $sketchdir)
         local sketchname=$(basename $sketch)
-        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
-            #echo "Skipping $sketch, beacause it is not the main sketch file";
-            continue
-        fi;
-        if [[ -f "$sketchdir/.test.skip" ]]; then
-            #echo "Skipping $sketch marked";
+        if [ "${sketchdirname}.ino" != "$sketchname" ] \
+        || [ -f "$sketchdir/.test.skip" ]; then
             continue
         fi
         sketchnum=$(($sketchnum + 1))
-        if [ "$sketchnum" -le "$start_index" ]; then
-        	#echo "Skipping $sketch index low"
-        	continue
-        fi
-        if [ "$sketchnum" -gt "$end_index" ]; then
-        	#echo "Skipping $sketch index high"
+        if [ "$sketchnum" -le "$start_index" ] \
+        || [ "$sketchnum" -gt "$end_index" ]; then
         	continue
         fi
         build_sketch "$fqbn" "$sketch" "$xtra_opts"
diff --git a/tools/ci/install-platformio-esp32.sh b/tools/ci/install-platformio-esp32.sh
index b7761b33841..503e7d0095e 100644
--- a/tools/ci/install-platformio-esp32.sh
+++ b/tools/ci/install-platformio-esp32.sh
@@ -71,7 +71,6 @@ function build_pio_sketches() # build_pio_sketches <examples-path> <board> <chun
     local board=$2
     local chunk_idex=$3
     local chunks_num=$4
-    local xtra_opts=$5
 
 	if [ "$chunks_num" -le 0 ]; then
 		echo "ERROR: Chunks count must be positive number"
@@ -85,6 +84,7 @@ function build_pio_sketches() # build_pio_sketches <examples-path> <board> <chun
     count_sketches "$examples"
     local sketchcount=$?
     local sketches=$(cat sketches.txt)
+    rm -rf sketches.txt
 
     local chunk_size=$(( $sketchcount / $chunks_num ))
     local all_chunks=$(( $chunks_num * $chunk_size ))
@@ -115,21 +115,13 @@ function build_pio_sketches() # build_pio_sketches <examples-path> <board> <chun
         local sketchdir=$(dirname $sketch)
         local sketchdirname=$(basename $sketchdir)
         local sketchname=$(basename $sketch)
-        if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
-            #echo "Skipping $sketch, beacause it is not the main sketch file";
-            continue
-        fi;
-        if [[ -f "$sketchdir/.test.skip" ]]; then
-            #echo "Skipping $sketch marked";
+        if [ "${sketchdirname}.ino" != "$sketchname" ] \
+        || [ -f "$sketchdir/.test.skip" ]; then
             continue
         fi
         sketchnum=$(($sketchnum + 1))
-        if [ "$sketchnum" -le "$start_index" ]; then
-        	#echo "Skipping $sketch index low"
-        	continue
-        fi
-        if [ "$sketchnum" -gt "$end_index" ]; then
-        	#echo "Skipping $sketch index high"
+        if [ "$sketchnum" -le "$start_index" ] \
+        || [ "$sketchnum" -gt "$end_index" ]; then
         	continue
         fi
         build_pio_sketch "$board" "$sketch"
diff --git a/tools/ci/on-push.sh b/tools/ci/on-push.sh
index c19e2c2a82c..7fbb477e67f 100755
--- a/tools/ci/on-push.sh
+++ b/tools/ci/on-push.sh
@@ -51,6 +51,6 @@ else
 	python -m platformio ci  --board esp32dev libraries/BLE/examples/BLE_server && \
 	python -m platformio ci  --board esp32dev libraries/AzureIoT/examples/GetStarted && \
 	python -m platformio ci  --board esp32dev libraries/ESP32/examples/Camera/CameraWebServer --project-option="board_build.partitions = huge_app.csv"
-	#build_pio_sketches libraries "esp32dev" "$CHUNK_INDEX" "$CHUNKS_CNT"
+	#build_pio_sketches libraries esp32dev $CHUNK_INDEX $CHUNKS_CNT
 	if [ $? -ne 0 ]; then exit 1; fi
 fi
\ No newline at end of file

From 8eb377cbb614e73f33e9df265355529f25f69fa2 Mon Sep 17 00:00:00 2001
From: Me No Dev <me-no-dev@users.noreply.github.com>
Date: Mon, 30 Sep 2019 01:48:23 +0300
Subject: [PATCH 7/7] Update main.yml

---
 .github/workflows/main.yml | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index de593aabb8e..b56dcbf9761 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -10,31 +10,31 @@ on:
 jobs:
 
   build-arduino-linux:
-    name: Build Arduino ${{ matrix.chunk }} on ubuntu-latest
+    name: Arduino ${{ matrix.chunk }} on ubuntu-latest
     runs-on: ubuntu-latest
     strategy:
       matrix:
-        chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+        chunk: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
     
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 11
+      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 12
 
   build-arduino-mac:
-    name: Build Arduino ${{ matrix.chunk }} on macOS-latest
+    name: Arduino ${{ matrix.chunk }} on macOS-latest
     runs-on: macOS-latest
     strategy:
       matrix:
-        chunk: [5, 10, 15]
+        chunk: [3, 6]
     
     steps:
     - uses: actions/checkout@v1
     - name: Build Sketches
-      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 20
+      run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 12
 
   build-arduino-win:
-    name: Build Arduino ${{ matrix.chunk }} on windows-latest
+    name: Arduino ${{ matrix.chunk }} on windows-latest
     runs-on: windows-latest
     strategy:
       matrix:
@@ -46,7 +46,7 @@ jobs:
       run: bash ./tools/ci/on-push.sh ${{ matrix.chunk }} 30
 
   build-platformio:
-    name: Build PlatformIO on ${{ matrix.os }}
+    name: PlatformIO on ${{ matrix.os }}
     runs-on: ${{ matrix.os }}
     strategy:
       matrix: