From 4bd939d172a24c4bc8730e8822de7a45807b73fb Mon Sep 17 00:00:00 2001 From: Chris Goes Date: Fri, 9 Feb 2024 09:13:44 -0700 Subject: [PATCH] Fixes for deb build and CI (#18) * Fix invalid version string for the bennu .deb - Ensure .deb has a properly formatted version - Set version for everything in cmake to 6.0.0 (not intended to change, just a placeholder) - Add GitHub URL to package metadata - Fix architecture variable - Fix warning with old tags command * refactoring CI for bennu C++ build * apply version fix to pybennu deb as well * WIP on CI * more CI tweaks * sudo is needed * split into separate steps, upload artifacts earlier --- .editorconfig | 7 +++- .github/workflows/c-cpp.yml | 67 +++++++++++++++++++++++-------------- CMakeLists.txt | 29 +++++++++------- cmake/CpackConfig.cmake | 18 +++++++--- src/pybennu/Makefile | 2 +- src/pybennu/setup.py | 2 +- 6 files changed, 80 insertions(+), 45 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0c72c638..fc594366 100644 --- a/.editorconfig +++ b/.editorconfig @@ -34,4 +34,9 @@ indent_style = tab end_of_line = crlf [*.{xml,xslt}] -indent_size = 2 \ No newline at end of file +indent_size = 2 + +[CMakeLists.txt] +indent_size = 2 +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.github/workflows/c-cpp.yml b/.github/workflows/c-cpp.yml index 31c1aebc..17da1c08 100644 --- a/.github/workflows/c-cpp.yml +++ b/.github/workflows/c-cpp.yml @@ -1,22 +1,26 @@ -name: C/C++ CI +name: Build and test C++ bennu and deb for pybennu on: pull_request: - branches: [ "main" ] + branches: + - main + push: + branches: + - main jobs: build: - runs-on: ubuntu-20.04 - steps: - name: checkout the repo - uses: actions/checkout@v3 - - name: get tags - run: git fetch --tags + uses: actions/checkout@v4 + - name: Install build dependencies + run: | + sudo apt-get update + sudo apt-get install --no-install-recommends -y build-essential cmake g++ gcc libasio-dev libboost-date-time-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libfreetype6-dev libssl-dev libzmq5-dev python3-pip python3-wheel + sudo gem install fpm - name: configure bennu run: | - sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential cmake g++ gcc libasio-dev libboost-date-time-dev libboost-filesystem-dev libboost-program-options-dev libboost-system-dev libboost-thread-dev libfreetype6-dev libssl-dev libzmq5-dev mkdir build cd build/ cmake ../ @@ -53,29 +57,40 @@ jobs: grep "load-power:999" probe.out echo -e "help\nexit" | bennu-brash >brash.out 2>&1 grep "SCEPTRE Field-Device" brash.out - - name: package bennu + bennu-watcherd --help + bennu-simulink-provider --help + bennu-field-deviced --help + bennu-simulink-provider-helics --help + - name: build deb for bennu run: | cd build/ sudo make package - - name: package pybennu + cp ./*.deb ../bennu.deb + - name: build deb for pybennu run: | - sudo apt-get install --no-install-recommends -y python3-pip python3-wheel - sudo gem install fpm cd src/pybennu - make deb > deb.log 2>&1 - #make dist > dist.log 2>&1 - - name: archive artifacts - uses: actions/upload-artifact@v3 + sudo make deb + cp ./dist/*.deb ../../pybennu.deb + - name: archive deb artifacts + uses: actions/upload-artifact@v4 with: - name: bennu artifacts + name: bennu-deb-artifacts + if-no-files-found: error path: | - *.log - build/*.deb - src/pybennu/dist/* - - name: release bennu and pybennu + bennu.deb + pybennu.deb + - name: deb file metadata run: | - cp build/*.deb build/bennu.deb - cp src/pybennu/dist/*.deb src/pybennu/dist/pybennu.deb - curl -F package=@build/bennu.deb https://${{ secrets.GEMFURY }}@push.fury.io/sceptre/ - curl -F package=@src/pybennu/dist/pybennu.deb https://${{ secrets.GEMFURY }}@push.fury.io/sceptre/ - + dpkg-deb --info ./bennu.deb + dpkg-deb --info ./pybennu.deb + - name: check bennu deb installs + run: | + sudo dpkg -i bennu.deb + - name: check pybennu deb installs + run: | + sudo dpkg -i pybennu.deb + - name: release debs to apt repo + if: (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true) || (github.event_name == 'push' && github.ref == 'refs/heads/main') + run: | + curl -F package=@bennu.deb https://${{ secrets.GEMFURY }}@push.fury.io/sceptre/ + curl -F package=@pybennu.deb https://${{ secrets.GEMFURY }}@push.fury.io/sceptre/ diff --git a/CMakeLists.txt b/CMakeLists.txt index af0e8d14..208e9ab8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,22 +1,27 @@ -cmake_minimum_required (VERSION 3.8.0 FATAL_ERROR) +cmake_minimum_required (VERSION 3.12.0 FATAL_ERROR) -# Get the latest tag of the working branch -execute_process( - COMMAND git describe --abbrev=0 - WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - OUTPUT_VARIABLE bennu_TAG - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -# Get the latest tag and abbreviated commit hash of the working branch +# Get the abbreviated commit hash of the working branch execute_process( COMMAND git rev-parse --short HEAD WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} - OUTPUT_VARIABLE bennu_TAG_HASH + OUTPUT_VARIABLE bennu_SHORT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ) -project(bennu VERSION ${bennu_TAG} LANGUAGES C CXX) +# CMake requires semantic versions with integer components +# Set it to something static so stuff works +set(bennu_VERSION "6.0.0") + +# Add commit hash to the version for use by the Deb package builder +# Example: 6.0.0.f7055755 +set(bennu_VERSION_WITH_COMMIT "${bennu_VERSION}.${bennu_SHORT_HASH}") + +project(bennu + VERSION "${bennu_VERSION}" + DESCRIPTION "SCEPTRE ICS Modeling and Simulation Package" + HOMEPAGE_URL "https://github.com/sandialabs/sceptre-bennu" + LANGUAGES C CXX +) if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) message(STATUS "Setting build type to 'Release' as none was specified.") diff --git a/cmake/CpackConfig.cmake b/cmake/CpackConfig.cmake index 3a9004ae..a6bf2e3a 100644 --- a/cmake/CpackConfig.cmake +++ b/cmake/CpackConfig.cmake @@ -1,13 +1,23 @@ # Generate deb package +# CPack DEB documentation: https://cmake.org/cmake/help/latest/cpack_gen/deb.html +# Debian archive description: https://www.debian.org/doc/debian-policy/ch-archive.html +# Debian archive metadata: https://www.debian.org/doc/debian-policy/ch-controlfields.html + string(TIMESTAMP timestamp "%Y%m%d_%H-%M-%S") set(CPACK_GENERATOR "DEB") set(CPACK_STRIP_FILES TRUE) set(CPACK_DEBIAN_PACKAGE_NAME bennu) -set(CPACK_DEBIAN_PACKAGE_VERSION ${bennu_TAG_HASH}) -set(CPACK_DEBIAN_PACKAGE_ARCHITECHTURE amd64) -set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sandia National Laboratories ") set(CPACK_DEBIAN_PACKAGE_DEPENDS "libasio-dev, libboost-date-time-dev, libboost-filesystem-dev, libboost-program-options-dev, libboost-system-dev") set(CPACK_DEBIAN_PACKAGE_SECTION misc) -set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "SCEPTRE ICS Modeling and Simulation Package") +set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CMAKE_PROJECT_DESCRIPTION}) set(CPACK_PACKAGE_FILE_NAME "bennu-${CPACK_DEBIAN_PACKAGE_VERSION}_amd64_${timestamp}") +set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${CMAKE_PROJECT_HOMEPAGE_URL}) + include(CPack) diff --git a/src/pybennu/Makefile b/src/pybennu/Makefile index 60887405..6ec5aa14 100644 --- a/src/pybennu/Makefile +++ b/src/pybennu/Makefile @@ -40,7 +40,7 @@ TIMESTAMP = $(shell date +%Y%m%d_%H-%M-%S) PACKAGE_SECTION = python PACKAGE_PRIORITY = extra PACKAGE_COMPRESSION = bzip2 -PACKAGE_FULL_VERSION:=$(shell git rev-parse --short HEAD) +PACKAGE_FULL_VERSION := 6.0.0.$(shell git rev-parse --short HEAD) PACKAGE_NAME = pybennu PACKAGE_FILENAME = $(PACKAGE_NAME)_$(PACKAGE_FULL_VERSION)_amd64_$(TIMESTAMP).deb PACKAGE_VENDOR = SNL diff --git a/src/pybennu/setup.py b/src/pybennu/setup.py index 55417e37..29744645 100644 --- a/src/pybennu/setup.py +++ b/src/pybennu/setup.py @@ -153,7 +153,7 @@ def run(self): # https://peps.python.org/pep-0440/ # TODO: move to pyproject.toml, use setuptools_scm to do version handling # https://github.com/pypa/setuptools_scm - version = '0.0.0', + version = '6.0.0', description = 'bennu python providers and utilities', url = 'https://github.com/sandialabs/sceptre-bennu.git', author = 'Sandia National Laboratories',