mirror of
https://github.com/nlohmann/json.git
synced 2026-09-30 14:05:18 +00:00
The new single header goes through the same checks and install steps as json.hpp and json_fwd.hpp: - cmake/ci.cmake: ci_test_amalgamation regenerates, formats, and compares json_view.hpp as well - check_amalgamation.yml: the pull request check does the same; it runs develop's tools, so it needs config_json_view.json on develop first - meson.build: installs single_include/nlohmann/json_view.hpp - gen_bazel_build_file.cmake, BUILD.bazel: json_view.hpp joins the single-header target; the glob of the other target already covers the new headers - labeler.yml: an "aspect: json_view" label for the header, its detail/view headers, tests, and documentation The CMake install rules for include/ and single_include/, the REUSE catch-all, and Package.swift cover the new files without changes. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
117 lines
4.2 KiB
YAML
117 lines
4.2 KiB
YAML
name: "Check amalgamation"
|
|
|
|
on:
|
|
pull_request:
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
|
|
cancel-in-progress: true
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
jobs:
|
|
save:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Save PR number
|
|
run: |
|
|
mkdir -p ./pr
|
|
echo ${{ github.event.number }} > ./pr/number
|
|
echo ${{ github.event.pull_request.user.login }} > ./pr/author
|
|
- uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: pr
|
|
path: pr/
|
|
|
|
check:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
MAIN_DIR: ${{ github.workspace }}/main
|
|
INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann
|
|
TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate
|
|
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@e14015d583714f6e62063499dc959a02595150a1 # v2.21.1
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Checkout pull request
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
path: main
|
|
ref: ${{ github.event.pull_request.head.sha }}
|
|
persist-credentials: false
|
|
|
|
- name: Checkout tools
|
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
with:
|
|
path: tools
|
|
ref: develop
|
|
persist-credentials: false
|
|
|
|
- name: Install astyle
|
|
run: |
|
|
python3 -mvenv venv
|
|
venv/bin/pip3 install -r $MAIN_DIR/tools/astyle/requirements.txt
|
|
|
|
- name: Regenerate amalgamation, formatting, and BUILD.bazel
|
|
run: |
|
|
cd $MAIN_DIR
|
|
|
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s .
|
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s .
|
|
python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_view.json -s .
|
|
|
|
# the header list of the Bazel "json" target must match the files in include/
|
|
cmake -P cmake/scripts/gen_bazel_build_file.cmake
|
|
|
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
|
$INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp $INCLUDE_DIR/json_view.hpp
|
|
|
|
# fail loudly if a directory is renamed or removed: find would only warn
|
|
# about the missing path and silently drop its files from the check
|
|
SOURCE_DIRS="docs/mkdocs/docs/examples include tests"
|
|
for DIR in $SOURCE_DIRS; do
|
|
if [ ! -d "$DIR" ]; then
|
|
echo "::error::source directory '$DIR' does not exist"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
|
|
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
|
|
|
|
- name: Build patch and check for differences
|
|
id: diff
|
|
run: |
|
|
cd $MAIN_DIR
|
|
mkdir -p ${{ github.workspace }}/patch
|
|
git diff --patch --no-color > ${{ github.workspace }}/patch/amalgamation.patch
|
|
if [ -s ${{ github.workspace }}/patch/amalgamation.patch ]; then
|
|
echo "The source code has not been amalgamated/formatted correctly or BUILD.bazel is out of date. Diff:"
|
|
cat ${{ github.workspace }}/patch/amalgamation.patch
|
|
echo "has_diff=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "has_diff=false" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
# Uploaded so contributors can fix their PR with `git apply amalgamation.patch`
|
|
# instead of installing the pinned astyle version locally.
|
|
- name: Upload patch
|
|
if: steps.diff.outputs.has_diff == 'true'
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: amalgamation-patch
|
|
path: patch/amalgamation.patch
|
|
|
|
- name: Fail if not amalgamated/formatted
|
|
if: steps.diff.outputs.has_diff == 'true'
|
|
run: exit 1
|