Skip to content

Split common.sh into separate scripts for each job #5569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,49 +20,50 @@ stages:
jobs:
include:
# Build stage. To save time, run all kinds of builds and tests in parallel.
# TODO: since we can now call different script for each job,
# split the do-it-all common.sh into separate scripts responsible
# for different types of jobs below:

- name: "Platformio (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
env:
- BUILD_TYPE=platformio_even
- BUILD_PARITY=even
- name: "Platformio (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/platformio.sh
env:
- BUILD_TYPE=platformio_odd
- BUILD_PARITY=odd

- name: "Build (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/build.sh
env:
- BUILD_TYPE=build_even
- BUILD_PARITY=even
- name: "Build (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/build.sh
env:
- BUILD_TYPE=build_odd
- BUILD_PARITY=odd

- name: "Debug (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/debug.sh
env:
- BUILD_TYPE=debug_even
- BUILD_PARITY=even
- name: "Debug (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/debug.sh
env:
- BUILD_TYPE=debug_odd
- BUILD_PARITY=odd

- name: "Build IPv6 (1)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/build6.sh
env:
- BUILD_TYPE=build6_even
- BUILD_PARITY=even
- name: "Build IPv6 (2)"
stage: build
script: $TRAVIS_BUILD_DIR/tests/common.sh
script: $TRAVIS_BUILD_DIR/tests/build6.sh
env:
- BUILD_TYPE=build6_odd
- BUILD_PARITY=odd

- name: "Host tests"
stage: build
Expand Down
22 changes: 22 additions & 0 deletions tests/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

cache_dir=$(mktemp -d)

source "$TRAVIS_BUILD_DIR"/tests/common.sh

if [ -z "$BUILD_PARITY" ]; then
mod=1
rem=0
elif [ "$BUILD_PARITY" = "even" ]; then
mod=2
rem=0
elif [ "$BUILD_PARITY" = "odd" ]; then
mod=2
rem=1
fi

install_arduino nodebug
build_sketches_with_arduino "$mod" "$rem" lm2f

rm -rf "$cache_dir"

22 changes: 22 additions & 0 deletions tests/build6.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

cache_dir=$(mktemp -d)

source "$TRAVIS_BUILD_DIR"/tests/common.sh

if [ -z "$BUILD_PARITY" ]; then
mod=1
rem=0
elif [ "$BUILD_PARITY" = "even" ]; then
mod=2
rem=0
elif [ "$BUILD_PARITY" = "odd" ]; then
mod=2
rem=1
fi

install_arduino nodebug
build_sketches_with_arduino "$mod" "$rem" lm6f

rm -rf "$cache_dir"

98 changes: 0 additions & 98 deletions tests/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -141,59 +141,6 @@ function install_ide()
export PATH="$ide_path:$core_path/tools/xtensa-lx106-elf/bin:$PATH"
}

function install_platformio()
{
pip install --user -U https://github.com/platformio/platformio/archive/develop.zip
platformio platform install "https://github.com/platformio/platform-espressif8266.git#feature/stage"
sed -i 's/https:\/\/github\.com\/esp8266\/Arduino\.git/*/' ~/.platformio/platforms/espressif8266/platform.json
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
# Install dependencies:
# - esp8266/examples/ConfigFile
pio lib install ArduinoJson
}

function build_sketches_with_platformio()
{
set +e
local srcpath=$1
local build_arg=$2
local build_mod=$3
local build_rem=$4
local sketches=$(find $srcpath -name *.ino | sort)
local testcnt=0
for sketch in $sketches; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
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 -e "\n ------------ Skipping $sketch ------------ \n";
continue
fi
local build_cmd="pio ci $sketchdir $build_arg"
echo -e "\n ------------ Building $sketch ------------ \n";
echo "$build_cmd"
time ($build_cmd >build.log)
local result=$?
if [ $result -ne 0 ]; then
echo "Build failed ($1)"
echo "Build log:"
cat build.log
set -e
return $result
fi
rm build.log
done
set -e
}

