From d5ff4a9d92a7b2cc117458cdbe7860e02e2ae8aa Mon Sep 17 00:00:00 2001 From: ekoby <7406535+ekoby@users.noreply.github.com> Date: Fri, 25 Oct 2019 11:27:22 -0400 Subject: [PATCH] Jenkins (#2) * derive project version from git tags, use BUILD_NUMBER enrironment var * fetch tags * use ziti-uploads Artifactory user --- CMakeLists.txt | 51 +++++++++++++------------------------- Jenkinsfile | 56 +++++++++++++++++++++++++++++++++++------- git.cmake | 41 +++++++++++++++++++++++++++++++ library/CMakeLists.txt | 1 + library/model.c | 2 +- make_publish_spec.sh | 12 +++++++++ 6 files changed, 119 insertions(+), 44 deletions(-) create mode 100644 git.cmake create mode 100755 make_publish_spec.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e7811ce..7198572e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required (VERSION 3.12) -file(READ version ver) +include(git.cmake) project (ziti-sdk VERSION ${ver} @@ -7,6 +7,10 @@ project (ziti-sdk ) 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") @@ -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 () @@ -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) @@ -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) diff --git a/Jenkinsfile b/Jenkinsfile index b0558970..d038fb2f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -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') { @@ -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" + ) } } } diff --git a/git.cmake b/git.cmake new file mode 100644 index 00000000..f76d5b8b --- /dev/null +++ b/git.cmake @@ -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)") + + + diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 8e43a381..3a724a0e 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -21,6 +21,7 @@ target_sources(ziti target_link_libraries(ziti PUBLIC uv_mbed + PUBLIC m ) target_include_directories(ziti diff --git a/library/model.c b/library/model.c index 1eaff56f..3500c028 100644 --- a/library/model.c +++ b/library/model.c @@ -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; } diff --git a/make_publish_spec.sh b/make_publish_spec.sh new file mode 100755 index 00000000..ca695fc2 --- /dev/null +++ b/make_publish_spec.sh @@ -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