From 144ca1aa4faf7d7fbe0f2d4245fa47be77bec302 Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 20 Jul 2025 07:38:46 +0330 Subject: [PATCH] refactor: extract shell commands from .drone.yml to separate script files --- .drone.yml | 96 ++------------------ tools/ci/steps/amd64_clang_sanitizer_leak.sh | 23 +++++ tools/ci/steps/amd64_gcc_tests.sh | 16 ++++ tools/ci/steps/amd64_gcc_valgrind.sh | 12 +++ tools/ci/steps/amd64_msvc_tests.ps1 | 16 ++++ tools/ci/steps/static_analysis.sh | 12 +++ tools/ci/steps/style.sh | 18 ++++ 7 files changed, 103 insertions(+), 90 deletions(-) create mode 100755 tools/ci/steps/amd64_clang_sanitizer_leak.sh create mode 100755 tools/ci/steps/amd64_gcc_tests.sh create mode 100755 tools/ci/steps/amd64_gcc_valgrind.sh create mode 100644 tools/ci/steps/amd64_msvc_tests.ps1 create mode 100755 tools/ci/steps/static_analysis.sh create mode 100755 tools/ci/steps/style.sh diff --git a/.drone.yml b/.drone.yml index 0835ece..1c2e327 100644 --- a/.drone.yml +++ b/.drone.yml @@ -12,23 +12,7 @@ platform: steps: - name: tests shell: powershell - commands: | - conan profile detect - - conan build . -s compiler.cppstd=20 -s build_type=Release - - $tests = Get-ChildItem -Path "./build" -Recurse -File | Where-Object { - $_.Name -like "*_tests.exe" - } - - foreach ($test in $tests) { - Write-Host "Running $($test.FullName)" - & $test.FullName - if ($LASTEXITCODE -ne 0) { - Write-Error "Test $($test.Name) failed! T_T" - exit $LASTEXITCODE - } - } + commands: ./tools/ci/steps/amd64_msvc_tests.ps1 --- kind: pipeline @@ -42,20 +26,7 @@ steps: - name: tests image: unit_tests:latest pull: if-not-exists - commands: | - set -e - conan build . \ - -c tools.system.package_manager:mode=install \ - -c tools.cmake.cmaketoolchain:generator=Ninja \ - -s build_type=Release \ - -o enable_tests=True \ - -o use_mold=True \ - --build=missing - - for test in $(find ./build -type f -name '*_tests' -executable); do - echo "Running $test" - "$test" - done + commands: ./tools/ci/steps/amd64_gcc_tests.sh --- kind: pipeline @@ -69,17 +40,7 @@ steps: - name: valgrind image: valgrind:latest pull: if-not-exists - commands: | - set -e - conan build . \ - -c tools.system.package_manager:mode=install \ - -c tools.cmake.cmaketoolchain:generator=Ninja \ - -s build_type=Release \ - -o enable_tests=True \ - -o use_mold=True \ - --build=missing - - find ./build -type f -name "*_tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 + commands: ./tools/ci/steps/amd64_gcc_valgrind.sh --- kind: pipeline @@ -93,26 +54,7 @@ steps: - name: leak sanitizer image: leak_sanitizer:latest pull: if-not-exists - commands: | - set -e - conan build . \ - -c tools.system.package_manager:mode=install \ - -c tools.cmake.cmaketoolchain:generator=Ninja \ - -c tools.build:cxxflags='["-g", "-fno-omit-frame-pointer", "-nostdinc++", "-isystem", "/libcxx_lsan/include/c++/v1/", "-fsanitize=leak"]' \ - -c tools.build:sharedlinkflags='["-L/libcxx_lsan/lib", "-Wl,-rpath,/libcxx_lsan/lib", "-lc++", "-lc++abi", "-fsanitize=leak"]' \ - -c tools.build:exelinkflags='["-L/libcxx_lsan/lib", "-Wl,-rpath,/libcxx_lsan/lib", "-lc++", "-lc++abi", "-fsanitize=leak"]' \ - -c tools.info.package_id:confs='["tools.build:cxxflags","tools.build:sharedlinkflags","tools.build:exelinkflags"]' \ - -c tools.build:compiler_executables='{"c": "clang", "cpp": "clang++"}' \ - -s build_type=Release \ - -s compiler=clang \ - -s compiler.version=20 \ - -s compiler.libcxx=libc++ \ - -o use_mold=True \ - --build=missing - for test in $(find ./build -type f -name '*_tests' -executable); do - echo "Running $test" - "$test" - done + commands: ./tools/ci/steps/amd64_clang_sanitizer_leak.sh --- kind: pipeline @@ -127,16 +69,7 @@ steps: image: static_analysis:latest pull: if-not-exists privileged: true - commands: - - | - conan build . \ - -c tools.system.package_manager:mode=install \ - -c tools.cmake.cmaketoolchain:generator=Ninja \ - -s build_type=Release \ - -o enable_static_analysis=True \ - -o enable_tests=True \ - -o use_mold=True \ - --build=missing + commands: ./tools/ci/steps/static_analysis.sh --- kind: pipeline @@ -150,21 +83,4 @@ steps: - name: clang format image: clang_format:latest pull: if-not-exists - commands: | - set -e - clang-format --version - has_fomatting_issues=0 - - for file in $(find ./modules -name '*.?pp'); do - echo "Checking format for $file" - if ! clang-format --dry-run --Werror "$file"; then - echo "❌ Formatting issue detected in $file" - has_fomatting_issues=1 - fi - done - - if [ "$has_fomatting_issues" -eq 0 ]; then - echo "✅ All files are properly formatted! Well done! ^~^" - fi - - exit ${has_fomatting_issues} + commands: ./tools/ci/steps/style.sh diff --git a/tools/ci/steps/amd64_clang_sanitizer_leak.sh b/tools/ci/steps/amd64_clang_sanitizer_leak.sh new file mode 100755 index 0000000..4a6871f --- /dev/null +++ b/tools/ci/steps/amd64_clang_sanitizer_leak.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +set -e + +conan build . \ + -c tools.system.package_manager:mode=install \ + -c tools.cmake.cmaketoolchain:generator=Ninja \ + -c tools.build:cxxflags='["-g", "-fno-omit-frame-pointer", "-nostdinc++", "-isystem", "/libcxx_lsan/include/c++/v1/", "-fsanitize=leak"]' \ + -c tools.build:sharedlinkflags='["-L/libcxx_lsan/lib", "-Wl,-rpath,/libcxx_lsan/lib", "-lc++", "-lc++abi", "-fsanitize=leak"]' \ + -c tools.build:exelinkflags='["-L/libcxx_lsan/lib", "-Wl,-rpath,/libcxx_lsan/lib", "-lc++", "-lc++abi", "-fsanitize=leak"]' \ + -c tools.info.package_id:confs='["tools.build:cxxflags","tools.build:sharedlinkflags","tools.build:exelinkflags"]' \ + -c tools.build:compiler_executables='{"c": "clang", "cpp": "clang++"}' \ + -s build_type=Release \ + -s compiler=clang \ + -s compiler.version=20 \ + -s compiler.libcxx=libc++ \ + -o use_mold=True \ + --build=missing + +for test in $(find ./build -type f -name '*_tests' -executable); do + echo "Running $test" + "$test" +done diff --git a/tools/ci/steps/amd64_gcc_tests.sh b/tools/ci/steps/amd64_gcc_tests.sh new file mode 100755 index 0000000..208ee8d --- /dev/null +++ b/tools/ci/steps/amd64_gcc_tests.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e + +conan build . \ + -c tools.system.package_manager:mode=install \ + -c tools.cmake.cmaketoolchain:generator=Ninja \ + -s build_type=Release \ + -o enable_tests=True \ + -o use_mold=True \ + --build=missing + +for test in $(find ./build -type f -name '*_tests' -executable); do + echo "Running $test" + "$test" +done diff --git a/tools/ci/steps/amd64_gcc_valgrind.sh b/tools/ci/steps/amd64_gcc_valgrind.sh new file mode 100755 index 0000000..cba4ed7 --- /dev/null +++ b/tools/ci/steps/amd64_gcc_valgrind.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e +conan build . \ + -c tools.system.package_manager:mode=install \ + -c tools.cmake.cmaketoolchain:generator=Ninja \ + -s build_type=Release \ + -o enable_tests=True \ + -o use_mold=True \ + --build=missing + +find ./build -type f -name "*_tests" -executable | xargs -I {} bash -c 'valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --error-exitcode=255 {}' || exit 1 diff --git a/tools/ci/steps/amd64_msvc_tests.ps1 b/tools/ci/steps/amd64_msvc_tests.ps1 new file mode 100644 index 0000000..fd603bb --- /dev/null +++ b/tools/ci/steps/amd64_msvc_tests.ps1 @@ -0,0 +1,16 @@ +conan profile detect +conan build . -s compiler.cppstd=20 -s build_type=Release + +$tests = Get-ChildItem -Path "./build" -Recurse -File | Where-Object { + $_.Name -like "*_tests.exe" +} + +foreach ($test in $tests) { + Write-Host "Running $($test.FullName)" + & $test.FullName + if ($LASTEXITCODE -ne 0) { + Write-Error "Test $($test.Name) failed! T_T" + exit $LASTEXITCODE + } +} + diff --git a/tools/ci/steps/static_analysis.sh b/tools/ci/steps/static_analysis.sh new file mode 100755 index 0000000..c44974a --- /dev/null +++ b/tools/ci/steps/static_analysis.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +conan build . \ +-c tools.system.package_manager:mode=install \ +-c tools.cmake.cmaketoolchain:generator=Ninja \ +-s build_type=Release \ +-o enable_static_analysis=True \ +-o enable_tests=True \ +-o use_mold=True \ +--build=missing diff --git a/tools/ci/steps/style.sh b/tools/ci/steps/style.sh new file mode 100755 index 0000000..6c1aa46 --- /dev/null +++ b/tools/ci/steps/style.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +has_fomatting_issues=0 +for file in $(find ./modules -name '*.?pp'); do + echo "Checking format for $file" + if ! clang-format --dry-run --Werror "$file"; then + echo "❌ Formatting issue detected in $file" + has_fomatting_issues=1 + fi +done + +if [ "$has_fomatting_issues" -eq 0 ]; then + echo "✅ All files are properly formatted! Well done! ^~^" +fi + +exit ${has_fomatting_issues}