Skip to content

Commit

Permalink
refactored folding to support different types
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias-luedtke committed Dec 15, 2019
1 parent 6f84f4c commit f260dd9
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 15 deletions.
1 change: 0 additions & 1 deletion bitbucket.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TARGET_REPO_PATH=$BITBUCKET_CLONE_DIR
export TARGET_REPO_NAME=${BITBUCKET_REPO_SLUG##*/}
export PYTHONUNBUFFERED=${PYTHONUNBUFFERED:1}
export _DO_NOT_FOLD=true

env "$@" bash "$DIR_THIS/industrial_ci/src/ci_main.sh"
1 change: 0 additions & 1 deletion ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@ DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export TARGET_REPO_PATH=${TARGET_REPO_PATH:-$(pwd)}
export TARGET_REPO_NAME=${TARGET_REPO_NAME:-${TARGET_REPO_PATH##*/}}
export _DO_NOT_FOLD=${_DO_NOT_FOLD:-true}

env "$@" bash "$DIR_THIS/industrial_ci/src/ci_main.sh"
1 change: 0 additions & 1 deletion gitlab.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export TARGET_REPO_PATH=$CI_PROJECT_DIR
export TARGET_REPO_NAME=$CI_PROJECT_NAME
export _DO_NOT_FOLD=true

if [ -n "$SSH_PRIVATE_KEY" ]; then
if [ "$CI_DISPOSABLE_ENVIRONMENT" != true ] && ! [ -f /.dockerenv ] ; then
Expand Down
1 change: 0 additions & 1 deletion industrial_ci/scripts/run_ci
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ fi
export TARGET_REPO_PATH
TARGET_REPO_PATH=$(cd "$repo_dir" && pwd)
export TARGET_REPO_NAME=${TARGET_REPO_PATH##*/}
export _DO_NOT_FOLD=true
echo "Testing $TARGET_REPO_PATH"

if [ -f "$script_dir/../src/ci_main.sh" ]; then # devel space
Expand Down
2 changes: 1 addition & 1 deletion industrial_ci/src/docker.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
_DO_NOT_FOLD
_FOLDING_TYPE
ABICHECK_URL
ABICHECK_VERSION
ADDITIONAL_DEBS
Expand Down
24 changes: 24 additions & 0 deletions industrial_ci/src/folding/none.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Copyright (c) 2019, Mathias Lüdtke
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function ici_start_fold() {
shift 3
}

function ici_end_fold() {
shift 4
}
34 changes: 34 additions & 0 deletions industrial_ci/src/folding/travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# Copyright (c) 2019, Mathias Lüdtke
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function ici_start_fold() {
local tag=$1; shift
local name=$1; shift
local start=$1; shift
ici_ansi_cleared_line "travis_fold:start:$name"
ici_ansi_cleared_line "travis_time:start:$tag"

}

function ici_end_fold() {
local tag=$1; shift
local name=$1; shift
local start=$1; shift
local end=$1; shift
ici_ansi_cleared_line "travis_time:end:$tag:start=$start,finish=$end,duration=$((end - start))"
ici_ansi_cleared_line "travis_fold:end:$name"
}
23 changes: 13 additions & 10 deletions industrial_ci/src/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function ici_color_output {
echo -e "\e[${c}m$*\e[0m"
}

function ici_ansi_cleared_line {
echo -en "$*\r\e[0K"
}

function ici_source_setup {
local u_set=1
[[ $- =~ u ]] || u_set=0
Expand Down Expand Up @@ -79,8 +83,11 @@ function ici_hook() {
fi
}

# shellcheck disable=SC1090
source "${ICI_SRC_PATH}/folding/${_FOLDING_TYPE:-none}.sh" || ici_error "Folding type '$_FOLDING_TYPE' not supported"

#######################################
# Starts a timer section on Travis CI
# Starts a timer section in a folding section
# based on https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_time_start.bash
# and https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_fold.bash
#
Expand All @@ -105,18 +112,15 @@ function ici_time_start {

echo # blank line

if [ "$_DO_NOT_FOLD" != "true" ]; then
echo -e "ici_fold:start:$ICI_FOLD_NAME"
echo -en "ici_time:start:$ICI_TIME_ID"
fi
ici_start_fold "$ICI_TIME_ID" "$ICI_FOLD_NAME" "$ICI_START_TIME"

ici_color_output $ANSI_BLUE ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
ici_color_output $ANSI_BLUE "Starting function '$ICI_FOLD_NAME'"
if [ "$DEBUG_BASH" ] && [ "$DEBUG_BASH" == true ]; then set -x; fi
}

#######################################
# Wraps up the timer section on Travis CI (that's started mostly by ici_time_start function).
# Wraps up the timer section that was started by ici_time_start function
# based on https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/bash/travis_time_finish.bash
#
# Globals:
Expand All @@ -139,10 +143,9 @@ function ici_time_end {
if [ -z "$ICI_START_TIME" ]; then ici_warn "[ici_time_end] var ICI_START_TIME is not set. You need to call ici_time_start in advance. Returning."; return; fi
local end_time; end_time=$(date -u +%s%N)
local elapsed_seconds; elapsed_seconds=$(( (end_time - ICI_START_TIME)/1000000000 ))
if [ "$_DO_NOT_FOLD" != "true" ]; then
echo -e "ici_time:end:$ICI_TIME_ID:start=$ICI_START_TIME,finish=$end_time,duration=$((end_time - ICI_START_TIME))"
echo -en "ici_fold:end:$name"
fi

ici_end_fold "$ICI_TIME_ID" "$name" "$ICI_START_TIME" "$end_time"

ici_color_output "$color_wrap" "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
ici_color_output "$color_wrap" "Function '$name' returned with code '${exit_code}' after $(( elapsed_seconds / 60 )) min $(( elapsed_seconds % 60 )) sec"

Expand Down
1 change: 1 addition & 0 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ DIR_THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
export TARGET_REPO_PATH=$TRAVIS_BUILD_DIR
export TARGET_REPO_NAME=${TRAVIS_REPO_SLUG##*/}
export PYTHONUNBUFFERED=${PYTHONUNBUFFERED:1}
export _FOLDING_TYPE=travis

if [ "$ABICHECK_MERGE" = "auto" ]; then
export ABICHECK_MERGE=false
Expand Down

0 comments on commit f260dd9

Please sign in to comment.