From 8e360304ece538dc04fe76fea1c6b5ec1ba687e9 Mon Sep 17 00:00:00 2001 From: kamchatka-volcano Date: Fri, 27 Sep 2024 16:45:47 +0500 Subject: [PATCH] -configured Docker to build Linux release; -added release ci config; -added clang-format config; --- .clang-format | 60 ++++++++++++++++++++++++++++ .github/workflows/build_and_test.yml | 20 +++++----- .github/workflows/release.yml | 60 ++++++++++++++++++++++++++++ Dockerfile | 27 +++++++++++++ src/node_utils.cpp | 2 + 5 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 .clang-format create mode 100644 .github/workflows/release.yml create mode 100644 Dockerfile diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..f921912 --- /dev/null +++ b/.clang-format @@ -0,0 +1,60 @@ +--- +BasedOnStyle: WebKit +AlignAfterOpenBracket: AlwaysBreak +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortLambdasOnASingleLine: Empty +AllowShortEnumsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortBlocksOnASingleLine: Empty +AlwaysBreakTemplateDeclarations: Yes +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterFunction: true + BeforeElse: true + BeforeLambdaBody: true + BeforeWhile: true + BeforeCatch: true +BreakBeforeBraces: Custom +BreakBeforeBinaryOperators: None +BreakInheritanceList: AfterComma +ColumnLimit: 120 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: true +NamespaceIndentation: None +PenaltyBreakBeforeFirstCallParameter: 0 +PenaltyReturnTypeOnItsOwnLine: 1000 +PenaltyBreakAssignment: 10 +SpaceBeforeCpp11BracedList: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpaceAfterTemplateKeyword: false +SpacesInLineCommentPrefix: + Minimum: 0 + Maximum: -1 +FixNamespaceComments: true +UseCRLF: false +IncludeCategories: + # Headers in <> without extension. + - Regex: '<[[:alnum:]\-_]+>' + Priority: 6 + # Headers in <> from specific external libraries. + - Regex: '<(gtest|gmock|boost|gsl)\/' + Priority: 5 + # Headers in <> with subdirectory. + - Regex: '<[[:alnum:]\-_]+\/' + Priority: 4 + # Headers in <> with extension. + - Regex: '<[[:alnum:].\-_]+>' + Priority: 3 + # Headers in "" with subdirectory. + - Regex: '"[[:alnum:]\-_]+\/' + Priority: 2 + # Headers in "" with extension. + - Regex: '"[[:alnum:].\-_]+"' + Priority: 1 +... diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 5f64559..888fab5 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -13,11 +13,8 @@ on: jobs: build: - name: ${{ matrix.config.name }} (nameof = ${{ matrix.use_nameof }}) + name: ${{ matrix.config.name }} runs-on: ${{ matrix.config.os }} - env: - CC: ${{ matrix.config.cc }} - CXX: ${{ matrix.config.cxx }} strategy: fail-fast: false @@ -56,7 +53,7 @@ jobs: - uses: ilammy/msvc-dev-cmd@v1 - name: Configure CMake - run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_EXAMPLES=ON + run: cmake --preset=${{ matrix.config.cmake-preset }} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_EXAMPLES=ON - name: Build run: cmake --build ${{github.workspace}}/build --config Release @@ -73,8 +70,9 @@ jobs: find build/examples -type f -name "*.so" -exec cp {} examples-build \; find build/examples -type f -name "*.dll" -exec cp {} examples-build \; - - name: Upload build artifact - uses: actions/upload-artifact@v3 + - name: Upload examples build artifact + if: matrix.config.cmake-preset != 'gcc-release' + uses: actions/upload-artifact@v4 with: name: hypertextcpp-examples-${{ matrix.config.os }} path: | @@ -101,12 +99,12 @@ jobs: shell_command: "", } steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - if: matrix.config.name == 'Windows' uses: msys2/setup-msys2@v2 with: path-type: inherit - - uses: robinraju/release-downloader@v1.7 + - uses: robinraju/release-downloader@v1.11 with: repository: "kamchatka-volcano/lunchtoast" latest: true @@ -119,7 +117,7 @@ jobs: run: chmod +x lunchtoast - name: Download hypertextcpp examples build id: pre_launch_tests - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: hypertextcpp-examples-${{ matrix.config.os }} path: examples-build @@ -140,7 +138,7 @@ jobs: run: lunchtoast/lunchtoast functional_tests ${{ matrix.config.shell_command }} -collectFailedTests=failed_tests -config="ci.cfg" - name: Upload failed tests if: failure() && steps.launch_tests.outcome != 'success' && steps.pre_launch_tests.outcome == 'success' - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: hypertextcpp-failed-tests-${{ matrix.config.os }} path: failed_tests diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..2b5aee5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,60 @@ +name: release + +on: + push: + tags: [ "v*" ] + +jobs: + build-windows: + name: Build Windows version + runs-on: windows-latest + steps: + - name: Install ninja + run: choco install ninja + + - uses: actions/checkout@v4 + - uses: rui314/setup-mold@v1 + - uses: ilammy/msvc-dev-cmd@v1 + + - name: Configure CMake + run: cmake --preset=msvc-release -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release + + - name: Build + run: cmake --build ${{github.workspace}}/build --config Release + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: hypertextcpp-windows-latest + path: | + ${{github.workspace}}/build/hypertextcpp.exe + + release_hypertextcpp: + name: Release hypertextcpp + runs-on: ubuntu-latest + needs: build-windows + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Build linux version in Docker + run: DOCKER_BUILDKIT=1 docker build --build-arg cmake_preset=clang-release --output build . + + - name: Run unit tests + working-directory: ${{github.workspace}}/build/tests + run: ./test_hypertextcpp + + - name: Download hypertextcpp Windows build + uses: actions/download-artifact@v4 + with: + name: hypertextcpp-windows-latest + path: build + - name: Archive shared_lib_api + run: zip -r shared_lib_api.zip shared_lib_api + - name: Upload release + uses: softprops/action-gh-release@v2 + with: + files: | + build/hypertextcpp + build/hypertextcpp.exe + shared_lib_api.zip \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d28abe0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM alpine:3.18.3 AS hypertextcpp-build-container +ARG cmake_preset +RUN apk update && \ + apk add --no-cache \ + git \ + build-base \ + ccache \ + cmake \ + clang \ + clang-dev \ + mold \ + samurai + +WORKDIR /hypertextcpp_src +COPY external ./external/ +COPY src ./src/ +COPY tests ./tests/ +COPY CMakeLists.txt . +COPY CMakePresets.json . +RUN cmake --preset "$cmake_preset" -B build -DCMAKE_BUILD_TYPE=MinSizeRel -DCMAKE_EXE_LINKER_FLAGS="-static" -DENABLE_TESTS=ON +RUN cmake --build build +RUN strip --strip-all build/hypertextcpp + + +FROM scratch AS hypertextcpp-build +COPY --from=hypertextcpp-build-container /hypertextcpp_src/build/hypertextcpp . +COPY --from=hypertextcpp-build-container /hypertextcpp_src/build/tests/test_hypertextcpp ./tests/ diff --git a/src/node_utils.cpp b/src/node_utils.cpp index 4a7fca5..45f0d92 100644 --- a/src/node_utils.cpp +++ b/src/node_utils.cpp @@ -1,4 +1,6 @@ #include "node_utils.h" +#include +#include namespace htcpp{