Skip to content

Commit 5c9787e

Browse files
🚢 Provide trait implementation for supported JSON libraries (#193)
* quick poc for #174 * Copy paste * Rename include/jwt-cpp/traits/traits.h to include/jwt-cpp/traits/danielaparker-jsoncons/traits.h * Create traits.h * adding a namespace * mustache + action to automate defaults generation since they should always be the same * fix order * traits tests should use traits * playing with header order to make clang happy * install all possible traits switch badge name to sha * Update CMakeLists.txt * Update traits.h * try commenting corrected code * rm typescript * make sure to implace edit * dont comment when no diff * apply linting * fixup boost-json traits * move comment and render to composite action * actions/github-script does not leave context in the usual spot * enabled globstar * make sure to forward inputs * try using env normally * fix typo * pass in linter name correctly * debug print * fix linting issues * more debug printing * fix linting issues * fix typpo + more rebug print * apply linting * more debug * try npm install global to be less intrusive * wip render traits tests * Update lint.yml * global install does not work * Update action.yml * Update defaults.h * remove nodejs action poc * include jsoncons in main test application (for coverage of new files) * do not exclude json (since it's used by all the traits) * exclude bundled json libraries * apply linting * add jsoncons for coverage testing * jsoncons set default to a viable version * exploring ci failure * Revert "exploring ci failure" it's overlapping symbols This reverts commit 3d5b7f9. * add missing specialization * be explicit with the tests * Create CMakeLists.txt * Create danielaparker-jsoncons.cpp * Update lint.yml * Update traits.yml * lint * better access too decoded claims * more tests on verify * tweak test trying to find minimum * lets enable linting tests * using env impl for github script * fix typo * apply linting * add boost to the tests (very hacky) * Update lint.yml * ceate light boost installer there is no cmake install anymore so just a blanket copy should do * remove path requirement * outline for commit and push linting on comment * try different webhook target * more event types * fix if for more event types * just a test commit * Update lint.yml * Update lint.yml * Update lint.yml * Apply automatic changes * add token * screw up formatting * Update lint.yml * Update lint.yml * Apply automatic changes * fix merge conflicts * missing errors * playing with globbing * lint issues * matrix on comment should give many pushes * Apply automatic changes * Update lint.yml * Apply automatic changes * Apply automatic changes * fix rebase * apply render tests * Apply automatic changes * Apply automatic changes * Delete package-lock.json * fail linting * Update .gitignore * Update lint.yml * Update lint.yml * Update lint.yml * Apply automatic changes * Update lint.yml * Update CMakeLists.txt * refactor boost.json inclusion - find paths - compile library - code coverage - traits example * Apply automatic changes * debug log * Update action.yml * debug output * Update action.yml * Delete private-boost-json.cpp.in * Update private-find-boost-json.cmake * Update CMakeLists.txt * Update CMakeLists.txt * Create CMakeLists.txt * Update boost-json.cpp * Update boost-json.cpp * Update boost-json.cpp * Update boost-json.cpp * remove old boost tests * examples to include traits * fix compilation * test nlohmann json traits * linting * refactor traits to make badges * try with less expression syntax * trying single quotes * advertise traits support * Update lint.yml * Update lint.yml * Update lint.yml * sync (prince-chrismc#16) * 🔧 Replace RSA related deprecated functions (#189) * RSA_size() --> EVP_PKEY_size() * getting rid of deprecated functions in rsa-pss signature creation * getting rid of deprecated functions in rsa-pss signature verification * generate_hash not used in pss * Update lint.yml * Update lint.yml * Update lint.yml Co-authored-by: Marek Klein <kleinmrk@gmail.com> * Update lint.yml * make sure to use install `nlohmann-json` * make action folder match trait names * add example + badge for kazuho-picojson * link to new examples * revert debug code * dont mix matrix with uses * fix bad copy paste * spec interface library so it's no compiled * fix installer * fix to interface * fix example * attempt 2 * make sure to avoid circular reference * attempt 3 * white space * white space * Update and rename .github/actions/comment-linting/action.yml to .github/actions/process-linting-results/action.yml * Update lint.yml * Update action.yml * Update action.yml * Update README.md Co-authored-by: prince-chrismc <prince-chrismc@users.noreply.github.com> Co-authored-by: Marek Klein <kleinmrk@gmail.com>
1 parent 275c750 commit 5c9787e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1998
-954
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Install Boost.JSON
2+
description: Install Boost.JSON for building test application
3+
inputs:
4+
version:
5+
description: The desired Boost.JSON version to install
6+
required: false
7+
default: "1.77.0"
8+
runs:
9+
using: composite
10+
steps:
11+
- run: |
12+
cd /tmp
13+
wget https://github.com/boostorg/json/archive/boost-${{ inputs.version }}.tar.gz
14+
tar -zxf /tmp/boost-${{ inputs.version }}.tar.gz
15+
cd json-boost-${{ inputs.version }}
16+
sudo cp -vR include/boost /usr/local/include
17+
shell: bash

.github/actions/install/jsoncons/action.yml renamed to .github/actions/install/danielaparker-jsoncons/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inputs:
44
version:
55
description: The desired jsoncons version to install
66
required: false
7-
default: "0.159.0"
7+
default: "0.167.1"
88
runs:
99
using: composite
1010
steps:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Install PicoJSON
2+
description: Install PicoJSON for building test application
3+
inputs:
4+
version:
5+
description: The desired PicoJSON version to install
6+
required: false
7+
default: "v1.3.0"
8+
runs:
9+
using: composite
10+
steps:
11+
- run: |
12+
cd /tmp
13+
wget https://github.com/kazuho/picojson/archive/${{ inputs.version }}.tar.gz
14+
tar -zxf /tmp/${{ inputs.version }}.tar.gz
15+
cd picojson-${{ inputs.version }}
16+
sudo cp -v picojson.h /usr/local/include/picojson
17+
shell: bash
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Install nlohmann-json
2+
description: Install nlohmann-json for building test application
3+
inputs:
4+
version:
5+
description: The desired nlohmann-json version to install
6+
required: false
7+
default: "3.10.4"
8+
runs:
9+
using: composite
10+
steps:
11+
- run: |
12+
cd /tmp
13+
wget https://github.com/nlohmann/json/archive/v${{ inputs.version }}.tar.gz
14+
tar -zxf /tmp/v${{ inputs.version }}.tar.gz
15+
cd json-${{ inputs.version }}
16+
cmake .
17+
sudo cmake --install .
18+
shell: bash
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Process Linting Results
2+
description: Add a comment to a pull request with when `git diff` present and save the changes as an artifact so they can be applied manually
3+
inputs:
4+
linter_name:
5+
description: The name of the tool to credit in the comment
6+
required: true
7+
runs:
8+
using: "composite"
9+
steps:
10+
- run: git add --update
11+
shell: bash
12+
- id: stage
13+
uses: dtinth/patch-generator-action@v1
14+
- if: steps.stage.outputs.result == 'dirty'
15+
uses: actions-ecosystem/action-create-comment@v1
16+
with:
17+
github_token: ${{ github.token }}
18+
body: |
19+
Hello, @${{ github.actor }}! `${{ inputs.linter_name }}` had some concerns :scream:
20+
- run: exit $(git status -uno -s | wc -l)
21+
shell: bash
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: "Render `defaults.h` Template"
2+
description: "Generate the `defaults.h` header file for a JSON library"
3+
inputs:
4+
traits_name:
5+
description: "Name of the traits structure to be used. Typically in the format `author_repository` or equivilant"
6+
required: true
7+
library_name:
8+
description: "Name of the JSON library."
9+
required: true
10+
library_url:
11+
description: "URL to the JSON library."
12+
required: true
13+
disable_default_traits:
14+
description: "Set the macro to disable the default traits"
15+
required: false
16+
default: "true"
17+
runs:
18+
using: composite
19+
steps:
20+
- uses: actions/setup-node@v2
21+
with:
22+
node-version: 14
23+
- run: npm install mustache
24+
shell: bash
25+
- uses: actions/github-script@v5
26+
env:
27+
TRAITS_NAME: ${{ inputs.traits_name }}
28+
LIBRARY_NAME: ${{ inputs.library_name }}
29+
LIBRARY_URL: ${{ inputs.library_url }}
30+
DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }}
31+
with:
32+
script: |
33+
const mustache = require('mustache')
34+
const path = require('path')
35+
const fs = require('fs')
36+
37+
const { TRAITS_NAME, LIBRARY_NAME, LIBRARY_URL, DISABLE_DEFAULT_TRAITS } = process.env
38+
console.log(`Rendering ${TRAITS_NAME}!`)
39+
40+
const disableDefault = DISABLE_DEFAULT_TRAITS === 'true'
41+
42+
const template = fs.readFileSync(path.join('include', 'jwt-cpp', 'traits', 'defaults.h.mustache'), 'utf8')
43+
const content = mustache.render(template, {
44+
traits_name: TRAITS_NAME,
45+
traits_name_upper: TRAITS_NAME.toUpperCase(),
46+
library_name: LIBRARY_NAME,
47+
library_url: LIBRARY_URL,
48+
disable_default_traits: disableDefault,
49+
})
50+
const outputDir = path.join('include', 'jwt-cpp', 'traits', TRAITS_NAME.replace('_', '-'))
51+
fs.mkdirSync(outputDir, { recursive: true })
52+
fs.writeFileSync(path.join(outputDir, 'defaults.h'), content)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "Render `TraitsTests.cpp` Template"
2+
description: "Generate the `TraitsTests.cpp` header file for a JSON library"
3+
inputs:
4+
traits_name:
5+
description: "Name of the traits structure to be used. Typically in the format `author_repository` or equivilant"
6+
required: true
7+
test_suite_name:
8+
description: "Name of the JSON library."
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: 14
16+
- run: npm install mustache
17+
shell: bash
18+
- uses: actions/github-script@v5
19+
env:
20+
TRAITS_NAME: ${{ inputs.traits_name }}
21+
SUITE_NAME: ${{ inputs.test_suite_name }}
22+
with:
23+
script: |
24+
const mustache = require('mustache')
25+
const path = require('path')
26+
const fs = require('fs')
27+
28+
const { TRAITS_NAME, SUITE_NAME } = process.env
29+
console.log(`Rendering ${TRAITS_NAME}!`)
30+
31+
const template = fs.readFileSync(path.join('tests', 'traits', 'TraitsTest.cpp.mustache'), 'utf8')
32+
const content = mustache.render(template, {
33+
traits_name: TRAITS_NAME,
34+
traits_dir: TRAITS_NAME.replace('_', '-'),
35+
test_suite_name: SUITE_NAME,
36+
})
37+
const outputDir = path.join('tests', 'traits')
38+
fs.mkdirSync(outputDir, { recursive: true })
39+
fs.writeFileSync(path.join(outputDir, `${SUITE_NAME}.cpp`), content)

