Commit 3c0d6521 authored by Maurice Kraus's avatar Maurice Kraus
Browse files

build: this refactors the script

parent 5d218f30
Pipeline #1912 waiting for manual action with stages
in 26 minutes and 19 seconds
......@@ -14,7 +14,7 @@ previous_build_status_text=""
exit_code=""
log_url=""
usage() {
usage () {
echo ""
echo "Usage: gitrise [options]"
echo
......@@ -176,7 +176,7 @@ get_build_status () {
}
get_follow_log () {
local test_call_counter=-1
local test_call_counter=0
local response=""
local counter=0
local retry=3
......@@ -184,14 +184,17 @@ get_follow_log () {
local log_is_archived="false"
local current_position=0
local current_timestamp_query=""
local command=""
while [ "${log_is_archived}" = "false" ]; do
if [ -z "${TESTING_ENABLED}" ]; then
sleep "$polling_interval"
local command="curl --silent -X GET -w \"\n%{http_code}\n\" 'https://app.bitrise.io/api/build/$build_slug/logs.json?is_include_log_chunks=true$current_timestamp_query' --header 'Accept: application/json' --header 'Authorization: $ACCESS_TOKEN'"
command="curl --silent -X GET -w \"\n%{http_code}\n\" 'https://app.bitrise.io/api/build/$build_slug/logs.json?is_include_log_chunks=true$current_timestamp_query' --header 'Accept: application/json' --header 'Authorization: $ACCESS_TOKEN'"
response=$(eval "${command}")
else
command="https://app.bitrise.io/api/build/[REDACTED]/logs.json?is_include_log_chunks=true$current_timestamp_query"
((test_call_counter++))
response=$(< ./testdata/"$1")
response=$(< ./testdata/"$1_$test_call_counter".json)
fi
if [[ "$response" != *"<!DOCTYPE html>"* ]]; then
......@@ -207,8 +210,8 @@ get_follow_log () {
current_position=$(echo "${positions[${#positions[@]}-1]}")
for i in "${chunks[@]}"; do
echo -e "$i"
[ "$DEBUG" == "true" ] && log "${command%%'--header'*}" "$i" "get_follow_status.log"
echo -e $i
[ "$DEBUG" == "true" ] && log "${command%%'--header'*}" "$i" "get_follow.log"
done
else
if [[ $counter -lt $retry ]]; then
......@@ -222,7 +225,7 @@ get_follow_log () {
done
}
process (){
process () {
local response="$1"
local current_build_status_text=$(echo "$response" | jq ".data .status_text" | sed 's/"//g')
if [ "$previous_build_status_text" != "$current_build_status_text" ]; then
......@@ -254,7 +257,7 @@ build_status_message () {
esac
}
get_log_info(){
get_log_info () {
local log_is_archived=false
local counter=0
local retry=4
......@@ -281,19 +284,21 @@ get_log_info(){
fi
}
get_logs(){
local url="$1"
local logs=$(curl --silent -X GET "$url")
render_logs () {
echo "================================================================================"
echo "============================== Bitrise Logs Start =============================="
echo "$logs"
"$1"
echo "================================================================================"
echo "============================== Bitrise Logs End =============================="
}
get_logs () {
local url="$1"
local logs=$(curl --silent -X GET "$url")
echo "$logs"
}
log(){
log () {
local request="$1"
local response="$2"
local log_file="$3"
......@@ -308,14 +313,14 @@ log(){
if [ "$0" = "${BASH_SOURCE[0]}" ] && [ -z "${TESTING_ENABLED}" ]; then
trigger_build
if [ "$FOLLOW" == "true" ]; then
get_follow_log
get_log_info
get_logs "$log_url"
render_logs get_follow_log
get_build_status
build_status_message "$build_status"
else
get_build_status
get_log_info
get_logs "$log_url"
logs=`get_logs "$log_url"`
render_logs "$logs"
build_status_message "$build_status"
fi
exit ${exit_code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment