| 1 |
name: Update bundled nlohmann/json |
| 2 |
|
| 3 |
on: |
| 4 |
schedule: |
| 5 |
# Run daily at 06:10 UTC |
| 6 |
- cron: '10 6 * * *' |
| 7 |
workflow_dispatch: |
| 8 |
|
| 9 |
permissions: |
| 10 |
contents: write |
| 11 |
pull-requests: write |
| 12 |
|
| 13 |
jobs: |
| 14 |
update-json: |
| 15 |
runs-on: ubuntu-latest |
| 16 |
steps: |
| 17 |
- name: Checkout |
| 18 |
uses: actions/checkout@v4 |
| 19 |
|
| 20 |
- name: Read bundled nlohmann/json version |
| 21 |
id: bundled |
| 22 |
run: | |
| 23 |
file="src/nlohmann/json.hpp" |
| 24 |
if [ ! -f "$file" ]; then |
| 25 |
echo "::error::$file not found" |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
major=$(grep -E '^#define NLOHMANN_JSON_VERSION_MAJOR' "$file" | awk '{print $3}') |
| 29 |
minor=$(grep -E '^#define NLOHMANN_JSON_VERSION_MINOR' "$file" | awk '{print $3}') |
| 30 |
patch=$(grep -E '^#define NLOHMANN_JSON_VERSION_PATCH' "$file" | awk '{print $3}') |
| 31 |
if [ -z "$major" ] || [ -z "$minor" ] || [ -z "$patch" ]; then |
| 32 |
echo "::error::Failed to parse NLOHMANN_JSON_VERSION_* from $file" |
| 33 |
exit 1 |
| 34 |
fi |
| 35 |
bundled="${major}.${minor}.${patch}" |
| 36 |
echo "bundled=$bundled" >> "$GITHUB_OUTPUT" |
| 37 |
echo "Bundled nlohmann/json version: $bundled" |
| 38 |
|
| 39 |
- name: Get latest nlohmann/json release |
| 40 |
id: latest |
| 41 |
env: |
| 42 |
GH_TOKEN: ${{ github.token }} |
| 43 |
run: | |
| 44 |
tag=$(curl -fsSL \ |
| 45 |
-H "Authorization: Bearer ${GH_TOKEN}" \ |
| 46 |
-H "Accept: application/vnd.github+json" \ |
| 47 |
https://api.github.com/repos/nlohmann/json/releases/latest | jq -r .tag_name) |
| 48 |
if [ -z "$tag" ] || [ "$tag" = "null" ]; then |
| 49 |
echo "::error::Failed to fetch latest nlohmann/json release tag" |
| 50 |
exit 1 |
| 51 |
fi |
| 52 |
# Release tags look like "v3.11.3"; strip the leading "v" for comparison. |
| 53 |
version="${tag#v}" |
| 54 |
echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 55 |
echo "version=$version" >> "$GITHUB_OUTPUT" |
| 56 |
echo "Latest nlohmann/json release: $tag (version $version)" |
| 57 |
|
| 58 |
- name: Up to date |
| 59 |
if: steps.latest.outputs.version == steps.bundled.outputs.bundled |
| 60 |
run: echo "Bundled nlohmann/json (${{ steps.bundled.outputs.bundled }}) matches the latest release; nothing to do." |
| 61 |
|
| 62 |
- name: Download new json.hpp from upstream release |
| 63 |
if: steps.latest.outputs.version != steps.bundled.outputs.bundled |
| 64 |
env: |
| 65 |
TAG: ${{ steps.latest.outputs.tag }} |
| 66 |
run: | |
| 67 |
url="https://github.com/nlohmann/json/releases/download/${TAG}/json.hpp" |
| 68 |
echo "Downloading $url" |
| 69 |
# Download to a temporary file, then verify the version matches before |
| 70 |
# overwriting the bundled header. |
| 71 |
tmp=$(mktemp) |
| 72 |
curl -fsSL --retry 3 -o "$tmp" "$url" |
| 73 |
|
| 74 |
# Sanity check: ensure the downloaded file contains the expected version macros. |
| 75 |
new_major=$(grep -E '^#define NLOHMANN_JSON_VERSION_MAJOR' "$tmp" | awk '{print $3}') |
| 76 |
new_minor=$(grep -E '^#define NLOHMANN_JSON_VERSION_MINOR' "$tmp" | awk '{print $3}') |
| 77 |
new_patch=$(grep -E '^#define NLOHMANN_JSON_VERSION_PATCH' "$tmp" | awk '{print $3}') |
| 78 |
new_version="${new_major}.${new_minor}.${new_patch}" |
| 79 |
expected="${TAG#v}" |
| 80 |
if [ "$new_version" != "$expected" ]; then |
| 81 |
echo "::error::Downloaded json.hpp version ($new_version) does not match release tag ($expected)" |
| 82 |
exit 1 |
| 83 |
fi |
| 84 |
|
| 85 |
mv "$tmp" src/nlohmann/json.hpp |
| 86 |
echo "Replaced src/nlohmann/json.hpp with upstream $TAG" |
| 87 |
|
| 88 |
- name: Create pull request |
| 89 |
if: steps.latest.outputs.version != steps.bundled.outputs.bundled |
| 90 |
uses: peter-evans/create-pull-request@v6 |
| 91 |
with: |
| 92 |
token: ${{ github.token }} |
| 93 |
branch: chore/update-nlohmann-json-${{ steps.latest.outputs.version }} |
| 94 |
delete-branch: true |
| 95 |
commit-message: | |
| 96 |
Update bundled nlohmann/json to ${{ steps.latest.outputs.version }} |
| 97 |
|
| 98 |
Replaces src/nlohmann/json.hpp with the upstream single-header release |
| 99 |
from https://github.com/nlohmann/json/releases/tag/${{ steps.latest.outputs.tag }}. |
| 100 |
title: "Update bundled nlohmann/json to ${{ steps.latest.outputs.version }}" |
| 101 |
body: | |
| 102 |
Automated update of the bundled [nlohmann/json](https://github.com/nlohmann/json) single-header library. |
| 103 |
|
| 104 |
- Previous version: `${{ steps.bundled.outputs.bundled }}` |
| 105 |
- New version: `${{ steps.latest.outputs.version }}` (tag `${{ steps.latest.outputs.tag }}`) |
| 106 |
- Source: https://github.com/nlohmann/json/releases/download/${{ steps.latest.outputs.tag }}/json.hpp |
| 107 |
- Release notes: https://github.com/nlohmann/json/releases/tag/${{ steps.latest.outputs.tag }} |
| 108 |
|
| 109 |
The downloaded `json.hpp` was verified to advertise version `${{ steps.latest.outputs.version }}` via its `NLOHMANN_JSON_VERSION_*` macros before being committed. |
| 110 |
|
| 111 |
_Opened automatically by the `update-nlohmann-json` workflow._ |
| 112 |
labels: dependencies |
| 113 |
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |
| 114 |
committer: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> |