Skip to content
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
1 change: 1 addition & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ blocks:
- tests/sem-semantic-release.bats
- tests/system_metrics_collector.bats
- tests/toolbox_metrics.bats
- tests/toolbox_env_var.bats
commands:
- source release/install_in_tests.sh
- truncate -s 10M 10mfile
Expand Down
2 changes: 1 addition & 1 deletion libcheckout
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ function checkout::metric() {
ref_type=${SEMAPHORE_GIT_REF_TYPE:-""}
size=${1:-"0"}
[[ $size -gt 0 ]] && status='success' || status='fail'
echo "libcheckout,provider='$SEMAPHORE_GIT_PROVIDER',reftype='$ref_type',status=$status size=$1" >> /tmp/toolbox_metrics
echo "libcheckout,provider=$SEMAPHORE_GIT_PROVIDER,reftype=$ref_type,status=$status size=$1" >> /tmp/toolbox_metrics
fi
}

Expand Down
4 changes: 2 additions & 2 deletions sem-install
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ install::package_url() {
[[ $(uname -m) =~ ^(aarch64|arm64)$ ]] && SEMAPHORE_ARCH="arm/" || SEMAPHORE_ARCH=""
case $DIST in
Linux)
echo "http://packages.semaphoreci.com/${SEMAPHORE_ARCH}$(lsb_release -cs)"
echo "http://${packages_host}/${SEMAPHORE_ARCH}$(lsb_release -cs)"
;;
Darwin)
[[ "${SEMAPHORE_ARCH}" == "arm/" ]] && echo "http://packages.semaphoreci.com/arm/mac" || echo "http://packagesmac.semaphoreci.com/mac"
[[ "${SEMAPHORE_ARCH}" == "arm/" ]] && echo "http://${packages_host}/arm/mac" || echo "http://packagesmac.semaphoreci.com/mac"
;;
*)
echo "Unsupported distro $DIST"
Expand Down
6 changes: 3 additions & 3 deletions sem-service
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DATE_FORMAT='%H:%M %d/%m/%Y'
docker_status=0
state=('success' 'fail')
download_location='local'
registry_host='registry.semaphoreci.com'
registry_host=${SEMAPHORE_TOOLBOX_SERVICE_HOST:-'registry.semaphoreci.com'}
[[ $(uname -m) =~ "aarch" ]] && registry_host="${registry_host}/arm"

declare -A sem_services
Expand Down Expand Up @@ -40,8 +40,8 @@ service::pull_image() {
if [[ -z $image_name ]]; then
service:err "Image name can't be empty"
fi
if ! echo "$image_name" | grep -E '^registry.semaphoreci.com/arm/[[:alnum:]]+(:[[:alnum:]]+.*)?$' &>/dev/null; then
if ! echo "$image_name" | grep -E '^registry.semaphoreci.com/[[:alnum:]]+(:[[:alnum:]]+.*)?$' &>/dev/null; then
if ! echo "$image_name" | grep -E '^'"${registry_host}"'/arm/[[:alnum:]]+(:[[:alnum:]]+.*)?$' &>/dev/null; then
if ! echo "$image_name" | grep -E '^'"${registry_host}"'/[[:alnum:]]+(:[[:alnum:]]+.*)?$' &>/dev/null; then
if ! echo "$image_name" | grep -E '^[[:alnum:]]+(:[[:alnum:]]+.*)?$' &>/dev/null; then
service::err "Invalid image name provided '${image_name}'"
fi
Expand Down
1 change: 1 addition & 0 deletions sem-version
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ VERSION="0.7"
DATE_FORMAT='%H:%M %d/%m/%Y'
TOTAL_TIME=0

export packages_host=${SEMAPHORE_TOOLBOX_PACKAGE_HOST:-'packages.semaphoreci.com'}
SEMAPHORE_ARCH=$(uname -m)

################################################################################
Expand Down
56 changes: 56 additions & 0 deletions tests/toolbox_env_var.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env bats

load "support/bats-support/load"
load "support/bats-assert/load"

setup() {
TMPFILE=$(mktemp /tmp/toolbox-XXXX)
source /tmp/.env-*
source /opt/change-erlang-version.sh
source /opt/change-python-version.sh
source /opt/change-go-version.sh
source /opt/change-java-version.sh
source /opt/change-scala-version.sh
source ~/.phpbrew/bashrc
. /home/semaphore/.nvm/nvm.sh
export PATH="$PATH:/home/semaphore/.yarn/bin"
export KIEX_HOME="$HOME/.kiex"
source "/home/semaphore/.kiex/scripts/kiex"
export PATH="/home/semaphore/.rbenv/bin:$PATH"
export NVM_DIR=/home/semaphore/.nvm
export PHPBREW_HOME=/home/semaphore/.phpbrew
eval "$(rbenv init -)"
export SEMAPHORE_TOOLBOX_PACKAGE_HOST="packages2.semaphoreci.com"
export SEMAPHORE_TOOLBOX_SERVICE_HOST="packages2.semaphoreci.com"
source ~/.toolbox/toolbox
}

@test "package url should contain packages2" {
run install::package_url
assert_output --partial "packages2"
}

@test "package url shouldn't contain packages2" {

run unset SEMAPHORE_TOOLBOX_PACKAGE_HOST && install::package_url
refute_output --partial "packages2"
}

@test "sem-service start postgres 16 should fail" {
sem-service start postgres 16 2>&1 > /dev/null || true
run psql -h 0.0.0.0 -U postgres -c "SELECT version()"
assert_failure
}

@test "sem-service start postgres 16 should succeed" {
unset SEMAPHORE_TOOLBOX_SERVICE_HOST
sem-service start postgres 16
sleep 20
run psql -h 0.0.0.0 -U postgres -c "SELECT version()"
assert_output --partial "16"
assert_success
}




2 changes: 1 addition & 1 deletion tests/toolbox_metrics.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ setup() {

sed -E -i '/^semversion,software=[a-z]*,state=(success|fail),version=[0-9a-zA-Z.-]+,osversion=[0-9.]+ duration=[0-9]+$/d' /tmp/toolbox_metrics

sed -E -i '/^libcheckout,provider=(github|bitbucket),reftype=[].*,status=(success|fail) size=[0-9]+$/d' /tmp/toolbox_metrics
sed -E -i "/^libcheckout,provider='?(github|bitbucket)'?,reftype='?[^']*'?,status=(success|fail) size=[0-9]+$/d" /tmp/toolbox_metrics

sed -E -i '/^usercache,server=[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3},user=[a-z,0-9,-]+,command=(store|restore),corrupt=[0,1] size=[0-9]+,duration=[0-9]+$/d' /tmp/toolbox_metrics

Expand Down