Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/generate-defaults-dot-h/action.yml
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 .github/actions/generate-defaults-dot-h/configure-traits.sh
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
13 changes: 0 additions & 13 deletions .github/actions/process-linting-results/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,4 @@ runs:
- run: git add --update
shell: bash
- id: stage
#continue-on-error: true
uses: Thalhammer/patch-generator-action@v3

Copy link
Copy Markdown
Collaborator Author

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 🙏


# Unfortunately the previous action reports a failure so nothing else can run
# partially a limitation on composite actions since `continue-on-error` is not
# yet supported
- if: steps.stage.outputs.result == 'dirty'
uses: actions-ecosystem/action-create-comment@v1
with:
github_token: ${{ github.token }}
body: |
Hello, @${{ github.actor }}! `${{ inputs.linter_name }}` had some concerns :scream:
- run: exit $(git status -uno -s | wc -l)
shell: bash
67 changes: 0 additions & 67 deletions .github/actions/render/defaults/action.yml

This file was deleted.

44 changes: 0 additions & 44 deletions .github/actions/render/tests/action.yml

This file was deleted.

62 changes: 7 additions & 55 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
strategy:
fail-fast: false
matrix:
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake"]
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake", "cmake/generate-defaults-h.cmake"]
steps:
- uses: actions/setup-python@v5
with:
Expand All @@ -60,65 +60,17 @@ jobs:
with:
linter_name: clang-tidy

render-defaults:
generate-defaults:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
traits:
- { name: "boost_json", library: "Boost.JSON", url: "https://github.com/boostorg/json", disable_pico: true }
- { name: "danielaparker_jsoncons", library: "jsoncons", url: "https://github.com/danielaparker/jsoncons", disable_pico: true }
- { name: "kazuho_picojson", library: "picojson", url: "https://github.com/kazuho/picojson", disable_pico: false }
- { name: "nlohmann_json", library: "JSON for Modern C++", url: "https://github.com/nlohmann/json", disable_pico: true }
- { name: "open_source_parsers_jsoncpp", library: "jsoncpp", url: "https://github.com/open-source-parsers/jsoncpp", disable_pico: true }
- { name: "glaze_json", library: "Glaze", url: "https://github.com/stephenberry/glaze", disable_pico: true }
- { name: "reflectcpp_json", library: "ReflectCpp", url: "https://github.com/getml/reflect-cpp", disable_pico: true }
name: render-defaults (${{ matrix.traits.name }})
steps:
- uses: actions/checkout@v4
- run: |
sudo apt-get install clang-format-14
- uses: ./.github/actions/render/defaults
id: render
with:
traits_name: ${{ matrix.traits.name }}
library_name: ${{ matrix.traits.library }}
library_url: ${{ matrix.traits.url }}
disable_default_traits: ${{ matrix.traits.disable_pico }}
- run: clang-format-14 -i ${{ steps.render.outputs.file_path }}
- run: git add ${{ steps.render.outputs.file_path }}
- uses: ./.github/actions/process-linting-results
with:
linter_name: render-defaults

render-tests:
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
traits:
# - { name: "boost_json", suite: "BoostJsonTest" } # Currently needs work around for API limitations
- { name: "danielaparker_jsoncons", suite: "JsonconsTest" }
# - { name: "kazuho_picojson", suite: "PicoJsonTest" } # No ctor for integer type
- { name: "nlohmann_json", suite: "NlohmannTest" }
- { name: "open_source_parsers_jsoncpp", suite: "OspJsoncppTest" }
# - { name: "glaze_json", suite: "GlazeTest" } # No supported due to istream buffer being specialized
# - { name: "reflectcpp_json", suite: "ReflectCppJsonTest" } # No supported due to istream buffer being specialized
name: render-tests (${{ matrix.traits.name }})
steps:
- uses: actions/checkout@v4
- run: |
sudo apt-get install clang-format-14
shopt -s globstar
- uses: ./.github/actions/render/tests
with:
traits_name: ${{ matrix.traits.name }}
test_suite_name: ${{ matrix.traits.suite }}
- run: clang-format-14 -i tests/**/*.cpp
- run: git add tests/traits/*
- run: sudo apt-get install clang-format-14
- uses: ./.github/actions/generate-defaults-dot-h
- run: clang-format-14 -i include/jwt-cpp/traits/*/*.h
- run: git add include/jwt-cpp/traits/*/*.h
- uses: ./.github/actions/process-linting-results
with:
linter_name: render-tests
linter_name: generate-defaults

line-ending:
runs-on: ubuntu-latest
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/ssl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ jobs:
with:
version: ${{ matrix.openssl.tag }}

- name: configure
run: cmake --preset unit-tests
- run: cmake --build --preset unit-tests
- name: test
run: ctest --preset unit-tests --output-on-failure
- run: cmake --workflow --preset unit-tests

- if: github.event_name == 'push' && always()
uses: ./.github/actions/badge
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ option(JWT_ENABLE_FUZZING "Enable fuzz testing" OFF)
option(JWT_DISABLE_PICOJSON "Do not provide the picojson template specialiaze" OFF)
option(JWT_DISABLE_BASE64 "Do not include the base64 implementation from this library" OFF)
include(CMakeDependentOption)
cmake_dependent_option(
JWT_BUILD_TESTS "Configure CMake to build tests (or not)" OFF
"NOT JWT_DISABLE_BASE64 AND NOT JWT_DISABLE_PICOJSON" OFF)
cmake_dependent_option(
JWT_EXTERNAL_PICOJSON "Use find_package() to locate picojson, provided to integrate with package managers" OFF
"NOT JWT_DISABLE_PICOJSON" OFF)
Expand Down
11 changes: 9 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"patch": 0
},
"include": [
"example/CMakePresets.json",
"tests/CMakePresets.json"
"example/CMakePresets.json",
"tests/CMakePresets.json"
],
"configurePresets": [
{
Expand All @@ -29,5 +29,12 @@
"configurePreset": "dev",
"configuration": "Debug"
}
],
"testPresets": [
{
"name": "dev",
"displayName": "Run all tests",
"configurePreset": "dev"
}
]
}
54 changes: 54 additions & 0 deletions cmake/generate-defaults-h.cmake
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}")
Loading
Loading