2021-03-18 11:19:28 +01:00
#!/bin/bash
2021-09-07 14:11:21 +02:00
is_kasmvnc( ) {
local package = " $1 " ;
echo " $package " | grep -q 'kasmvncserver_'
}
2021-03-18 11:19:28 +01:00
function prepare_upload_filename( ) {
local package = " $1 " ;
2021-09-07 14:11:21 +02:00
if ! is_kasmvnc " $package " ; then
export upload_filename = " $package "
return
fi
2021-03-18 11:19:28 +01:00
.ci/detect_os_arch_package_format " $package " > /tmp/os_arch_package_format;
source /tmp/os_arch_package_format;
detect_release_branch
2021-09-07 14:11:21 +02:00
detect_revision " $package " " $OS_ARCH "
if [ -n " $REVISION " ] ; then
REVISION = " _ ${ REVISION } "
fi
2021-03-18 11:19:28 +01:00
if [ -n " $RELEASE_BRANCH " ] ; then
2021-09-07 14:11:21 +02:00
export upload_filename = " kasmvncserver_ ${ PACKAGE_OS } _ ${ RELEASE_VERSION } ${ REVISION } _ ${ OS_ARCH } . ${ PACKAGE_FORMAT } " ;
2021-03-18 11:19:28 +01:00
else
export SANITIZED_BRANCH = " $( echo $CI_COMMIT_REF_NAME | sed 's/\//_/g' ) " ;
2021-09-07 14:11:21 +02:00
export upload_filename = " kasmvncserver_ ${ PACKAGE_OS } _ ${ RELEASE_VERSION } _ ${ SANITIZED_BRANCH } _ ${ CI_COMMIT_SHA : 0 : 6 } ${ REVISION } _ ${ OS_ARCH } . ${ PACKAGE_FORMAT } " ;
2021-03-18 11:19:28 +01:00
fi
} ;
function upload_to_s3( ) {
local package = " $1 " ;
local upload_filename = " $2 " ;
# Transfer to S3
python3 amazon-s3-bitbucket-pipelines-python/s3_upload.py " ${ S3_BUCKET } " " $package " " ${ S3_BUILD_DIRECTORY } / ${ upload_filename } " ;
# Use the Gitlab API to tell Gitlab where the artifact was stored
export S3_URL = " https:// ${ S3_BUCKET } .s3.amazonaws.com/ ${ S3_BUILD_DIRECTORY } / ${ upload_filename } " ;
export BUILD_STATUS = " {\"key\":\"doc\", \"state\":\"SUCCESSFUL\", \"name\":\" ${ upload_filename } \", \"url\":\" ${ S3_URL } \"} " ;
curl --request POST --header " PRIVATE-TOKEN: ${ GITLAB_API_TOKEN } " " ${ CI_API_V4_URL } /projects/ ${ CI_PROJECT_ID } /statuses/ ${ CI_COMMIT_SHA } ?state=success&name=build-url&target_url= ${ S3_URL } " ;
} ;
2021-09-07 14:11:21 +02:00
2021-03-18 11:19:28 +01:00
function prepare_to_run_scripts_and_s3_uploads( ) {
export DEBIAN_FRONTEND = noninteractive;
apt-get update;
apt-get install -y ruby2.7 git;
apt-get install -y python3 python3-pip python3-boto3 curl pkg-config libxmlsec1-dev;
git clone https://bitbucket.org/awslabs/amazon-s3-bitbucket-pipelines-python.git;
} ;
detect_release_branch( ) {
if echo $CI_COMMIT_REF_NAME | grep -Pq '^release/([\d.]+)$' ; then
export RELEASE_BRANCH = 1;
fi
}
2021-09-07 14:11:21 +02:00
detect_revision( ) {
local package = " $1 "
local arch = " $2 "
REVISION =
if ! echo " $package " | grep -q '+' ; then
return
fi
REVISION = $( echo " $package " | sed " s/_ ${ arch } .\+// " | sed 's/.\++//' )
}