Skip to content

Commit f60582c

Browse files
committed
feature: Generate Debian packages with CPack
1 parent 7558348 commit f60582c

File tree

13 files changed

+156
-27
lines changed

13 files changed

+156
-27
lines changed

.github/actions/generate/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ inputs:
3737
description: Whether to use mold linker
3838
required: true
3939
default: "false"
40+
package:
41+
description: Whether to generate Linux binary packages
42+
required: true
43+
default: "true"
4044

4145
runs:
4246
using: composite
@@ -55,6 +59,7 @@ runs:
5559
BENCHMARK_OPTION: "${{ inputs.build_benchmark == 'true' && 'True' || 'False' }}"
5660
TIME_TRACE: "${{ inputs.time_trace == 'true' && 'True' || 'False' }}"
5761
USE_MOLD: "${{ inputs.use_mold == 'true' && 'True' || 'False' }}"
62+
PACKAGE: "${{ inputs.package == 'true' && 'True' || 'False' }}"
5863
run: |
5964
cd build
6065
conan \
@@ -70,6 +75,7 @@ runs:
7075
-o "&:coverage=${CODE_COVERAGE}" \
7176
-o "&:time_trace=${TIME_TRACE}" \
7277
-o "&:use_mold=${USE_MOLD}" \
78+
-o "&:package=${PACKAGE}" \
7379
--profile:all "${{ inputs.conan_profile }}"
7480
7581
- name: Run cmake

.github/workflows/build.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,23 @@ jobs:
8585
secrets:
8686
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8787

88+
package:
89+
name: Build packages
90+
91+
uses: ./.github/workflows/build_impl.yml
92+
with:
93+
runs_on: heavy
94+
container: '{ "image": "ghcr.io/xrplf/clio-ci:0d262e74bcd286ccd6fc36e45990ff2e6b8d8430" }'
95+
conan_profile: gcc
96+
build_type: Release
97+
disable_cache: false
98+
code_coverage: false
99+
static: true
100+
upload_clio_server: false
101+
package: true
102+
targets: package
103+
analyze_build_time: false
104+
88105
check_config:
89106
name: Check Config Description
90107
needs: build-and-test

.github/workflows/build_and_test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ on:
6363
type: string
6464
default: ""
6565

66+
package:
67+
description: Build Linux deb package
68+
required: false
69+
type: boolean
70+
default: true
71+
6672
jobs:
6773
build:
6874
uses: ./.github/workflows/build_impl.yml
@@ -78,6 +84,7 @@ jobs:
7884
targets: ${{ inputs.targets }}
7985
analyze_build_time: false
8086
expected_version: ${{ inputs.expected_version }}
87+
package: ${{ inputs.package }}
8188

8289
test:
8390
needs: build

.github/workflows/build_impl.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ on:
5959
type: string
6060
default: ""
6161

62+
package:
63+
description: Build Linux deb package
64+
required: false
65+
type: boolean
66+
6267
secrets:
6368
CODECOV_TOKEN:
6469
required: false
@@ -111,6 +116,7 @@ jobs:
111116
static: ${{ inputs.static }}
112117
time_trace: ${{ inputs.analyze_build_time }}
113118
use_mold: ${{ runner.os != 'macOS' }}
119+
package: ${{ inputs.package }}
114120

115121
- name: Build Clio
116122
uses: ./.github/actions/build_clio
@@ -171,6 +177,13 @@ jobs:
171177
name: clio_integration_tests_${{ runner.os }}_${{ inputs.build_type }}_${{ inputs.conan_profile }}
172178
path: build/clio_integration_tests
173179

