From baa5c9ccd048c86273109cb9fc29b651b50fe2d1 Mon Sep 17 00:00:00 2001 From: Petra Baranski Date: Thu, 27 Jul 2023 18:12:13 +0200 Subject: [PATCH] ci: create release workflow --- .github/workflows/create-release-package.yml | 33 +++++++++++++++ CHANGELOG.md | 1 + CMakeLists.txt | 43 +++++++++----------- README.md | 32 ++++++++++++++- tests/CMakeLists.txt | 19 +++++++++ 5 files changed, 102 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/create-release-package.yml diff --git a/.github/workflows/create-release-package.yml b/.github/workflows/create-release-package.yml new file mode 100644 index 0000000..4120b30 --- /dev/null +++ b/.github/workflows/create-release-package.yml @@ -0,0 +1,33 @@ +name: release +permissions: + contents: write + +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.25.0" # <--= optional, use most recent 3.25.x version + ninjaVersion: "^1.11.1" # <--= optional, use most recent 1.x version + + - name: create zip + run: | + mkdir tmp + cd tmp + cmake -DMADDY_CREATE_PACKAGE=ON .. + make maddy_package + + - name: create release + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/maddy-src.zip + tag: ${{ github.ref }} + body: "You can find all changes of this release in the [changelog](https://github.com/progsource/maddy/blob/master/CHANGELOG.md)" diff --git a/CHANGELOG.md b/CHANGELOG.md index 53c160f..8334afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ maddy uses [semver versioning](https://semver.org/). * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) class attribute to code blocks if there is text after the three backticks like ` ```cpp` * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) optional support for latex blocks - it's off by default * ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) version info to the parser class +* ![**ADDED**](https://img.shields.io/badge/-ADDED-%23099) GitHub workflow for release, so that one can include maddy easier via cmake's `FetchContent` * ? ## version 1.1.2 2020-10-04 diff --git a/CMakeLists.txt b/CMakeLists.txt index af99f39..1481d49 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,49 +7,33 @@ project(maddy) # ------------------------------------------------------------------------------ -set(MADDY_CPP_VERSION 14) -add_definitions(-DCPP_VERSION=${MADDY_CPP_VERSION}) - -# ------------------------------------------------------------------------------ - set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build) set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) # ------------------------------------------------------------------------------ -option(MADDY_BUILD_WITH_TESTS "enable building tests" OFF) +option(MADDY_BUILD_WITH_TESTS "enable building tests - does not work with zip download" OFF) if(${MADDY_BUILD_WITH_TESTS}) enable_testing() endif() +option(MADDY_CREATE_PACKAGE "create a package for a version release" OFF) + # ------------------------------------------------------------------------------ set(MADDY_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) # ------------------------------------------------------------------------------ -if (UNIX) - set( - CMAKE_CXX_FLAGS - "${CMAKE_CXX_FLAGS} -g -std=c++${MADDY_CPP_VERSION} -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions -fsanitize=address -fno-omit-frame-pointer" - ) +if(NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 14) endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) -# ------------------------------------------------------------------------------ - -if (UNIX AND NOT APPLE) - execute_process(COMMAND ${CMAKE_CXX_COMPILER} - -fuse-ld=gold -Wl,--version - ERROR_QUIET OUTPUT_VARIABLE ld_version) - if ("${ld_version}" MATCHES "GNU gold") - message(STATUS "Found Gold linker, use faster linker") - set(CMAKE_EXE_LINKER_FLAGS - "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") - set(CMAKE_SHARED_LINKER_FLAGS - "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold ") - endif() +if(${CMAKE_CXX_STANDARD} LESS 14) + message(FATAL_ERROR "maddy requires >=C++14") endif() # ------------------------------------------------------------------------------ @@ -64,3 +48,14 @@ target_include_directories(maddy INTERFACE if(${MADDY_BUILD_WITH_TESTS}) add_subdirectory(tests) endif() + +# ------------------------------------------------------------------------------ + +if(${MADDY_CREATE_PACKAGE}) + set(MADDY_PACKAGE_FILES include/ CMakeLists.txt LICENSE) + add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip + COMMAND ${CMAKE_COMMAND} -E tar c ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip --format=zip -- ${MADDY_PACKAGE_FILES} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${MADDY_PACKAGE_FILES}) + add_custom_target(${PROJECT_NAME}_package DEPENDS ${CMAKE_BINARY_DIR}/${PROJECT_NAME}-src.zip) +endif() diff --git a/README.md b/README.md index 91adfd5..d9ff99a 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,40 @@ It is tested to work on: ## Why maddy? -When I was needing a Markdown parser in C++ I couldn't find any, that was +When I looking for a Markdown parser in C++, I couldn't find any, that was fitting my needs. So I simply wrote my own one. ## Markdown syntax The supported syntax can be found in the [definitions docs](docs/definitions.md). +## How to add maddy to your cmake project + +You can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) +which was introduced in CMake 3.11. + +This way you can add + +```cmake +include(FetchContent) + +FetchContent_Declare( + maddy + URL https://github.com/progsource/maddy/.../maddy-src.zip +) +FetchContent_MakeAvailable(maddy) + +add_executable(my_exe) +target_link_libraries(my_exe PUBLIC maddy) +``` + +to your CMake file to make it work. Check the +[release](https://github.com/progsource/maddy/releases) for the full +zip-file-url. + +The zip only contains a `CMakeLists.txt`, the `include` folder and the `LICENSE` +file. + ## How to use To use maddy in your project, simply add the include path of maddy to yours @@ -52,7 +79,8 @@ std::shared_ptr parser = std::make_shared(config); std::string htmlOutput = parser->Parse(markdownInput); ``` -You can find all parser flags in [`include/maddy/parserconfig.h`](include/maddy/parserconfig.h). +You can find all parser flags in +[`include/maddy/parserconfig.h`](include/maddy/parserconfig.h). ## How to run the tests diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d8b9b2f..2fdaea7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,21 @@ # This project is licensed under the MIT license. For more information see the # LICENSE file. +if (UNIX AND NOT APPLE) + execute_process(COMMAND ${CMAKE_CXX_COMPILER} + -fuse-ld=gold -Wl,--version + ERROR_QUIET OUTPUT_VARIABLE ld_version) + if ("${ld_version}" MATCHES "GNU gold") + message(STATUS "Found Gold linker, use faster linker") + set(CMAKE_EXE_LINKER_FLAGS + "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=gold") + set(CMAKE_SHARED_LINKER_FLAGS + "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=gold ") + endif() +endif() + +# ------------------------------------------------------------------------------ + include(FetchContent) FetchContent_Declare( @@ -25,4 +40,8 @@ target_include_directories(MaddyTests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) target_link_libraries(MaddyTests maddy gmock_main) +set_target_properties(MaddyTests PROPERTIES + CMAKE_CXX_FLAGS + "${CMAKE_CXX_FLAGS} -g -Wall -Wpedantic -Wextra -Wno-ignored-qualifiers -fno-rtti -fno-exceptions -fsanitize=address -fno-omit-frame-pointer" +) add_test(NAME MaddyTests COMMAND MaddyTests)