Skip to content

Commit 169f800

Browse files
authored
Provide continuous delivery capability (#4)
- automatically build and release packages for any tag starting with `v` and theoretically any commit to `main`
1 parent 6b4dd56 commit 169f800

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ name: ci
22
on:
33
pull_request:
44
push:
5+
tags:
6+
- v*
57
branches:
68
- main
7-
- master
89

910
env:
1011
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
@@ -69,6 +70,12 @@ jobs:
6970
- compiler: gcc-8
7071
gcov: "gcov-8"
7172

73+
# setup preferred package generators
74+
- developer_mode: OFF
75+
build_type: Release
76+
package_generator: TBZ2
77+
78+
7279
# This exists solely to make sure a non-multiconfig build works
7380
- os: ubuntu-20.04
7481
compiler: gcc
@@ -97,6 +104,7 @@ jobs:
97104
generator: "Visual Studio 16 2019"
98105
build_type: Release
99106
developer_mode: Off
107+
package_generator: ZIP
100108

101109

102110

@@ -143,7 +151,7 @@ jobs:
143151

144152
- name: Configure CMake
145153
run: |
146-
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}} -DENABLE_LARGE_TESTS:BOOL=${{matrix.large_tests}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }}
154+
cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -DENABLE_DEVELOPER_MODE:BOOL=${{matrix.developer_mode}} -DENABLE_LARGE_TESTS:BOOL=${{matrix.large_tests}} -DOPT_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} -DGIT_SHA:STRING=${{ github.sha }}
147155
148156
- name: Build
149157
# Execute the build. You can specify a specific target with "--target <NAME>"
@@ -169,6 +177,19 @@ jobs:
169177
run: |
170178
OpenCppCoverage.exe --export_type cobertura:coverage.xml --cover_children -- ctest -C ${{matrix.build_type}}
171179
180+
- name: Build Package
181+
if: matrix.package_generator != ''
182+
working-directory: ./build
183+
run: |
184+
cpack -C ${{matrix.build_type}} -G ${{matrix.package_generator}}
185+
186+
- name: Release
187+
uses: softprops/action-gh-release@v1
188+
if: ${{ (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main') && matrix.package_generator != '' }}
189+
with:
190+
files: |
191+
build/*-*-*${{ matrix.build_type }}*-*-*.*
192+
172193
- name: Publish to codecov
173194
uses: codecov/codecov-action@v2
174195
with:

CMakeLists.txt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ set(CMAKE_CXX_EXTENSIONS OFF)
2020
# Add project_options v0.13.1
2121
# https://github.com/cpp-best-practices/project_options
2222
include(FetchContent)
23-
FetchContent_Declare(_project_options
23+
FetchContent_Declare(_project_options
2424
URL https://github.com/cpp-best-practices/project_options/archive/refs/heads/main.zip)
25-
# URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.13.1.zip)
25+
# URL https://github.com/cpp-best-practices/project_options/archive/refs/tags/v0.13.1.zip)
2626
FetchContent_MakeAvailable(_project_options)
2727
include(${_project_options_SOURCE_DIR}/Index.cmake)
2828

2929
# uncomment to enable vcpkg:
3030
# # Setup vcpkg - should be called before defining project()
3131
# run_vcpkg()
3232

33+
set(GIT_SHA "Unknown" CACHE STRING "SHA this build was generated from")
34+
string(SUBSTRING "${GIT_SHA}" 0 8 GIT_SHORT_SHA)
35+
3336
# Set the project name and language
34-
project(json2cpp VERSION 0.0.1 DESCRIPTION "Compiles JSON files into `static constexpr` C++ files" LANGUAGES CXX C)
37+
project(
38+
json2cpp
39+
VERSION 0.0.1
40+
DESCRIPTION "Compiles JSON files into `static constexpr` C++ files"
41+
LANGUAGES CXX C)
3542

3643
if(GENERATOR_IS_MULTI_CONFIG AND NOT CMAKE_BUILD_TYPE)
3744
# Make sure that all supported configuration types have their
@@ -72,17 +79,14 @@ dynamic_project_options(
7279
# GCC_WARNINGS # Override the defaults for the GCC warnings
7380
)
7481

75-
7682
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "9")
7783
target_link_libraries(project_options INTERFACE stdc++fs)
7884
endif()
7985

80-
8186
target_compile_features(project_options INTERFACE cxx_std_${USER_CXX_STANDARD})
8287

8388
option(ENABLE_LARGE_TESTS "Enable tests and tools that use the Energy+ schema file" ON)
8489

85-
8690
# Adding the src:
8791
add_subdirectory(src)
8892

@@ -111,4 +115,9 @@ endif()
111115
# set the startup project for the "play" button in MSVC
112116
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT json2cpp)
113117

118+
set(CPACK_PACKAGE_FILE_NAME
119+
"${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}-${GIT_SHORT_SHA}-${CMAKE_SYSTEM_NAME}-${CMAKE_BUILD_TYPE}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}")
120+
114121
include(CPack)
122+
123+

0 commit comments

Comments
 (0)