Skip to content

Commit

Permalink
git revert moving mustache to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
prince-chrismc committed Jan 1, 2024
1 parent dfb0376 commit d712509
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 131 deletions.
67 changes: 67 additions & 0 deletions .github/actions/render/defaults/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
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"
outputs:
file_path:
description: "Relative path which the 'defaults.h' was written to"
value: ${{ steps.script.outputs.result }}
runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version: 14
- run: npm install mustache
shell: bash
- uses: actions/github-script@v6
id: script
env:
TRAITS_NAME: ${{ inputs.traits_name }}
LIBRARY_NAME: ${{ inputs.library_name }}
LIBRARY_URL: ${{ inputs.library_url }}
DISABLE_DEFAULT_TRAITS: ${{ inputs.disable_default_traits }}
with:
result-encoding: string
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,
})
// https://dmitripavlutin.com/replace-all-string-occurrences-javascript/
function replaceAll(string, search, replace) {
return string.split(search).join(replace);
}
const outputDir = path.join('include', 'jwt-cpp', 'traits', replaceAll(TRAITS_NAME, '_', '-'))
fs.mkdirSync(outputDir, { recursive: true })
const filePath = path.join(outputDir, 'defaults.h')
fs.writeFileSync(filePath, content)
return filePath
17 changes: 7 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,13 @@ jobs:
name: render-defaults (${{ matrix.traits.name }})
steps:
- uses: actions/checkout@v3
- uses: lukka/get-cmake@latest
- id: render
run: |
cmake -DTRAITS_NAME="${{ matrix.traits.name }}" \
-DLIBRARY_NAME="${{ matrix.traits.library }}" \
-DLIBRARY_URL="${{ matrix.traits.url }}" \
-DJWT_DISABLE_PICOJSON=${{ matrix.traits.disable_pico }} \
-P cmake/render-defaults.cmake
echo $OUTPUT_FILE
echo "file_path=$(echo $OUTPUT_FILE)" >> $GITHUB_OUTPUT
- 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 -i ${{ steps.render.outputs.file_path }}
- run: git add ${{ steps.render.outputs.file_path }}
- uses: ./.github/actions/process-linting-results
Expand Down
24 changes: 0 additions & 24 deletions cmake/render-defaults.cmake

This file was deleted.

91 changes: 0 additions & 91 deletions include/jwt-cpp/traits/defaults.h.in

This file was deleted.

4 changes: 0 additions & 4 deletions include/jwt-cpp/traits/kazuho-picojson/defaults.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#ifndef JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H
#define JWT_CPP_KAZUHO_PICOJSON_DEFAULTS_H

#ifndef JWT_DISABLE_PICOJSON
/* #undef JWT_DISABLE_PICOJSON */
#endif

#include "traits.h"

namespace jwt {
Expand Down
6 changes: 4 additions & 2 deletions include/jwt-cpp/traits/open-source-parsers-jsoncpp/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace jwt {
* \return Parsed JWK
* \throw std::runtime_error Token is not in correct format
*/
inline jwk<traits::open_source_parsers_jsoncpp> parse_jwk(const traits::open_source_parsers_jsoncpp::string_type& token) {
inline jwk<traits::open_source_parsers_jsoncpp>
parse_jwk(const traits::open_source_parsers_jsoncpp::string_type& token) {
return jwk<traits::open_source_parsers_jsoncpp>(token);
}

Expand All @@ -77,7 +78,8 @@ namespace jwt {
* \return Parsed JWKs
* \throw std::runtime_error Token is not in correct format
*/
inline jwks<traits::open_source_parsers_jsoncpp> parse_jwks(const traits::open_source_parsers_jsoncpp::string_type& token) {
inline jwks<traits::open_source_parsers_jsoncpp>
parse_jwks(const traits::open_source_parsers_jsoncpp::string_type& token) {
return jwks<traits::open_source_parsers_jsoncpp>(token);
}

Expand Down

0 comments on commit d712509

Please sign in to comment.