.github/workflows/jwt.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
- uses: actions/checkout@v2
1414
- uses: lukka/get-cmake@latest
1515
- uses: ./.github/actions/install/gtest
16+
- uses: ./.github/actions/install/danielaparker-jsoncons
17+
- uses: ./.github/actions/install/boost-json
1618

1719
- name: configure
1820
run: |

.github/workflows/lint.yml

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,105 @@ jobs:
1010
clang-format:
1111
runs-on: ubuntu-20.04
1212
strategy:
13+
fail-fast: false
1314
matrix:
14-
files: ["include/jwt-cpp/*.h", "tests/**.cpp"]
15+
files:
16+
- "include/jwt-cpp/*.h"
17+
- "include/jwt-cpp/traits/**/*.h"
18+
- "tests/*.cpp"
19+
- "tests/**/*.cpp"
20+
- "example/*.cpp"
21+
- "example/**/*.cpp"
1522
steps:
16-
- run: sudo apt-get install clang-format
23+
- run: |
24+
sudo apt-get install clang-format
25+
shopt -s globstar
1726
- uses: actions/checkout@v2
1827
- run: clang-format -i ${{ matrix.files }}
19-
- run: exit $(git status -s | wc -l)
28+
- uses: ./.github/actions/process-linting-results
29+
with:
30+
linter_name: clang-format
2031

