Skip to content

Commit

Permalink
Jenkins (#2)
Browse files Browse the repository at this point in the history
* derive project version from git tags, use BUILD_NUMBER enrironment var
* fetch tags
* use ziti-uploads Artifactory user
  • Loading branch information
ekoby authored Oct 25, 2019
1 parent 499fac2 commit d5ff4a9
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 44 deletions.
51 changes: 17 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
cmake_minimum_required (VERSION 3.12)
file(READ version ver)
include(git.cmake)

project (ziti-sdk
VERSION ${ver}
LANGUAGES C CXX
)

message("project version: ${PROJECT_VERSION}")
message("git info:")
message(" branch : ${GIT_BRANCH}")
message(" hash : ${GIT_COMMIT_HASH}")
message(" date : ${BUILD_DATE}")

if (WIN32)
message("WIN32 build. Creating: ${CMAKE_BINARY_DIR}/cmake_install")
Expand All @@ -22,37 +26,8 @@ message("cross-compiling ${CMAKE_CROSSCOMPILING}")

enable_testing()

# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# capture build date
execute_process(
COMMAND date +%a-%m/%d/%Y-%H:%M:%S-%Z
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

message("git info:")
message(" branch : ${GIT_BRANCH}")
message(" hash : ${GIT_COMMIT_HASH}")
message(" date : ${BUILD_DATE}")

if (DEFINED ENV{BITBUCKET_BUILD_NUMBER})
set(ZITI_BUILDNUM $ENV{BITBUCKET_BUILD_NUMBER})
if (DEFINED ENV{BUILD_NUMBER})
set(ZITI_BUILDNUM $ENV{BUILD_NUMBER})
else ()
set(ZITI_BUILDNUM local)
endif ()
Expand All @@ -77,7 +52,9 @@ elseif (WIN32)
endif ()

include(CPack)
add_custom_target(publish)
add_custom_target(publish
COMMENT "generate publish specs"
)

if(${GIT_BRANCH} STREQUAL master)
set(PUB_PFX ziti-staging)
Expand All @@ -100,7 +77,13 @@ macro(PUBCOMP comp)

add_custom_target(${comp}-pub
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${comp}-${ZITI_VERSION}-${CMAKE_SYSTEM_NAME}.tar.gz
COMMAND jfrog rt u ${PUB_OPTS} --props='${${comp}_PUB_PROPS}' ${comp}-${ZITI_VERSION}-${CMAKE_SYSTEM_NAME}.tar.gz ${${comp}_PUB_PATH}
# COMMAND jfrog rt u ${PUB_OPTS} --props='${${comp}_PUB_PROPS}' ${comp}-${ZITI_VERSION}-${CMAKE_SYSTEM_NAME}.tar.gz ${${comp}_PUB_PATH}
COMMAND echo "{"
\"target\": \"${${comp}_PUB_PATH}\",
\"pattern\": \"${CMAKE_CURRENT_BINARY_DIR}/${comp}-${ZITI_VERSION}-${CMAKE_SYSTEM_NAME}.tar.gz\",
\"props\": \"${${comp}_PUB_PROPS}\"
"}" > ${CMAKE_BINARY_DIR}/${comp}-pub-spec.json
VERBATIM
)

add_dependencies(publish ${comp}-pub)
Expand Down
56 changes: 47 additions & 9 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ pipeline {
steps {
sh 'git submodule update --init --recursive'
sh 'git submodule status --recursive'
sh 'git fetch --verbose --tags'
}
}
stage('Tagging') {
when { branch 'master'}
steps {
echo 'NO TAGGING YET!'
script {
def zitiVer = readFile('version').trim()
def tagVer = sh(returnStdout: true, script: 'git describe')
echo "zitiVer = ${zitiVer} tagVer = ${tagVer}"
if (zitiVer > tagVer) {
echo "advancing tag based on 'version' file"
} else {
echo "advancing tag based on commits"
}
}
}
}
stage('Tests') {
Expand Down Expand Up @@ -45,17 +62,38 @@ pipeline {
}
}
stage('Build all platforms') {
environment {
JFROG_CLI_OFFER_CONFIG = false
JFROG_API_KEY = credentials('ad-tf-var-jfrog-api-key')
failFast true
parallel {
stage('Linux-x86_64') {
steps {
echo "building ${STAGE_NAME}"
sh "mkdir -p build-${STAGE_NAME}"
dir("build-${STAGE_NAME}") {
sh 'cmake -DCMAKE_BUILD_TYPE=Debug ..'
sh 'cmake --build . --target package --target publish'
}
}
}
stage('Linux-arm') {
steps {
echo "building ${STAGE_NAME}"
sh "mkdir -p build-${STAGE_NAME}"
dir("build-${STAGE_NAME}") {
sh 'cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../toolchains/${STAGE_NAME}.cmake ..'
sh 'cmake --build . --target package --target publish'
}
}
}
}
}
stage('Publish') {
steps {
sh './uber-build.sh'
}
post {
success {
sh "./publish.sh"
}
sh "./make_publish_spec.sh"
sh "cat publish.json"
rtUpload (
serverId: 'ziti-uploads',
specPath: "./publish.json"
)
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions git.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Get the current working branch
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# capture build date
execute_process(
COMMAND date +%a-%m/%d/%Y-%H:%M:%S-%Z
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BUILD_DATE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# lookup most recent tag to derive version
execute_process(
COMMAND git describe HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_INFO
OUTPUT_STRIP_TRAILING_WHITESPACE
)

if(${GIT_INFO} MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)$")
set(ver ${GIT_INFO})
elseif(${GIT_INFO} MATCHES "^([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-[^-]*")
string(JOIN "." ver ${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
endif()
message("project version: ${ver} (derived from git)")



1 change: 1 addition & 0 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_sources(ziti

target_link_libraries(ziti
PUBLIC uv_mbed
PUBLIC m
)

target_include_directories(ziti
Expand Down
2 changes: 1 addition & 1 deletion library/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static int parse_bool(const char *json, int json_len, const char *path) {
static int parse_int(const char *json, int json_len, const char *path) {
double result;
if (mjson_get_number(json, json_len, path, &result)) {
return (int)round(result);
return (int)lrint(result);
}
return -1;
}
Expand Down
12 changes: 12 additions & 0 deletions make_publish_spec.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash

echo '{ "files": [' > publish.json
for f in build-*/*-pub-spec.json
do
if [ -n "$first" ]; then
echo "," >> publish.json
fi
cat $f >> publish.json
first="done"
done
echo "]}" >> publish.json

0 comments on commit d5ff4a9

Please sign in to comment.