From 97390ddd2aa8e7ab3526bd7b1c16a580b3a4b4c1 Mon Sep 17 00:00:00 2001 From: Thomas Willetal Date: Mon, 5 Oct 2026 20:25:45 +0200 Subject: [PATCH 1/2] Update packaging to use gzip format and add release workflow --- .github/workflows/ci-build.yml | 2 +- .github/workflows/release.yml | 55 +++++++++++++++++++++++ README.md | 6 +-- ctprintf/CMakeLists.txt | 25 ++++++++--- ctprintf/cmake/DebianChangelog.cmake | 66 ++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 ctprintf/cmake/DebianChangelog.cmake diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index d20e6f4..1282d63 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -39,6 +39,6 @@ jobs: with: name: ctprintf-packages path: | - ctprintf/build/release/*.tar.zst + ctprintf/build/release/*.tar.gz build/debian/ if-no-files-found: error diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..47e17c0 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,55 @@ +name: Release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v7 + + - name: Install build dependencies + run: ./scripts/build-dependencies.sh + + - name: Verify release version + id: version + run: | + if [[ "$GITHUB_REF" != "refs/heads/main" ]]; then + echo "Releases must be run from the main branch." + exit 1 + fi + + debian_version="$(dpkg-parsechangelog --show-field Version)" + upstream_version="${debian_version%-*}" + tag="v${upstream_version}" + + if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null; then + echo "Tag ${tag} already exists." + exit 1 + fi + + echo "upstream_version=${upstream_version}" >>"$GITHUB_OUTPUT" + echo "tag=${tag}" >>"$GITHUB_OUTPUT" + + - name: Configure, build, test, and package + working-directory: ctprintf + run: cmake --workflow --fresh --preset release-workflow + + - name: Build Debian package + run: ./scripts/build-package.sh + + - name: Create GitHub release + uses: softprops/action-gh-release@v3 + with: + tag_name: ${{ steps.version.outputs.tag }} + target_commitish: ${{ github.sha }} + name: Release ${{ steps.version.outputs.tag }} + generate_release_notes: true + files: | + ctprintf/build/release/*.tar.gz + build/debian/*.deb + build/debian/*.buildinfo + build/debian/*.changes diff --git a/README.md b/README.md index 1095d44..44de987 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ ctest --test-dir build --output-on-failure ## Creating a package -CPack creates a Zstandard-compressed tarball containing the installable headers, +CPack creates a gzip-compressed tarball containing the installable headers, CMake package files, README, and license: ```bash @@ -151,8 +151,8 @@ cpack --config build/CPackConfig.cmake ``` The archive is written to the build directory and is named -`ctprintf--.tar.zst`, for example -`ctprintf-0.1.0-Linux.tar.zst`. +`ctprintf--.tar.gz`, for example +`ctprintf-0.1.0-Linux.tar.gz`. ## Installation and CMake integration diff --git a/ctprintf/CMakeLists.txt b/ctprintf/CMakeLists.txt index 5ece6f4..c11cb43 100644 --- a/ctprintf/CMakeLists.txt +++ b/ctprintf/CMakeLists.txt @@ -1,7 +1,16 @@ cmake_minimum_required(VERSION 3.25) -project(ctprintf VERSION 0.1.0 LANGUAGES CXX) +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include(DebianChangelog) +parse_debian_changelog("${CMAKE_SOURCE_DIR}/../debian/changelog") + +project( + ctprintf + VERSION ${DEBIAN_PROJECT_VERSION} + LANGUAGES CXX) include(GNUInstallDirs) +include(CMakePackageConfigHelpers) option(ENABLE_TESTING "Build and enable tests" OFF) @@ -35,11 +44,17 @@ install( NAMESPACE ctprintf:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf) -install(FILES cmake/ctprintf-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf) +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/ctprintf-config-version.cmake" + VERSION "${PROJECT_VERSION}" + COMPATIBILITY SameMinorVersion) install( - FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md ${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE - DESTINATION ${CMAKE_INSTALL_DOCDIR}) + FILES cmake/ctprintf-config.cmake "${CMAKE_CURRENT_BINARY_DIR}/ctprintf-config-version.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ctprintf) + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/../README.md ${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE + DESTINATION ${CMAKE_INSTALL_DOCDIR}) if(ENABLE_TESTING) include(CTest) @@ -47,7 +62,7 @@ if(ENABLE_TESTING) add_subdirectory(tests) endif() # ENABLE_TESTING -set(CPACK_GENERATOR "TZST") +set(CPACK_GENERATOR "TGZ") set(CPACK_PACKAGE_CONTACT "Thomas Willetal ") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Compile-time checked printf-style formatting library") set(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}") diff --git a/ctprintf/cmake/DebianChangelog.cmake b/ctprintf/cmake/DebianChangelog.cmake new file mode 100644 index 0000000..95c3e02 --- /dev/null +++ b/ctprintf/cmake/DebianChangelog.cmake @@ -0,0 +1,66 @@ +# cmake-format: off +# Function: parse_debian_changelog() +#---------------------------------------------------- +# Description: +# Parses a Debian-style debian/changelog file +# - DEBIAN_PROJECT_NAME : package name +# - DEBIAN_PROJECT_EPOCH : epoch (defaults to 0 if not present) +# - DEBIAN_PROJECT_VERSION : upstream version (e.g. 1.2.3) +# - DEBIAN_PROJECT_REVISION : Debian revision (e.g. -1, -2, etc.) +# +# Format of Debian version: +# [epoch:]upstream_version[-debian_revision] +# +# Example: +# some-prj (0.1.0-1) unstable; urgency=medium +# * Initial release +# +# Produces: +# DEBIAN_PROJECT_NAME = some-prj +# DEBIAN_PROJECT_EPOCH = 0 +# DEBIAN_PROJECT_VERSION = 0.1.0 +# DEBIAN_PROJECT_REVISION = 1 +# +# Reference: +# https://www.debian.org/doc/debian-policy/ch-controlfields.html#version +# cmake-format: on + +function(parse_debian_changelog CHANGELOG_FILE) + file(READ "${CHANGELOG_FILE}" changelog) + + string(REGEX MATCH "^[a-z]+[a-z0-9+-.]+" project_name "${changelog}") + + string(REGEX MATCH + "\\\((([0-9]+):)?(([0-9.]+)([A-Za-z0-9.+~]*))(-(([0-9.]*)([A-Za-z0-9.+~]*)))?\\\)" + _ ${changelog}) + + set(epoch "${CMAKE_MATCH_2}") + set(version "${CMAKE_MATCH_4}") + set(revision "${CMAKE_MATCH_7}") + + # Epoch fallback to 0 if not found + if(NOT epoch) + set(epoch "0") + endif() + if(NOT revision) + set(revision "0") + endif() + + set(DEBIAN_PROJECT_EPOCH + "${epoch}" + PARENT_SCOPE) + set(DEBIAN_PROJECT_VERSION + "${version}" + PARENT_SCOPE) + set(DEBIAN_PROJECT_REVISION + "${revision}" + PARENT_SCOPE) + set(DEBIAN_PROJECT_NAME + "${project_name}" + PARENT_SCOPE) + + message(STATUS "Set project name to: ${project_name}") + message(STATUS "Set project epoch to: ${epoch}") + message(STATUS "Set project version to: ${version}") + message(STATUS "Set project revision to: ${revision}") +endfunction() From 98d80fd7c3bf408afec8dc7bde39aee1e4c80203 Mon Sep 17 00:00:00 2001 From: Thomas Willetal Date: Mon, 5 Oct 2026 20:31:23 +0200 Subject: [PATCH 2/2] Add CI badge and latest release badge to README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 44de987..6385e53 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,10 @@ The library is intended for diagnostic output such as UART, ITM/SWO, log buffers, or host-side test buffers. It does not use `printf`, iostreams, `std::string`, or dynamic allocation itself. + +[![CI](https://github.com/embtom/ctprintf/actions/workflows/ci-build.yml/badge.svg)](https://github.com/embtom/ctprintf/actions/workflows/ci-build.yml) +[![Latest release](https://img.shields.io/github/v/release/embtom/ctprintf)](https://github.com/embtom/ctprintf/releases) + ## Features - C++20 header-only library