From 2f1f4917ae4cff5a0ea25b216a181f31ff7794bd Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Wed, 18 Sep 2024 10:18:21 +0200 Subject: [PATCH 1/2] Add InsertBraces check to .clang-format Additionaly, the lint job is now run in the ubuntu-24.04 runner. This is needed to use a newer version of clang-format that supports the InsertBraces check. --- .clang-format | 2 ++ .github/workflows/lint.yml | 9 +++++++-- collector/lib/DuplexGRPC.h | 3 +-- collector/lib/ProcfsScraper.cpp | 3 +-- collector/lib/SignalServiceClient.cpp | 3 +-- collector/lib/SignalServiceClient.h | 4 ++-- integration-tests/container/perf/scripts/init.sh | 10 +++++----- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.clang-format b/.clang-format index d17114b043..2e7b27223f 100644 --- a/.clang-format +++ b/.clang-format @@ -7,6 +7,8 @@ PointerAlignment: Left IndentPPDirectives: AfterHash +InsertBraces: true + IncludeBlocks: Regroup IncludeCategories: - Regex: '^((\"|<)(api|internalapi|storage)/)' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a7e411a26d..5be4c91651 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,7 +4,7 @@ on: [pull_request] jobs: lint: - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 with: @@ -18,4 +18,9 @@ jobs: # Install actionlint to ~/bin/, otherwise pre-commit won't be able to find the executable. GOBIN="${HOME}/bin/" go install github.com/rhysd/actionlint/cmd/actionlint@latest - - uses: pre-commit/action@v3.0.0 + - name: Run pre-commit + run: | + python3 -m venv .venv + source .venv/bin/activate + python3 -m pip install pre-commit + pre-commit run --show-diff-on-failure --color=always --all-files diff --git a/collector/lib/DuplexGRPC.h b/collector/lib/DuplexGRPC.h index 425488328f..22e0efb8b3 100644 --- a/collector/lib/DuplexGRPC.h +++ b/collector/lib/DuplexGRPC.h @@ -550,8 +550,7 @@ class DuplexClientReaderWriter : public DuplexClientWriter { // Shutdown the client and drain the queue. this->Shutdown(); // ignore errors auto now = ToDeadline(time_point::min()); - while (ProcessSingle(nullptr, now, nullptr)) - ; + while (ProcessSingle(nullptr, now, nullptr)); } template diff --git a/collector/lib/ProcfsScraper.cpp b/collector/lib/ProcfsScraper.cpp index b7b075c93b..f02f086d7c 100644 --- a/collector/lib/ProcfsScraper.cpp +++ b/collector/lib/ProcfsScraper.cpp @@ -44,8 +44,7 @@ const char* nextfield(const char* p, const char* endp) { while (p < endp && *p && !std::isspace(*p)) { p++; } - while (p < endp && *p && std::isspace(*++p)) - ; + while (p < endp && *p && std::isspace(*++p)); return (p < endp && *p) ? p : nullptr; } diff --git a/collector/lib/SignalServiceClient.cpp b/collector/lib/SignalServiceClient.cpp index 3034ce3159..b0676cc6a7 100644 --- a/collector/lib/SignalServiceClient.cpp +++ b/collector/lib/SignalServiceClient.cpp @@ -43,8 +43,7 @@ bool SignalServiceClient::EstablishGRPCStreamSingle() { } void SignalServiceClient::EstablishGRPCStream() { - while (EstablishGRPCStreamSingle()) - ; + while (EstablishGRPCStreamSingle()); CLOG(INFO) << "Signal service client terminating."; } diff --git a/collector/lib/SignalServiceClient.h b/collector/lib/SignalServiceClient.h index 49f8b97c2a..668989f609 100644 --- a/collector/lib/SignalServiceClient.h +++ b/collector/lib/SignalServiceClient.h @@ -66,8 +66,8 @@ class StdoutSignalServiceClient : public ISignalServiceClient { explicit StdoutSignalServiceClient() {} - void Start(){}; - void Stop(){}; + void Start() {}; + void Stop() {}; SignalHandler::Result PushSignals(const SignalStreamMessage& msg); }; diff --git a/integration-tests/container/perf/scripts/init.sh b/integration-tests/container/perf/scripts/init.sh index e22cfaf9d2..2c0f27f1ea 100755 --- a/integration-tests/container/perf/scripts/init.sh +++ b/integration-tests/container/perf/scripts/init.sh @@ -123,6 +123,11 @@ check_headers() { return 0 } +if [[ "$(sysctl -n kernel.kptr_restrict)" != "0" ]]; then + # If this is not zero, it can interfere with most of the tools + sysctl -w kernel.kptr_restrict=0 +fi + if [[ ! -e "/lib/modules/.installed" ]]; then if check_headers "${HOST_MODULES_DIR}"; then HEADERS_TARGET="${HOST_MODULES_DIR}/source" @@ -139,8 +144,3 @@ else echo "Headers already installed" exit 0 fi - -if [[ "$(sysctl -n kernel.kptr_restrict)" != "0" ]]; then - # If this is not zero, it can interfere with most of the tools - sysctl -w kernel.kptr_restrict=0 -fi From cdc5e0b2a616e1750854f42c7452692f56b6f800 Mon Sep 17 00:00:00 2001 From: Mauro Ezequiel Moltrasio Date: Fri, 20 Sep 2024 10:31:55 +0200 Subject: [PATCH 2/2] Run lint job inside fedora:40 container This should make the environment used for running the lint job closer to what most of the team has as local dev environments. --- .github/workflows/lint.yml | 22 +++++++++++++++++++++- collector/lib/CollectorStats.h | 2 +- collector/test/HostHeuristicsTest.cpp | 2 +- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 5be4c91651..2c911b53fc 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,13 +5,33 @@ on: [pull_request] jobs: lint: runs-on: ubuntu-24.04 + container: + image: fedora:40 steps: + - name: dnf install dependencies + run: | + dnf install -y \ + git \ + golang \ + shellcheck \ + clang-tools-extra + + echo "PATH=${HOME}/bin:${PATH}" >> "${GITHUB_ENV}" + - uses: actions/checkout@v4 with: # fetch all to allow linting of differences between branches fetch-depth: 0 + + - name: Mark repo as safe + run: | + git config --global --add safe.directory "${GITHUB_WORKSPACE}" + - uses: actions/setup-python@v5 - - uses: mfinelli/setup-shfmt@v2 + + - name: Install shfmt + run: | + GOBIN="${HOME}/bin/" go install mvdan.cc/sh/v3/cmd/shfmt@latest - name: Install actionlint run: | diff --git a/collector/lib/CollectorStats.h b/collector/lib/CollectorStats.h index 1b7c46de84..5c8f3d230d 100644 --- a/collector/lib/CollectorStats.h +++ b/collector/lib/CollectorStats.h @@ -90,7 +90,7 @@ class CollectorStats { std::array, counter_type_max> counter_ = {{}}; - CollectorStats(){}; + CollectorStats() {}; }; template diff --git a/collector/test/HostHeuristicsTest.cpp b/collector/test/HostHeuristicsTest.cpp index 6f66f03ef5..dfa737652f 100644 --- a/collector/test/HostHeuristicsTest.cpp +++ b/collector/test/HostHeuristicsTest.cpp @@ -51,7 +51,7 @@ class MockHostInfoHeuristics : public HostInfo { class MockCollectorConfig : public CollectorConfig { public: MockCollectorConfig() - : CollectorConfig(){}; + : CollectorConfig() {}; void SetCollectionMethod(CollectionMethod cm) { if (host_config_.HasCollectionMethod()) {