Skip to content

Commit

Permalink
🚢 Provide trait implementation for supported JSON libraries (#193)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* 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 <[email protected]>
Co-authored-by: Marek Klein <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2022
1 parent 275c750 commit 5c9787e
Show file tree
Hide file tree
Showing 52 changed files with 1,998 additions and 954 deletions.
17 changes: 17 additions & 0 deletions .github/actions/install/boost-json/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Install Boost.JSON
description: Install Boost.JSON for building test application
inputs:
version:
description: The desired Boost.JSON version to install
required: false
default: "1.77.0"
runs:
using: composite
steps:
- run: |
cd /tmp
wget https://github.com/boostorg/json/archive/boost-${{ inputs.version }}.tar.gz
tar -zxf /tmp/boost-${{ inputs.version }}.tar.gz
cd json-boost-${{ inputs.version }}
sudo cp -vR include/boost /usr/local/include
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
version:
description: The desired jsoncons version to install
required: false
default: "0.159.0"
default: "0.167.1"
runs:
using: composite
steps:
Expand Down
17 changes: 17 additions & 0 deletions .github/actions/install/kazuho-picojson/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Install PicoJSON
description: Install PicoJSON for building test application
inputs:
version:
description: The desired PicoJSON version to install
required: false
default: "v1.3.0"
runs:
using: composite
steps:
- run: |
cd /tmp
wget https://github.com/kazuho/picojson/archive/${{ inputs.version }}.tar.gz
tar -zxf /tmp/${{ inputs.version }}.tar.gz
cd picojson-${{ inputs.version }}
sudo cp -v picojson.h /usr/local/include/picojson
shell: bash
18 changes: 18 additions & 0 deletions .github/actions/install/nlohmann-json/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Install nlohmann-json
description: Install nlohmann-json for building test application
inputs:
version:
description: The desired nlohmann-json version to install
required: false
default: "3.10.4"
runs:
using: composite
steps:
- run: |
cd /tmp
wget https://github.com/nlohmann/json/archive/v${{ inputs.version }}.tar.gz
tar -zxf /tmp/v${{ inputs.version }}.tar.gz
cd json-${{ inputs.version }}
cmake .
sudo cmake --install .
shell: bash
21 changes: 21 additions & 0 deletions .github/actions/process-linting-results/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Process Linting Results
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
inputs:
linter_name:
description: The name of the tool to credit in the comment
required: true
runs:
using: "composite"
steps:
- run: git add --update
shell: bash
- id: stage
uses: dtinth/patch-generator-action@v1
- 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
52 changes: 52 additions & 0 deletions .github/actions/render/defaults/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Render `defaults.h` Template"
description: "Generate the `defaults.h` header file for a JSON library"
inputs:
traits_name:
description: "Name of the traits structure to be used. Typically in the format `author_repository` or equivilant"
required: true
library_name:
description: "Name of the JSON library."
required: true
library_url:
description: "URL to the JSON library."
required: true
disable_default_traits:
description: "Set the macro to disable the default traits"
required: false
default: "true"
runs:
using: composite
steps:
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install mustache
shell: bash
- uses: actions/github-script@v5
env:
TRAITS_NAME: ${{ inputs.traits_name }}
LIBRARY_NAME: ${{ inputs.library_name }}
LIBRARY_URL: ${{ inputs.library_url }}
DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }}
with:
script: |
const mustache = require('mustache')
const path = require('path')
const fs = require('fs')
const { TRAITS_NAME, LIBRARY_NAME, LIBRARY_URL, DISABLE_DEFAULT_TRAITS } = process.env
console.log(`Rendering ${TRAITS_NAME}!`)
const disableDefault = DISABLE_DEFAULT_TRAITS === 'true'
const template = fs.readFileSync(path.join('include', 'jwt-cpp', 'traits', 'defaults.h.mustache'), 'utf8')
const content = mustache.render(template, {
traits_name: TRAITS_NAME,
traits_name_upper: TRAITS_NAME.toUpperCase(),
library_name: LIBRARY_NAME,
library_url: LIBRARY_URL,
disable_default_traits: disableDefault,
})
const outputDir = path.join('include', 'jwt-cpp', 'traits', TRAITS_NAME.replace('_', '-'))
fs.mkdirSync(outputDir, { recursive: true })
fs.writeFileSync(path.join(outputDir, 'defaults.h'), content)
39 changes: 39 additions & 0 deletions .github/actions/render/tests/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: "Render `TraitsTests.cpp` Template"
description: "Generate the `TraitsTests.cpp` header file for a JSON library"
inputs:
traits_name:
description: "Name of the traits structure to be used. Typically in the format `author_repository` or equivilant"
required: true
test_suite_name:
description: "Name of the JSON library."
required: true
runs:
using: composite
steps:
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install mustache
shell: bash
- uses: actions/github-script@v5
env:
TRAITS_NAME: ${{ inputs.traits_name }}
SUITE_NAME: ${{ inputs.test_suite_name }}
with:
script: |
const mustache = require('mustache')
const path = require('path')
const fs = require('fs')
const { TRAITS_NAME, SUITE_NAME } = process.env
console.log(`Rendering ${TRAITS_NAME}!`)
const template = fs.readFileSync(path.join('tests', 'traits', 'TraitsTest.cpp.mustache'), 'utf8')
const content = mustache.render(template, {
traits_name: TRAITS_NAME,
traits_dir: TRAITS_NAME.replace('_', '-'),
test_suite_name: SUITE_NAME,
})
const outputDir = path.join('tests', 'traits')
fs.mkdirSync(outputDir, { recursive: true })
fs.writeFileSync(path.join(outputDir, `${SUITE_NAME}.cpp`), content)
2 changes: 2 additions & 0 deletions .github/workflows/jwt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
- uses: actions/checkout@v2
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest
- uses: ./.github/actions/install/danielaparker-jsoncons
- uses: ./.github/actions/install/boost-json