function install_arduino()
{
local debug=$1
Expand Down Expand Up @@ -235,48 +182,3 @@ if [ -z "$TRAVIS_BUILD_DIR" ]; then
echo "TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR"
fi

cache_dir=$(mktemp -d)

if [ "$BUILD_TYPE" = "build" ]; then
install_arduino nodebug
build_sketches_with_arduino 1 0 lm2f
elif [ "$BUILD_TYPE" = "build6" ]; then
install_arduino nodebug
build_sketches_with_arduino 1 0 lm6f
elif [ "$BUILD_TYPE" = "build_even" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 0 lm2f
elif [ "$BUILD_TYPE" = "build_odd" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 1 lm2f
elif [ "$BUILD_TYPE" = "debug_even" ]; then
install_arduino debug
build_sketches_with_arduino 2 0 lm2f
elif [ "$BUILD_TYPE" = "debug_odd" ]; then
install_arduino debug
build_sketches_with_arduino 2 1 lm2f
elif [ "$BUILD_TYPE" = "build6_even" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 0 lm6f
elif [ "$BUILD_TYPE" = "build6_odd" ]; then
install_arduino nodebug
build_sketches_with_arduino 2 1 lm6f
elif [ "$BUILD_TYPE" = "platformio" ]; then
# PlatformIO
install_platformio
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 1 0
elif [ "$BUILD_TYPE" = "platformio_even" ]; then
# PlatformIO
install_platformio
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 0
elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
# PlatformIO
install_platformio
build_sketches_with_platformio $TRAVIS_BUILD_DIR/libraries "--board nodemcuv2 --verbose" 2 1
else
echo "BUILD_TYPE not set or invalid"
rm -rf $cache_dir
exit 1
fi

rm -rf $cache_dir
19 changes: 19 additions & 0 deletions tests/debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

cache_dir=$(mktemp -d)

source "$TRAVIS_BUILD_DIR"/tests/common.sh

if [ "$BUILD_PARITY" = "even" ]; then
mod=2
rem=0
elif [ "$BUILD_PARITY" = "odd" ]; then
mod=2
rem=1
fi

install_arduino debug
build_sketches_with_arduino "$mod" "$rem" lm2f

rm -rf "$cache_dir"

75 changes: 75 additions & 0 deletions tests/platformio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash

cache_dir=$(mktemp -d)

source "$TRAVIS_BUILD_DIR"/tests/common.sh

function install_platformio()
{
pip install --user -U https://github.com/platformio/platformio/archive/develop.zip
platformio platform install "https://github.com/platformio/platform-espressif8266.git#feature/stage"
sed -i 's/https:\/\/github\.com\/esp8266\/Arduino\.git/*/' ~/.platformio/platforms/espressif8266/platform.json
ln -s $TRAVIS_BUILD_DIR ~/.platformio/packages/framework-arduinoespressif8266
# Install dependencies:
# - esp8266/examples/ConfigFile
pio lib install ArduinoJson
}

function build_sketches_with_platformio()
{
set +e
local srcpath=$1
local build_arg=$2
local build_mod=$3
local build_rem=$4
local sketches=$(find $srcpath -name *.ino | sort)
local testcnt=0
for sketch in $sketches; do
testcnt=$(( ($testcnt + 1) % $build_mod ))
if [ $testcnt -ne $build_rem ]; then
continue # Not ours to do
fi
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 -e "\n ------------ Skipping $sketch ------------ \n";
continue
fi
local build_cmd="pio ci $sketchdir $build_arg"
echo -e "\n ------------ Building $sketch ------------ \n";
echo "$build_cmd"
time ($build_cmd >build.log)
local result=$?
if [ $result -ne 0 ]; then
echo "Build failed ($1)"
echo "Build log:"
cat build.log
set -e
return $result
fi
rm build.log
done
set -e
}

if [ -z "$BUILD_PARITY" ]; then
mod=1
rem=0
elif [ "$BUILD_PARITY" = "even" ]; then
mod=2
rem=0
elif [ "$BUILD_PARITY" = "odd" ]; then
mod=2
rem=1
fi

install_platformio
build_sketches_with_platformio "$TRAVIS_BUILD_DIR"/libraries "--board nodemcuv2 --verbose" "$mod" "$rem"

rm -rf "$cache_dir"

40 changes: 37 additions & 3 deletions tests/run_CI_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,41 @@ EOF
done

# use pip2 for python2 with python3 is around, platformio doesn't like it
cp tests/common.sh tests/common-custom.sh
sed -i 's,pip ,pip2 ,g' tests/common-custom.sh
cp tests/platformio.sh tests/platformio-custom.sh
sed -i 's,pip ,pip2 ,g' tests/platformio-custom.sh

export HOME="${TMPCI}"
export TRAVIS_BUILD_DIR="${TMPCI}"
export BUILD_TYPE="$BUILD_TYPE"

if [ "$BUILD_TYPE" = "build" ]; then
tests/build.sh
elif [ "$BUILD_TYPE" = "build_even" ]; then
BUILD_PARITY=even tests/build.sh
elif [ "$BUILD_TYPE" = "build_odd" ]; then
BUILD_PARITY=odd tests/build.sh

elif [ "$BUILD_TYPE" = "debug_even" ]; then
BUILD_PARITY=even tests/debug.sh
elif [ "$BUILD_TYPE" = "debug_odd" ]; then
BUILD_PARITY=odd tests/debug.sh

elif [ "$BUILD_TYPE" = "build6" ]; then
tests/build6.sh
elif [ "$BUILD_TYPE" = "build6_even" ]; then
BUILD_PARITY=even tests/build6.sh
elif [ "$BUILD_TYPE" = "build6_odd" ]; then
BUILD_PARITY=odd tests/build6.sh

elif [ "$BUILD_TYPE" = "platformio" ]; then
tests/platformio-custom.sh
elif [ "$BUILD_TYPE" = "platformio_even" ]; then
BUILD_PARITY=even tests/platformio-custom.sh
elif [ "$BUILD_TYPE" = "platformio_odd" ]; then
BUILD_PARITY=odd tests/platformio-custom.sh

else
echo "BUILD_TYPE not set or invalid"
exit 1
fi

HOME=${TMPCI} TRAVIS_BUILD_DIR=${TMPCI} BUILD_TYPE=$BUILD_TYPE tests/common-custom.sh