-
-
Notifications
You must be signed in to change notification settings - Fork 307
Improve linters for traits #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
prince-chrismc
merged 16 commits into
Thalhammer:master
from
prince-chrismc:simplier-linters
Mar 25, 2026
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ec35e35
quick poc at using cmake to generate the defaults.h traits files
prince-chrismc fa75aec
add test preset to dev
prince-chrismc 39d6f65
self review
prince-chrismc 6632573
poc moving logic to actions
prince-chrismc 08ff25c
Remove stale defaults.h generation configuration
prince-chrismc ffb7aa3
Fix file path in lint workflow configuration
prince-chrismc 5303507
chmod +x
prince-chrismc 69d097d
linter
prince-chrismc 3759a1b
linter
prince-chrismc a3e9ccf
clean up action and lint workflow
prince-chrismc 977451d
rm source_dir cli arg from cmake script
prince-chrismc 7969203
linter
prince-chrismc e857449
Merge branch 'master' into simplier-linters
prince-chrismc d6579c9
fix order
prince-chrismc bcf7b03
add workflow preset for running unit test
prince-chrismc 90542ab
Merge branch 'master' into simplier-linters
prince-chrismc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: "Render `defaults.h` Template" | ||
| description: "Generate all the `defaults.h` header file for JSON libraries" | ||
| runs: | ||
| using: composite | ||
| steps: | ||
| - run: ${{ github.action_path }}/configure-traits.sh | ||
| shell: bash |
38 changes: 38 additions & 0 deletions
38
.github/actions/generate-defaults-dot-h/configure-traits.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/bash | ||
| # Trait metadata configuration for generating defaults.h files | ||
| # Maps trait names to their library information | ||
|
|
||
| set -e # Exit on error | ||
|
|
||
| # Define traits metadata as pipe-delimited strings | ||
| # Format: TRAITS_NAME|LIBRARY_NAME|LIBRARY_URL|DISABLE_DEFAULT_TRAITS | ||
| JWT_TRAITS_METADATA=( | ||
| "kazuho_picojson|picojson|https://github.com/kazuho/picojson|false" | ||
| "nlohmann_json|JSON for Modern C++|https://github.com/nlohmann/json|true" | ||
| "boost_json|Boost.JSON|https://github.com/boostorg/json|true" | ||
| "danielaparker_jsoncons|jsoncons|https://github.com/danielaparker/jsoncons|true" | ||
| "open_source_parsers_jsoncpp|jsoncpp|https://github.com/open-source-parsers/jsoncpp|true" | ||
| "glaze_json|Glaze|https://github.com/stephenberry/glaze|true" | ||
| "reflectcpp_json|ReflectCpp|https://github.com/getml/reflect-cpp|true" | ||
| ) | ||
|
|
||
| # Function to configure traits defaults | ||
| configure_traits_defaults() { | ||
| for trait_meta in "${JWT_TRAITS_METADATA[@]}"; do | ||
| # Split the metadata by pipe delimiter | ||
| IFS='|' read -r TRAITS_NAME LIBRARY_NAME LIBRARY_URL DISABLE_DEFAULT_TRAITS <<< "$trait_meta" | ||
|
|
||
| # Call the CMake script to generate defaults.h for this trait | ||
| if ! cmake \ | ||
| -DTRAITS_NAME="$TRAITS_NAME" \ | ||
| -DLIBRARY_NAME="$LIBRARY_NAME" \ | ||
| -DLIBRARY_URL="$LIBRARY_URL" \ | ||
| -DDISABLE_DEFAULT_TRAITS="$DISABLE_DEFAULT_TRAITS" \ | ||
| -P "cmake/generate-defaults-h.cmake"; then | ||
| echo "::error::Failed to configure defaults.h for $TRAITS_NAME" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| # Execute the configuration | ||
| configure_traits_defaults |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #[[ | ||
| # This script generates a single defaults.h file from the defaults.h.in template | ||
| # It is invoked from the root directory of the project. | ||
| # | ||
| # Expected variables (set via -D command line): | ||
| # - TRAITS_NAME: name of the trait (e.g., nlohmann_json) | ||
| # - LIBRARY_NAME: name of the JSON library (e.g., JSON for Modern C++) | ||
| # - LIBRARY_URL: URL to the library | ||
| # - DISABLE_DEFAULT_TRAITS: whether to disable default picojson (true/false) | ||
| #]] | ||
|
|
||
| if(NOT DEFINED TRAITS_NAME) | ||
| message(FATAL_ERROR "TRAITS_NAME must be defined") | ||
| endif() | ||
|
|
||
| if(NOT DEFINED LIBRARY_NAME) | ||
| message(FATAL_ERROR "LIBRARY_NAME must be defined") | ||
| endif() | ||
|
|
||
| if(NOT DEFINED LIBRARY_URL) | ||
| message(FATAL_ERROR "LIBRARY_URL must be defined") | ||
| endif() | ||
|
|
||
| # Convert traits name to directory format (replace underscores with dashes) | ||
| string(REPLACE "_" "-" TRAITS_DIR_NAME "${TRAITS_NAME}") | ||
| string(TOUPPER "${TRAITS_NAME}" TRAITS_NAME_UPPER) | ||
|
|
||
| set(TEMPLATE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/jwt-cpp/traits/defaults.h.in") | ||
| if(NOT EXISTS "${TEMPLATE_FILE}") | ||
| message(FATAL_ERROR "Wrong working directory! Template file `${TEMPLATE_FILE}` does not exist.") | ||
| endif() | ||
|
|
||
| # Determine output directory | ||
| set(OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include/jwt-cpp/traits/${TRAITS_DIR_NAME}") | ||
| set(OUTPUT_FILE "${OUTPUT_DIR}/defaults.h") | ||
|
|
||
| # Ensure output directory exists | ||
| file(MAKE_DIRECTORY "${OUTPUT_DIR}") | ||
|
|
||
| # Handle the conditional DISABLE_PICOJSON block | ||
| if(DISABLE_DEFAULT_TRAITS) | ||
| set(DISABLE_PICOJSON_DEFINE | ||
| " | ||
| #ifndef JWT_DISABLE_PICOJSON | ||
| #define JWT_DISABLE_PICOJSON | ||
| #endif") | ||
| else() | ||
| set(DISABLE_PICOJSON_DEFINE "") | ||
| endif() | ||
|
|
||
| # Configure the file | ||
| configure_file("${TEMPLATE_FILE}" "${OUTPUT_FILE}" @ONLY) | ||
|
|
||
| message(STATUS "Generated ${OUTPUT_FILE}") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thalhammer when you have a chance, I also made Thalhammer/patch-generator-action#1 to support making more than 1 patch at a time 🙏