- name: configure
run: |
Expand Down
91 changes: 76 additions & 15 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,105 @@ jobs:
clang-format:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
files: ["include/jwt-cpp/*.h", "tests/**.cpp"]
files:
- "include/jwt-cpp/*.h"
- "include/jwt-cpp/traits/**/*.h"
- "tests/*.cpp"
- "tests/**/*.cpp"
- "example/*.cpp"
- "example/**/*.cpp"
steps:
- run: sudo apt-get install clang-format
- run: |
sudo apt-get install clang-format
shopt -s globstar
- uses: actions/checkout@v2
- run: clang-format -i ${{ matrix.files }}
- run: exit $(git status -s | wc -l)
- uses: ./.github/actions/process-linting-results
with:
linter_name: clang-format

cmake-format:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
files: ["CMakeLists.txt", "**/CMakeLists.txt", "cmake/code-coverage.cmake"]
files: ["**/CMakeLists.txt", "cmake/code-coverage.cmake"]
steps:
- uses: actions/setup-python@v2
with:
python-version: '3.x'
python-version: "3.x"
- run: pip install cmakelang
- run: shopt -s globstar
- uses: actions/checkout@v2
- run: ls ${{ matrix.files }}
- run: cmake-format --check $(ls ${{ matrix.files }})
- run: cmake-format -i ${{ matrix.files }}
- uses: ./.github/actions/process-linting-results
with:
linter_name: cmake-format

clang-tidy:
runs-on: ubuntu-20.04
steps:
- run: sudo apt-get install clang-tidy
- uses: actions/checkout@v2
- uses: lukka/get-cmake@latest
- uses: ./.github/actions/install/gtest

- uses: actions/checkout@v2
- name: configure
run: |
mkdir build
cd build
cmake .. -DCMAKE_CXX_CLANG_TIDY="clang-tidy;-fix"
- name: run
run: |
cd build
make
- run: exit $(git status -s | wc -l)
working-directory: build
run: make
- uses: ./.github/actions/process-linting-results
with:
linter_name: clang-tidy

render-defaults:
runs-on: ubuntu-20.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: render-defaults (${{ matrix.traits.name }})
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions/render/defaults
with:
traits_name: ${{ matrix.traits.name }}
library_name: ${{ matrix.traits.library }}
library_url: ${{ matrix.traits.url }}
disable_default_traits: ${{ matrix.traits.disable_pico }}
- run: git add include/jwt-cpp/traits/*
- uses: ./.github/actions/process-linting-results
with:
linter_name: render-defaults

render-tests:
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
traits:
# - { name: "boost_json", suite: "BoostJsonTest" } # Currently needs work arounds for API limitations
- { name: "danielaparker_jsoncons", suite: "JsonconsTest" }
# - { name: "kazuho_picojson", suite: "PicoJsonTest" } # Currently the default everything tests against this!
- { name: "nlohmann_json", suite: "NlohmannTest" }
name: render-tests (${{ matrix.traits.name }})
steps:
- uses: actions/checkout@v2
- run: shopt -s globstar
- uses: ./.github/actions/render/tests
with:
traits_name: ${{ matrix.traits.name }}
test_suite_name: ${{ matrix.traits.suite }}
- run: clang-format -i tests/**/*.cpp
- run: git add tests/traits/*
- uses: ./.github/actions/process-linting-results
with:
linter_name: render-tests
Loading

0 comments on commit 5c9787e

Please sign in to comment.