2132
cmake-format:
2233
runs-on: ubuntu-20.04
2334
strategy:
35+
fail-fast: false
2436
matrix:
25-
files: ["CMakeLists.txt", "**/CMakeLists.txt", "cmake/code-coverage.cmake"]
37+
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake"]
2638
steps:
2739
- uses: actions/setup-python@v2
2840
with:
29-
python-version: '3.x'
41+
python-version: "3.x"
3042
- run: pip install cmakelang
43+
- run: shopt -s globstar
3144
- uses: actions/checkout@v2
32-
- run: ls ${{ matrix.files }}
33-
- run: cmake-format --check $(ls ${{ matrix.files }})
45+
- run: cmake-format -i ${{ matrix.files }}
46+
- uses: ./.github/actions/process-linting-results
47+
with:
48+
linter_name: cmake-format
3449

3550
clang-tidy:
3651
runs-on: ubuntu-20.04
3752
steps:
3853
- run: sudo apt-get install clang-tidy
39-
- uses: actions/checkout@v2
4054
- uses: lukka/get-cmake@latest
41-
- uses: ./.github/actions/install/gtest
42-
55+
- uses: actions/checkout@v2
4356
- name: configure
4457
run: |
4558
mkdir build
4659
cd build
4760
cmake .. -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
48-
4961
- name: run
50-
run: |
51-
cd build
52-
make
53-
- run: exit $(git status -s | wc -l)
62+
working-directory: build
63+
run: make
64+
- uses: ./.github/actions/process-linting-results
65+
with:
66+
linter_name: clang-tidy
67+
68+
render-defaults:
69+
runs-on: ubuntu-20.04
70+
strategy:
71+
fail-fast: false
72+
matrix:
73+
traits:
74+
- { name: "boost_json", library: "Boost.JSON", url: "https://github.com/boostorg/json", disable_pico: true }
75+
- { name: "danielaparker_jsoncons", library: "jsoncons", url: "https://github.com/danielaparker/jsoncons", disable_pico: true }
76+
- { name: "kazuho_picojson", library: "picojson", url: "https://github.com/kazuho/picojson", disable_pico: false }
77+
- { name: "nlohmann_json", library: "JSON for Modern C++", url: "https://github.com/nlohmann/json", disable_pico: true }
78+
name: render-defaults (${{ matrix.traits.name }})
79+
steps:
80+
- uses: actions/checkout@v2
81+
- uses: ./.github/actions/render/defaults
82+
with:
83+
traits_name: ${{ matrix.traits.name }}
84+
library_name: ${{ matrix.traits.library }}
85+
library_url: ${{ matrix.traits.url }}
86+
disable_default_traits: ${{ matrix.traits.disable_pico }}
87+
- run: git add include/jwt-cpp/traits/*
88+
- uses: ./.github/actions/process-linting-results
89+
with:
90+
linter_name: render-defaults
91+
92+
render-tests:
93+
runs-on: ubuntu-20.04
94+
strategy:
95+
fail-fast: false
96+
matrix:
97+
traits:
98+
# - { name: "boost_json", suite: "BoostJsonTest" } # Currently needs work arounds for API limitations
99+
- { name: "danielaparker_jsoncons", suite: "JsonconsTest" }
100+
# - { name: "kazuho_picojson", suite: "PicoJsonTest" } # Currently the default everything tests against this!
101+
- { name: "nlohmann_json", suite: "NlohmannTest" }
102+
name: render-tests (${{ matrix.traits.name }})
103+
steps:
104+
- uses: actions/checkout@v2
105+
- run: shopt -s globstar
106+
- uses: ./.github/actions/render/tests
107+
with:
108+
traits_name: ${{ matrix.traits.name }}
109+
test_suite_name: ${{ matrix.traits.suite }}
110+
- run: clang-format -i tests/**/*.cpp
111+
- run: git add tests/traits/*
112+
- uses: ./.github/actions/process-linting-results
113+
with:
114+
linter_name: render-tests

0 commit comments

Comments
 (0)