From a77050ebb99b6f6d5b637df214d1c37d6141ca7d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 6 Sep 2023 08:48:34 +0200 Subject: [PATCH] Update ci build scripts build on OS-latest with newest setup-cpp version ymllint all files fix typos and strip WS --- .CMakeUserPresets.json | 167 +++++++++++++++++++++++++ .github/workflows/ci.yml | 23 ++-- .github/workflows/codeql-analysis.yml | 114 ++++++++--------- .github/workflows/template-janitor.yml | 12 +- .gitlab-ci.yml | 51 ++++---- 5 files changed, 271 insertions(+), 96 deletions(-) create mode 100644 .CMakeUserPresets.json diff --git a/.CMakeUserPresets.json b/.CMakeUserPresets.json new file mode 100644 index 00000000..3ae5e967 --- /dev/null +++ b/.CMakeUserPresets.json @@ -0,0 +1,167 @@ +{ + "version": 6, + "cmakeMinimumRequired": { + "major": 3, + "minor": 26, + "patch": 0 + }, + "configurePresets": [ + { + "name": "default-config", + "hidden": true, + "generator": "Ninja", + "cacheVariables": { + "CMAKE_HOST_SYSTEM_PROCESSOR": "$penv{PROCESSOR_ARCHITECTURE}" + } + }, + { + "name": "common-config", + "description": "Settings for all toolchains", + "hidden": true, + "inherits": "default-config", + "binaryDir": "${sourceDir}/out/build/${presetName}", + "installDir": "${sourceDir}/out/install/${presetName}", + "cacheVariables": { + "ENABLE_DOXYGEN": false, + "ENABLE_CPPCHECK": false, + "ENABLE_CLANG_TIDY": false + }, + "vendor": { + "microsoft.com/VisualStudioRemoteSettings/CMake/1.0": { + "sourceDir": "$env{HOME}/.vs/$ms{projectDirName}" + } + } + }, + { + "name": "debug", + "displayName": "Debug", + "description": "Debug build type", + "inherits": "conf-unixlike-common", + "cacheVariables": { + "CMAKE_SKIP_INSTALL_RULES": true, + "CMAKE_BUILD_TYPE": "Debug", + "myproject_ENABLE_COVERAGE": true + } + }, + { + "name": "release", + "displayName": "Release", + "description": "Release build type", + "inherits": "conf-unixlike-common", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "ENABLE_DOXYGEN": true + } + } + ], + "testPresets": [ + { + "name": "common-test", + "description": + "Test CMake settings that apply to all configurations", + "hidden": true, + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": true + } + }, + { + "name": "debug", + "displayName": "Strict", + "description": "Enable output and stop on failure", + "inherits": "common-test", + "configuration": "Debug", + "configurePreset": "debug" + }, + { + "name": "release", + "displayName": "Strict", + "description": "Enable output and stop on failure", + "inherits": "common-test", + "configuration": "Release", + "configurePreset": "release" + } + ], + "buildPresets": [ + { + "name": "release", + "configurePreset": "release" + }, + { + "name": "install", + "configurePreset": "release", + "targets": [ + "install" + ] + }, + { + "name": "doxygen-docs", + "configurePreset": "release", + "targets": [ + "doxygen-docs" + ] + }, + { + "name": "debug", + "configurePreset": "debug" + } + ], + "packagePresets": [ + { + "name": "release", + "configurePreset": "release", + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "description": "Developer workflow without installation", + "name": "debug", + "steps": [ + { + "type": "configure", + "name": "debug" + }, + { + "type": "build", + "name": "debug" + }, + { + "type": "test", + "name": "debug" + } + ] + }, + { + "description": "Release workflow without test", + "name": "release", + "steps": [ + { + "name": "release", + "type": "configure" + }, + { + "name": "release", + "type": "build" + }, + { + "name": "release", + "type": "test" + }, + { + "name": "install", + "type": "build" + }, + { + "name": "release", + "type": "package" + } + ] + } + ] +} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db6c6110..800367fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ on: env: CLANG_TIDY_VERSION: "15.0.2" + CPM_SOURCE_CACHE: ~/.cache/CPM VERBOSE: 1 @@ -18,7 +19,7 @@ jobs: Test: runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: true # Recommendations: # * support at least 2 operating systems @@ -29,13 +30,13 @@ jobs: # and your own projects needs matrix: os: - - ubuntu-20.04 - - macos-10.15 - - windows-2019 + - ubuntu-latest + - macos-latest + - windows-2022 compiler: # you can specify the version after `-` like "llvm-15.0.2". - llvm-15.0.2 - - gcc-11 + - gcc generator: - "Ninja Multi-Config" build_type: @@ -49,13 +50,13 @@ jobs: exclude: # mingw is determined by this author to be too buggy to support - - os: windows-2019 - compiler: gcc-11 + - os: windows-2022 + compiler: gcc include: # Add appropriate variables for gcov version required. This will intentionally break # if you try to use a compiler that does not have gcov set - - compiler: gcc-11 + - compiler: gcc gcov_executable: gcov enable_ipo: On @@ -63,7 +64,7 @@ jobs: enable_ipo: Off gcov_executable: "llvm-cov gcov" - - os: macos-10.15 + - os: macos-latest enable_ipo: Off # Set up preferred package generators, for given build configurations @@ -72,8 +73,8 @@ jobs: package_generator: TBZ2 # This exists solely to make sure a non-multiconfig build works - - os: ubuntu-20.04 - compiler: gcc-11 + - os: ubuntu-latest + compiler: gcc generator: "Unix Makefiles" build_type: Debug gcov_executable: gcov diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index e21dc29e..66469ad7 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -48,60 +48,60 @@ jobs: steps: - - uses: actions/checkout@v3 - - - name: Setup Cache - uses: ./.github/actions/setup_cache - with: - compiler: ${{ matrix.compiler }} - build_type: ${{ matrix.build_type }} - packaging_maintainer_mode: ${{ matrix.packaging_maintainer_mode }} - generator: ${{ matrix.generator }} - - - name: Project Name - uses: cardinalby/export-env-action@v2 - with: - envFile: '.github/constants.env' - - - - name: Setup Cpp - uses: aminya/setup-cpp@v1 - with: - compiler: ${{ matrix.compiler }} - vcvarsall: ${{ contains(matrix.os, 'windows' )}} - - cmake: true - ninja: true - vcpkg: false - ccache: true - clangtidy: false - - cppcheck: false - - gcovr: false - opencppcoverage: false - - # make sure coverage is only enabled for Debug builds, since it sets -O0 to make sure coverage - # has meaningful results - - name: Configure CMake - run: | - cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -D${{ env.PROJECT_NAME }}_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.packaging_maintainer_mode}} -D${{ env.PROJECT_NAME }}_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - - - name: Build - # Execute the build. You can specify a specific target with "--target " - run: | - cmake --build ./build --config ${{matrix.build_type}} - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + - uses: actions/checkout@v3 + + - name: Setup Cache + uses: ./.github/actions/setup_cache + with: + compiler: ${{ matrix.compiler }} + build_type: ${{ matrix.build_type }} + packaging_maintainer_mode: ${{ matrix.packaging_maintainer_mode }} + generator: ${{ matrix.generator }} + + - name: Project Name + uses: cardinalby/export-env-action@v2 + with: + envFile: '.github/constants.env' + + + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + compiler: ${{ matrix.compiler }} + vcvarsall: ${{ contains(matrix.os, 'windows' )}} + + cmake: true + ninja: true + vcpkg: false + ccache: true + clangtidy: false + + cppcheck: false + + gcovr: false + opencppcoverage: false + + # make sure coverage is only enabled for Debug builds, since it sets -O0 to make sure coverage + # has meaningful results + - name: Configure CMake + run: | + cmake -S . -B ./build -G "${{matrix.generator}}" -DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} -D${{ env.PROJECT_NAME }}_PACKAGING_MAINTAINER_MODE:BOOL=${{matrix.packaging_maintainer_mode}} -D${{ env.PROJECT_NAME }}_ENABLE_COVERAGE:BOOL=${{ matrix.build_type == 'Debug' }} + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + + - name: Build + # Execute the build. You can specify a specific target with "--target " + run: | + cmake --build ./build --config ${{matrix.build_type}} + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/template-janitor.yml b/.github/workflows/template-janitor.yml index bc56ba05..a730a3ef 100644 --- a/.github/workflows/template-janitor.yml +++ b/.github/workflows/template-janitor.yml @@ -44,7 +44,7 @@ jobs: developer_mode: ${{ matrix.developer_mode }} generator: ${{ matrix.generator }} - - name: Get organization and project name + - name: Get organization and project name run: | echo "NEW_ORG=${{ github.repository_owner }}" >> $GITHUB_ENV echo "NEW_PROJECT=${{ github.event.repository.name }}" >> $GITHUB_ENV @@ -69,9 +69,9 @@ jobs: run: | # hyphens and dots in c++ identifiers are forbidden. Use underscores instead. NEW_SAFE_PROJECT=$(echo ${{ env.NEW_PROJECT }} | sed "s/-/_/g" | sed "s/\./_/g" ) - echo "NEW_SAFE_PROJECT=$NEW_SAFE_PROJECT" >> $GITHUB_ENV + echo "NEW_SAFE_PROJECT=$NEW_SAFE_PROJECT" >> $GITHUB_ENV - # Rename all cpp_starter_project occurences to current repository and remove this workflow + # Rename all cpp_starter_project occurrences to current repository and remove this workflow - name: Insert new org and project run: | # rename the CMake project to match the github project @@ -129,7 +129,6 @@ jobs: envFile: '.github/constants.env' - - name: Test simple configuration to make sure nothing broke run: | cmake -S . -B ./build -G "${{ matrix.generator }}" -DCMAKE_BUILD_TYPE:STRING=${{ matrix.build_type }} -D${{ env.NEW_SAFE_PROJECT }}_PACKAGING_MAINTAINER_MODE:BOOL=ON @@ -149,7 +148,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - template-rename: name: Renames template when a new name is detected runs-on: ubuntu-latest @@ -175,7 +173,7 @@ jobs: developer_mode: ${{ matrix.developer_mode }} generator: ${{ matrix.generator }} - - name: Get organization and project name + - name: Get organization and project name run: | echo "TEST_RUN=false" >> $GITHUB_ENV echo "NEW_ORG=${{ github.repository_owner }}" >> $GITHUB_ENV @@ -205,7 +203,7 @@ jobs: # Rename all cpp_starter_project occurrences to current repository and remove this workflow - name: Update repository to match new template information run: | - # Update the README and template files to match the new org / repository names + # Update the README and template files to match the new org / repository names sed -i "s|${{ env.TEMPLATE_REPOSITORY }}|${{ env.NEW_REPOSITORY }}|g" README.md ${{ env.TEMPLATES_PATH }}/template_repository sed -i "s|${{ env.TEMPLATE_NAME }}|${{ env.NEW_PROJECT }}|g" README.md ${{ env.TEMPLATES_PATH }}/template_name diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 727a39ae..477ba967 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,44 +6,53 @@ stages: .setup_linux: &setup_linux | DEBIAN_FRONTEND=noninteractive - # set time-zone TZ=Canada/Pacific ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone - # for downloading apt-get update -qq - apt-get install -y --no-install-recommends curl gnupg ca-certificates + apt-get install -y --no-install-recommends git make curl gnupg ca-certificates python3-pip - # keys used by apt apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 1E9377A2BA9EF27F +# with foldable multi-line commands .setup_cpp: &setup_cpp | - curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.10.0/setup_cpp_linux" - chmod +x setup_cpp_linux - ./setup_cpp_linux --compiler $compiler --cmake true --ninja true --conan true --ccache true --clangtidy true --clangformat true --cppcheck true - source ~/.profile - -.test: &test | - # Build and Test - cmake -S . -B ./build -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo - cmake --build ./build --config RelWithDebInfo + curl -LJO "https://github.com/aminya/setup-cpp/releases/download/v0.35.2/setup-cpp-x64-linux" + chmod +x setup-cpp-x64-linux + echo -e "section_end:"`date +%s`":.setup_cpp\r\e[0Ksection_start:"`date +%s`":hidden_section\r\e[0K setup cpp" + ./setup-cpp-x64-linux --compiler $compiler --cmake true --ninja true --ccache true \ + --clangtidy true --clangformat true --cppcheck true --gcovr true + source ~/.cpprc + echo -e "section_end:"`date +%s`":hidden_section\r\e[0Ksection_start:"`date +%s`":.setup_cpp\r\e[0K" + clang-tidy --version + cmake --version + ninja --version + gcc --version + +# with foldable multi-line commands +.build: + script: + - *setup_cpp + - echo -e "section_end:"`date +%s`":.build\r\e[0Ksection_start:"`date +%s`":hidden_section\r\e[0K configure" + - cmake -S . -B ./build -G Ninja -D CMAKE_BUILD_TYPE=Debug -D CMAKE_UNITY_BUILD=YES -D CMAKE_SKIP_INSTALL_RULES=YES + - echo -e "section_end:"`date +%s`":hidden_section\r\e[0Ksection_start:"`date +%s`":.build\r\e[0K" + - cmake --build ./build --config Debug + - cmake --build ./build --config Debug --target test + - gcovr . + +default: + before_script: + - *setup_linux test_linux_llvm: stage: test variables: compiler: llvm - script: - - *setup_linux - - *setup_cpp - - *test + extends: .build test_linux_gcc: stage: test variables: compiler: gcc - script: - - *setup_linux - - *setup_cpp - - *test + extends: .build