180+
- name: Upload Clio Linux package
181+
if: inputs.package
182+
uses: actions/upload-artifact@v4
183+
with:
184+
name: Clio_debian_package
185+
path: build/*.deb
186+
174187
- name: Save cache
175188
if: ${{ !inputs.disable_cache && github.ref == 'refs/heads/develop' }}
176189
uses: ./.github/actions/save_cache

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ if (docs)
9494
endif ()
9595

9696
include(install/install)
97-
if (packaging)
98-
include(cmake/packaging.cmake) # This file exists only in build runner
97+
if (package)
98+
include(ClioPackage)
9999
endif ()
100100

101101
if (snapshot)

cmake/ClioPackage.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
set(CPACK_PACKAGING_INSTALL_PREFIX "/opt/clio")
2+
include("${CMAKE_CURRENT_LIST_DIR}/ClioVersion.cmake")
3+
4+
set(VERSION ${CLIO_VERSION})
5+
6+
if (VERSION MATCHES "^([0-9]+)\.([0-9]+)\.([0-9]+)(-(b|rc|hf)([0-9]+))?$|^([0-9a-zA-Z]+)-(.+)-([0-9a-fA-F]+)$")
7+
if (CMAKE_MATCH_2)
8+
set(MAJOR "${CMAKE_MATCH_1}")
9+
set(MINOR "${CMAKE_MATCH_2}")
10+
set(PATCH "${CMAKE_MATCH_3}")
11+
message(DEBUG " Major: ${MAJOR}")
12+
message(DEBUG " Minor: ${MINOR}")
13+
message(DEBUG " Patch: ${PATCH}")
14+
set(release_type "release ${MAJOR}.${MINOR}.${PATCH}")
15+
if (CMAKE_MATCH_4)
16+
set(PRE_TYPE "${CMAKE_MATCH_5}")
17+
set(PRE_NUM "${CMAKE_MATCH_6}")
18+
message(DEBUG " Pre-release type: ${PRE_TYPE}")
19+
message(DEBUG " Pre-release number number: ${PRE_NUM}")
20+
set(release_type "pre-${release_type}-${PRE_TYPE}-${PRE_NUM}")
21+
endif ()
22+
else ()
23+
set(DATE "${CMAKE_MATCH_7}")
24+
set(BRANCH "${CMAKE_MATCH_8}")
25+
set(GIT_HASH "${CMAKE_MATCH_9}")
26+
message(DEBUG " Date: ${DATE}")
27+
message(DEBUG " Branch: ${BRANCH}")
28+
message(DEBUG " Git hash: ${GIT_HASH}")
29+
set(release_type "development ${DATE}-${BRANCH}-${GIT_HASH}")
30+
endif ()
31+
set(CPACK_PACKAGE_VERSION "${CMAKE_MATCH_0}")
32+
else ()
33+
message(FATAL_ERROR "Version string '${CLIO_VERSION}' did not match expected patterns.")
34+
endif ()
35+
36+
message(STATUS "Release type: ${release_type}")
37+
38+
set(CPACK_STRIP_FILES TRUE)
39+
40+
include(pkg/deb)
41+
include(CPack)

cmake/ClioVersion.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ else ()
3434
OUTPUT_STRIP_TRAILING_WHITESPACE COMMAND_ERROR_IS_FATAL ANY
3535
)
3636

37+
if (BRANCH STREQUAL "")
38+
set(BRANCH "dev")
39+
endif ()
40+
3741
set(CLIO_VERSION "${DATE}-${BRANCH}-${REV}")
3842
set(DOC_CLIO_VERSION "develop")
3943
endif ()

cmake/install/clio.service.in

Lines changed: 0 additions & 17 deletions
This file was deleted.

cmake/install/install.cmake

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
set(CLIO_INSTALL_DIR "/opt/clio")
2-
set(CMAKE_INSTALL_PREFIX ${CLIO_INSTALL_DIR})
2+
set(CMAKE_INSTALL_PREFIX "${CLIO_INSTALL_DIR}" CACHE PATH "Install prefix" FORCE)
33

4-
install(TARGETS clio_server DESTINATION bin)
4+
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
5+
6+
include(GNUInstallDirs)
7+
8+
install(TARGETS clio_server DESTINATION ${CMAKE_INSTALL_BINDIR})
59

610
file(READ docs/examples/config/example-config.json config)
711
string(REGEX REPLACE "./clio_log" "/var/log/clio/" config "${config}")
812
file(WRITE ${CMAKE_BINARY_DIR}/install-config.json "${config}")
913
install(FILES ${CMAKE_BINARY_DIR}/install-config.json DESTINATION etc RENAME config.json)
10-
11-
configure_file("${CMAKE_SOURCE_DIR}/cmake/install/clio.service.in" "${CMAKE_BINARY_DIR}/clio.service")
12-
13-
install(FILES "${CMAKE_BINARY_DIR}/clio.service" DESTINATION /lib/systemd/system)

cmake/pkg/deb.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
set(CPACK_GENERATOR "DEB")
2+
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/XRPLF/clio")
3+
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Ripple Labs Inc. <support@ripple.com>")
4+
5+
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
6+
7+
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
8+
9+
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${CMAKE_SOURCE_DIR}/cmake/pkg/postinst)
10+
11+
if (PKG_RELEASE GREATER 0)
12+
set(CPACK_DEBIAN_PACKAGE_RELEASE ${PKG_RELEASE} CACHE STRING "Debian package release number")
13+
endif ()
14+
15+
if (DEFINED PRE_TYPE)
16+
string(REPLACE "-" "~" CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
17+
endif ()

0 commit comments

Comments
 (0)