Skip to content

Commit 7327132

Browse files
nlohmannslowriot
authored andcommitted
Clean up CI (nlohmann#4553)
* 💚 overwork cppcheck * 🔒 adjust permissions * 💚 fixes * 💚 fixes
1 parent 16f52f0 commit 7327132

File tree

10 files changed

+76
-76
lines changed

10 files changed

+76
-76
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ updates:
1616
interval: daily
1717

1818
- package-ecosystem: pip
19-
directory: /.reuse
19+
directory: /cmake/requirements
2020
schedule:
2121
interval: daily

.github/workflows/ubuntu.yml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ on:
88
- release/*
99
pull_request:
1010
workflow_dispatch:
11-
11+
12+
permissions:
13+
contents: read
14+
1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
1417
cancel-in-progress: true
@@ -46,7 +49,6 @@ jobs:
4649
strategy:
4750
matrix:
4851
target: [
49-
ci_cppcheck, # needs cppcheck
5052
ci_test_valgrind, # needs Valgrind
5153
ci_test_amalgamation, # needs AStyle
5254
ci_infer, # needs Infer
@@ -75,7 +77,7 @@ jobs:
7577
runs-on: ubuntu-latest
7678
strategy:
7779
matrix:
78-
target: [ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata]
80+
target: [ci_cppcheck, ci_cpplint, ci_reproducible_tests, ci_non_git_tests, ci_offline_testdata, ci_reuse_compliance]
7981
steps:
8082
- name: Harden Runner
8183
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
@@ -126,9 +128,6 @@ jobs:
126128

127129
ci_test_coverage:
128130
runs-on: ubuntu-latest
129-
permissions:
130-
contents: read
131-
checks: write
132131
steps:
133132
- name: Harden Runner
134133
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
@@ -266,23 +265,6 @@ jobs:
266265
. /opt/intel/oneapi/setvars.sh
267266
cmake --build build --target ci_icpc
268267
269-
ci_reuse_compliance:
270-
runs-on: ubuntu-latest
271-
steps:
272-
- name: Harden Runner
273-
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
274-
with:
275-
egress-policy: audit
276-
277-
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
278-
- uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0
279-
with:
280-
python-version: '3.11'
281-
- name: Install REUSE tool
282-
run: python -m pip install -r .reuse/requirements.txt
283-
- name: Run REUSE lint
284-
run: reuse lint
285-
286268
ci_test_documentation:
287269
runs-on: ubuntu-latest
288270
strategy:

.github/workflows/windows.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ on:
99
pull_request:
1010
workflow_dispatch:
1111

12+
permissions:
13+
contents: read
14+
1215
concurrency:
1316
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
1417
cancel-in-progress: true

cmake/ci.cmake

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ message(STATUS "🔖 Clang-Tidy ${CLANG_TIDY_TOOL_VERSION} (${CLANG_TIDY_TOOL})"
2525

2626
message(STATUS "🔖 CMake ${CMAKE_VERSION} (${CMAKE_COMMAND})")
2727

28-
find_program(CPPCHECK_TOOL NAMES cppcheck)
29-
execute_process(COMMAND ${CPPCHECK_TOOL} --version OUTPUT_VARIABLE CPPCHECK_TOOL_VERSION ERROR_VARIABLE CPPCHECK_TOOL_VERSION)
30-
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" CPPCHECK_TOOL_VERSION "${CPPCHECK_TOOL_VERSION}")
31-
message(STATUS "🔖 Cppcheck ${CPPCHECK_TOOL_VERSION} (${CPPCHECK_TOOL})")
32-
3328
find_program(GCC_TOOL NAMES g++-latest g++-HEAD g++ g++-15 g++-14 g++-13 g++-12 g++-11 g++-10)
3429
execute_process(COMMAND ${GCC_TOOL} --version OUTPUT_VARIABLE GCC_TOOL_VERSION ERROR_VARIABLE GCC_TOOL_VERSION)
3530
string(REGEX MATCH "[0-9]+(\\.[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION}")
@@ -716,7 +711,14 @@ add_custom_target(ci_clang_analyze
716711
###############################################################################
717712

718713
add_custom_target(ci_cppcheck
719-
COMMAND ${CPPCHECK_TOOL} --enable=warning --suppress=missingReturn --inline-suppr --inconclusive --force --std=c++11 ${PROJECT_SOURCE_DIR}/single_include/nlohmann/json.hpp --error-exitcode=1
714+
COMMAND ${Python3_EXECUTABLE} -mvenv venv_cppcheck
715+
COMMAND clang -dM -E -x c++ -std=c++11 ${CMAKE_SOURCE_DIR}/include/nlohmann/thirdparty/hedley/hedley.hpp > default_defines.hpp 2> /dev/null
716+
COMMAND venv_cppcheck/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/cmake/requirements/requirements-cppcheck.txt
717+
COMMAND venv_cppcheck/bin/cppcheck --enable=warning --check-level=exhaustive --inline-suppr --inconclusive --force
718+
--std=c++11 ${PROJECT_SOURCE_DIR}/include/nlohmann/json.hpp -I ${CMAKE_SOURCE_DIR}/include
719+
--error-exitcode=1 --relative-paths=${PROJECT_SOURCE_DIR} -j 10 --include=default_defines.hpp
720+
-UJSON_CATCH_USER -UJSON_TRY_USER -UJSON_ASSERT -UJSON_INTERNAL_CATCH -UJSON_THROW
721+
-DJSON_HAS_CPP_11 -UJSON_HAS_CPP_14 -UJSON_HAS_CPP_17 -UJSON_HAS_CPP_20 -UJSON_HAS_THREE_WAY_COMPARISON
720722
COMMENT "Check code with Cppcheck"
721723
)
722724

@@ -726,7 +728,7 @@ add_custom_target(ci_cppcheck
726728

727729
add_custom_target(ci_cpplint
728730
COMMAND ${Python3_EXECUTABLE} -mvenv venv_cpplint
729-
COMMAND venv_cpplint/bin/pip3 --quiet install cpplint
731+
COMMAND venv_cpplint/bin/pip3 --quiet install -r ${CMAKE_SOURCE_DIR}/cmake/requirements/requirements-cpplint.txt
730732
COMMAND venv_cpplint/bin/cpplint --filter=-whitespace,-legal,-runtime/references,-runtime/explicit,-runtime/indentation_namespace,-readability/casting,-readability/nolint --quiet --recursive ${SRC_FILES}
731733
COMMENT "Check code with cpplint"
732734
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
@@ -1013,6 +1015,17 @@ add_custom_target(ci_icpc
10131015
COMMENT "Compile and test with ICPC"
10141016
)
10151017

1018+
###############################################################################
1019+
# REUSE
1020+
###############################################################################
1021+
1022+
add_custom_target(ci_reuse_compliance
1023+
COMMAND ${Python3_EXECUTABLE} -mvenv venv_reuse
1024+
COMMAND venv_reuse/bin/pip3 --quiet install -r ${PROJECT_SOURCE_DIR}/cmake/requirements/requirements-reuse.txt
1025+
COMMAND venv_reuse/bin/reuse --root ${PROJECT_SOURCE_DIR} lint
1026+
COMMENT "Check REUSE specification compliance"
1027+
)
1028+
10161029
###############################################################################
10171030
# test documentation
10181031
###############################################################################
@@ -1025,7 +1038,7 @@ add_custom_target(ci_test_examples
10251038

10261039
add_custom_target(ci_test_build_documentation
10271040
COMMAND ${Python3_EXECUTABLE} -mvenv venv
1028-
COMMAND venv/bin/pip3 install -r requirements.txt
1041+
COMMAND venv/bin/pip3 --quiet install -r requirements.txt
10291042
COMMAND make build
10301043
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/docs/mkdocs
10311044
COMMENT "Build the documentation"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cppcheck==1.4.6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cpplint==2.0.0

include/nlohmann/detail/input/input_adapters.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ contiguous_bytes_input_adapter input_adapter(CharT b)
502502
}
503503
auto length = std::strlen(reinterpret_cast<const char*>(b));
504504
const auto* ptr = reinterpret_cast<const char*>(b);
505-
return input_adapter(ptr, ptr + length);
505+
return input_adapter(ptr, ptr + length); // cppcheck-suppress[nullPointerArithmeticRedundantCheck]
506506
}
507507

508508
template<typename T, std::size_t N>

include/nlohmann/json.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,10 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
12141214
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
12151215
basic_json(basic_json&& other) noexcept
12161216
: json_base_class_t(std::forward<json_base_class_t>(other)),
1217-
m_data(std::move(other.m_data))
1217+
m_data(std::move(other.m_data)) // cppcheck-suppress[accessForwarded] TODO check
12181218
{
12191219
// check that passed value is valid
1220-
other.assert_invariant(false);
1220+
other.assert_invariant(false); // cppcheck-suppress[accessForwarded]
12211221

12221222
// invalidate payload
12231223
other.m_data.m_type = value_t::null;
@@ -1949,7 +1949,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
19491949
{
19501950
// create better exception explanation
19511951
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this));
1952-
}
1952+
} // cppcheck-suppress[missingReturn]
19531953
}
19541954
else
19551955
{
@@ -1972,7 +1972,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
19721972
{
19731973
// create better exception explanation
19741974
JSON_THROW(out_of_range::create(401, detail::concat("array index ", std::to_string(idx), " is out of range"), this));
1975-
}
1975+
} // cppcheck-suppress[missingReturn]
19761976
}
19771977
else
19781978
{
@@ -4019,7 +4019,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
40194019
const bool ignore_comments = false)
40204020
{
40214021
basic_json result;
4022-
parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result);
4022+
parser(detail::input_adapter(std::forward<InputType>(i)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved,accessForwarded]
40234023
return result;
40244024
}
40254025

@@ -4034,7 +4034,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
40344034
const bool ignore_comments = false)
40354035
{
40364036
basic_json result;
4037-
parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result);
4037+
parser(detail::input_adapter(std::move(first), std::move(last)), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved]
40384038
return result;
40394039
}
40404040

@@ -4046,7 +4046,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
40464046
const bool ignore_comments = false)
40474047
{
40484048
basic_json result;
4049-
parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(true, result);
4049+
parser(i.get(), std::move(cb), allow_exceptions, ignore_comments).parse(true, result); // cppcheck-suppress[accessMoved]
40504050
return result;
40514051
}
40524052

@@ -4368,7 +4368,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
43684368
basic_json result;
43694369
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
43704370
auto ia = detail::input_adapter(std::forward<InputType>(i));
4371-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4371+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
43724372
return res ? result : basic_json(value_t::discarded);
43734373
}
43744374

@@ -4384,7 +4384,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
43844384
basic_json result;
43854385
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
43864386
auto ia = detail::input_adapter(std::move(first), std::move(last));
4387-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4387+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
43884388
return res ? result : basic_json(value_t::discarded);
43894389
}
43904390

@@ -4410,7 +4410,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44104410
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44114411
auto ia = i.get();
44124412
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
4413-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler);
4413+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::cbor).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); // cppcheck-suppress[accessMoved]
44144414
return res ? result : basic_json(value_t::discarded);
44154415
}
44164416

@@ -4425,7 +4425,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44254425
basic_json result;
44264426
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44274427
auto ia = detail::input_adapter(std::forward<InputType>(i));
4428-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4428+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
44294429
return res ? result : basic_json(value_t::discarded);
44304430
}
44314431

@@ -4440,7 +4440,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44404440
basic_json result;
44414441
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44424442
auto ia = detail::input_adapter(std::move(first), std::move(last));
4443-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4443+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
44444444
return res ? result : basic_json(value_t::discarded);
44454445
}
44464446

@@ -4464,7 +4464,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44644464
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44654465
auto ia = i.get();
44664466
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
4467-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict);
4467+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::msgpack).sax_parse(input_format_t::msgpack, &sdp, strict); // cppcheck-suppress[accessMoved]
44684468
return res ? result : basic_json(value_t::discarded);
44694469
}
44704470

@@ -4479,7 +4479,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44794479
basic_json result;
44804480
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44814481
auto ia = detail::input_adapter(std::forward<InputType>(i));
4482-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4482+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
44834483
return res ? result : basic_json(value_t::discarded);
44844484
}
44854485

@@ -4494,7 +4494,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
44944494
basic_json result;
44954495
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
44964496
auto ia = detail::input_adapter(std::move(first), std::move(last));
4497-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4497+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
44984498
return res ? result : basic_json(value_t::discarded);
44994499
}
45004500

@@ -4518,7 +4518,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
45184518
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
45194519
auto ia = i.get();
45204520
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
4521-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict);
4521+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::ubjson).sax_parse(input_format_t::ubjson, &sdp, strict); // cppcheck-suppress[accessMoved]
45224522
return res ? result : basic_json(value_t::discarded);
45234523
}
45244524

@@ -4533,7 +4533,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
45334533
basic_json result;
45344534
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
45354535
auto ia = detail::input_adapter(std::forward<InputType>(i));
4536-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4536+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
45374537
return res ? result : basic_json(value_t::discarded);
45384538
}
45394539

@@ -4548,7 +4548,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
45484548
basic_json result;
45494549
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
45504550
auto ia = detail::input_adapter(std::move(first), std::move(last));
4551-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict);
4551+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bjdata).sax_parse(input_format_t::bjdata, &sdp, strict); // cppcheck-suppress[accessMoved]
45524552
return res ? result : basic_json(value_t::discarded);
45534553
}
45544554

@@ -4563,7 +4563,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
45634563
basic_json result;
45644564
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
45654565
auto ia = detail::input_adapter(std::forward<InputType>(i));
4566-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4566+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
45674567
return res ? result : basic_json(value_t::discarded);
45684568
}
45694569

@@ -4578,7 +4578,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
45784578
basic_json result;
45794579
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
45804580
auto ia = detail::input_adapter(std::move(first), std::move(last));
4581-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4581+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
45824582
return res ? result : basic_json(value_t::discarded);
45834583
}
45844584

@@ -4602,7 +4602,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
46024602
detail::json_sax_dom_parser<basic_json> sdp(result, allow_exceptions);
46034603
auto ia = i.get();
46044604
// NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg)
4605-
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict);
4605+
const bool res = binary_reader<decltype(ia)>(std::move(ia), input_format_t::bson).sax_parse(input_format_t::bson, &sdp, strict); // cppcheck-suppress[accessMoved]
46064606
return res ? result : basic_json(value_t::discarded);
46074607
}
46084608
/// @}

0 commit comments

Comments
 (0)