Commit 477c2b09 authored by Maurice Kraus's avatar Maurice Kraus
Browse files

build: this updates the gitrise version

parent a496461d
Pipeline #1909 canceled with stages
in 4 minutes and 38 seconds
......@@ -4,7 +4,7 @@
# shellcheck disable=SC2120
# disables "foo references arguments, but none are ever passed."
VERSION="0.7.0"
VERSION="0.8.0"
APP_NAME="Gitrise Trigger"
build_slug=""
......@@ -21,6 +21,7 @@ usage() {
echo "[options]"
echo " -w, --workflow <string> Bitrise Workflow"
echo " -b, --branch <string> Git Branch"
echo " -f, --follow Continously pulls log updates from the current Workflow"
echo " -e, --env <string> List of environment variables in the form of key1:value1,key2:value2"
echo " -a, --access-token <string> Bitrise access token"
echo " -s, --slug <string> Bitrise project slug"
......@@ -68,6 +69,10 @@ while [ $# -gt 0 ]; do
-d|--debug)
DEBUG="true"
shift
;;
-f|--follow)
FOLLOW="true"
shift
;;
*)
echo "Invalid option '$1'"
......@@ -136,7 +141,7 @@ trigger_build () {
build_url=$(echo "$response" | jq ".build_url" | sed 's/"//g')
build_slug=$(echo "$response" | jq ".build_slug" | sed 's/"//g')
fi
printf "\nHold on... We're about to liftoff! 🚀\n \nTo follow the build in real time, please visit Bitrise.io:\n%s\n" "${build_url}"
printf "\nHold on... We're about to liftoff! 🚀\n \nBuild URL: %s\n" "${build_url}"
}
get_build_status () {
......@@ -170,6 +175,53 @@ get_build_status () {
if [ "$build_status" = 1 ]; then exit_code=0; else exit_code=1; fi
}
get_follow_log () {
local test_call_counter=-1
local response=""
local counter=0
local retry=3
local polling_interval=10
local log_is_archived="false"
local current_position=0
local current_timestamp_query=""
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'"
response=$(eval "${command}")
else
((test_call_counter++))
response=$(< ./testdata/"$1")
fi
if [[ "$response" != *"<!DOCTYPE html>"* ]]; then
status=$(echo "$response" | tail -n1)
response=${response%$status} # subtract status code from response
log_is_archived=$(echo "$response" | jq ".is_archived")
current_timestamp_query=$(echo "$response" | jq ".timestamp")
current_timestamp_query=$(sed -e 's/^"//' -e 's/"$//' <<<"$current_timestamp_query")
current_timestamp_query="&timestamp="$current_timestamp_query
log_chunks=$(echo "$response" | jq "{chunks: [.log_chunks[]]}")
chunks=$(echo "$log_chunks" | jq ".chunks[].chunk")
positions=$(echo "$log_chunks" | jq ".chunks[].position")
current_position=$(echo "${positions[${#positions[@]}-1]}")
for i in "${chunks[@]}"; do
echo $i
[ "$DEBUG" == "true" ] && log "${command%%'--header'*}" "$i" "get_follow_status.log"
done
else
if [[ $counter -lt $retry ]]; then
build_status=0
((counter++))
else
echo "ERROR: Invalid response received from Bitrise API"
build_status="null"
fi
fi
done
}
process (){
local response="$1"
local current_build_status_text=$(echo "$response" | jq ".data .status_text" | sed 's/"//g')
......@@ -255,9 +307,16 @@ log(){
# disables "use foo "$@" if function's $1 should mean script's $1."
if [ "$0" = "${BASH_SOURCE[0]}" ] && [ -z "${TESTING_ENABLED}" ]; then
trigger_build
get_build_status
get_log_info
get_logs "$log_url"
build_status_message "$build_status"
if [ "$FOLLOW" == "true" ]; then
get_follow_log
get_log_info
get_logs "$log_url"
build_status_message "$build_status"
else
get_build_status
get_log_info
get_logs "$log_url"
build_status_message "$build_status"
fi
exit ${exit_code}
fi
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