json-structure 0.6.0

JSON Structure schema validation library for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
name: Release CLI

on:
  push:
    tags:
      - 'v*'
  workflow_dispatch:
    inputs:
      version:
        description: 'Version to release (e.g., 0.1.0)'
        required: true
        type: string

env:
  CARGO_TERM_COLOR: always
  BINARY_NAME: jstruct

jobs:
  build:
    name: Build ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux x86_64
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-22.04
            archive: tar.gz
            
          # Linux x86_64 musl (static binary)
          - target: x86_64-unknown-linux-musl
            os: ubuntu-22.04
            archive: tar.gz
            
          # Linux ARM64
          - target: aarch64-unknown-linux-gnu
            os: ubuntu-22.04
            archive: tar.gz
            cross: true
            
          # Linux ARM64 musl
          - target: aarch64-unknown-linux-musl
            os: ubuntu-22.04
            archive: tar.gz
            cross: true
            
          # macOS x86_64 (Intel)
          - target: x86_64-apple-darwin
            os: macos-13
            archive: tar.gz
            
          # macOS ARM64 (Apple Silicon)
          - target: aarch64-apple-darwin
            os: macos-14
            archive: tar.gz
            
          # Windows x86_64
          - target: x86_64-pc-windows-msvc
            os: windows-2022
            archive: zip
            
          # Windows ARM64
          - target: aarch64-pc-windows-msvc
            os: windows-2022
            archive: zip

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-action@stable
        with:
          targets: ${{ matrix.target }}

      - name: Install cross-compilation tools
        if: matrix.cross
        run: |
          cargo install cross --git https://github.com/cross-rs/cross

      - name: Install musl tools
        if: contains(matrix.target, 'musl') && !matrix.cross
        run: |
          sudo apt-get update
          sudo apt-get install -y musl-tools

      - name: Build binary
        shell: bash
        run: |
          if [ "${{ matrix.cross }}" = "true" ]; then
            cross build --release --features cli --target ${{ matrix.target }}
          else
            cargo build --release --features cli --target ${{ matrix.target }}
          fi

      - name: Prepare artifacts (Unix)
        if: runner.os != 'Windows'
        shell: bash
        run: |
          mkdir -p dist
          cp target/${{ matrix.target }}/release/${{ env.BINARY_NAME }} dist/
          cp README.md LICENSE dist/ 2>/dev/null || true
          cd dist
          tar -czvf ../${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz *

      - name: Prepare artifacts (Windows)
        if: runner.os == 'Windows'
        shell: pwsh
        run: |
          New-Item -ItemType Directory -Force -Path dist
          Copy-Item "target/${{ matrix.target }}/release/${{ env.BINARY_NAME }}.exe" dist/
          Copy-Item README.md, LICENSE dist/ -ErrorAction SilentlyContinue
          Compress-Archive -Path dist/* -DestinationPath "${{ env.BINARY_NAME }}-${{ matrix.target }}.zip"

      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.target }}
          path: |
            ${{ env.BINARY_NAME }}-${{ matrix.target }}.${{ matrix.archive }}

  # Create Debian package
  package-deb:
    name: Package DEB
    needs: build
    runs-on: ubuntu-22.04
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            arch: amd64
          - target: aarch64-unknown-linux-gnu
            arch: arm64
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.target }}

      - name: Extract binary
        run: |
          tar -xzf ${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz

      - name: Get version
        id: version
        run: |
          if [ -n "${{ inputs.version }}" ]; then
            echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
          else
            echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
          fi

      - name: Create DEB package
        run: |
          VERSION=${{ steps.version.outputs.version }}
          PKG_NAME=${{ env.BINARY_NAME }}
          ARCH=${{ matrix.arch }}
          
          mkdir -p pkg/DEBIAN
          mkdir -p pkg/usr/bin
          mkdir -p pkg/usr/share/doc/$PKG_NAME
          mkdir -p pkg/usr/share/man/man1
          
          cp ${{ env.BINARY_NAME }} pkg/usr/bin/
          chmod 755 pkg/usr/bin/${{ env.BINARY_NAME }}
          
          # Create control file
          cat > pkg/DEBIAN/control << EOF
          Package: $PKG_NAME
          Version: $VERSION
          Section: devel
          Priority: optional
          Architecture: $ARCH
          Maintainer: JSON Structure Contributors <json-structure@example.com>
          Description: JSON Structure schema validation CLI
           A command-line tool for validating JSON Structure schemas and instances.
           Supports text, JSON, and TAP output formats.
          Homepage: https://github.com/json-structure/sdk
          EOF
          
          # Create copyright file
          cp LICENSE pkg/usr/share/doc/$PKG_NAME/copyright 2>/dev/null || echo "MIT License" > pkg/usr/share/doc/$PKG_NAME/copyright
          
          # Build package
          dpkg-deb --build pkg ${PKG_NAME}_${VERSION}_${ARCH}.deb

      - name: Upload DEB
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.arch }}.deb
          path: "*.deb"

  # Create RPM package
  package-rpm:
    name: Package RPM
    needs: build
    runs-on: ubuntu-22.04
    container: fedora:latest
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            arch: x86_64
          - target: aarch64-unknown-linux-gnu
            arch: aarch64
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install RPM tools
        run: |
          dnf install -y rpm-build rpmdevtools

      - name: Download binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.target }}

      - name: Extract binary
        run: |
          tar -xzf ${{ env.BINARY_NAME }}-${{ matrix.target }}.tar.gz

      - name: Get version
        id: version
        run: |
          if [ -n "${{ inputs.version }}" ]; then
            echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
          else
            echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
          fi

      - name: Create RPM package
        run: |
          VERSION=${{ steps.version.outputs.version }}
          PKG_NAME=${{ env.BINARY_NAME }}
          ARCH=${{ matrix.arch }}
          
          # Setup rpmbuild structure
          rpmdev-setuptree
          
          # Copy binary
          mkdir -p ~/rpmbuild/BUILDROOT/${PKG_NAME}-${VERSION}-1.${ARCH}/usr/bin
          cp ${{ env.BINARY_NAME }} ~/rpmbuild/BUILDROOT/${PKG_NAME}-${VERSION}-1.${ARCH}/usr/bin/
          chmod 755 ~/rpmbuild/BUILDROOT/${PKG_NAME}-${VERSION}-1.${ARCH}/usr/bin/${{ env.BINARY_NAME }}
          
          # Create spec file
          cat > ~/rpmbuild/SPECS/${PKG_NAME}.spec << EOF
          Name:           $PKG_NAME
          Version:        $VERSION
          Release:        1
          Summary:        JSON Structure schema validation CLI
          License:        MIT
          URL:            https://github.com/json-structure/sdk
          
          %description
          A command-line tool for validating JSON Structure schemas and instances.
          Supports text, JSON, and TAP output formats.
          
          %files
          %attr(755, root, root) /usr/bin/$PKG_NAME
          EOF
          
          # Build RPM
          rpmbuild -bb --target $ARCH ~/rpmbuild/SPECS/${PKG_NAME}.spec
          
          cp ~/rpmbuild/RPMS/$ARCH/*.rpm .

      - name: Upload RPM
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-${{ matrix.arch }}.rpm
          path: "*.rpm"

  # Create macOS universal binary and PKG installer
  package-macos:
    name: Package macOS
    needs: build
    runs-on: macos-14
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download x86_64 binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-x86_64-apple-darwin

      - name: Download ARM64 binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-aarch64-apple-darwin
          path: arm64/

      - name: Get version
        id: version
        run: |
          if [ -n "${{ inputs.version }}" ]; then
            echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
          else
            echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
          fi

      - name: Create universal binary
        run: |
          tar -xzf ${{ env.BINARY_NAME }}-x86_64-apple-darwin.tar.gz -C .
          mv ${{ env.BINARY_NAME }} ${{ env.BINARY_NAME }}-x86_64
          tar -xzf arm64/${{ env.BINARY_NAME }}-aarch64-apple-darwin.tar.gz -C .
          mv ${{ env.BINARY_NAME }} ${{ env.BINARY_NAME }}-arm64
          
          # Create universal binary
          lipo -create -output ${{ env.BINARY_NAME }} ${{ env.BINARY_NAME }}-x86_64 ${{ env.BINARY_NAME }}-arm64
          
          # Verify
          lipo -info ${{ env.BINARY_NAME }}

      - name: Create PKG installer
        run: |
          VERSION=${{ steps.version.outputs.version }}
          PKG_NAME=${{ env.BINARY_NAME }}
          
          # Create package structure
          mkdir -p pkg/usr/local/bin
          cp ${{ env.BINARY_NAME }} pkg/usr/local/bin/
          chmod 755 pkg/usr/local/bin/${{ env.BINARY_NAME }}
          
          # Build package
          pkgbuild --root pkg \
                   --identifier com.json-structure.jstruct \
                   --version $VERSION \
                   --install-location / \
                   ${PKG_NAME}-${VERSION}-universal.pkg

      - name: Create tarball
        run: |
          VERSION=${{ steps.version.outputs.version }}
          mkdir -p dist
          cp ${{ env.BINARY_NAME }} dist/
          cp README.md LICENSE dist/ 2>/dev/null || true
          cd dist
          tar -czvf ../${{ env.BINARY_NAME }}-${VERSION}-macos-universal.tar.gz *

      - name: Upload PKG
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-macos.pkg
          path: "*.pkg"

      - name: Upload universal tarball
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-macos-universal.tar.gz
          path: "*-macos-universal.tar.gz"

  # Create Windows MSIX package
  package-msix:
    name: Package MSIX
    needs: build
    runs-on: windows-2022
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Download x64 binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-x86_64-pc-windows-msvc

      - name: Download ARM64 binary
        uses: actions/download-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-aarch64-pc-windows-msvc
          path: arm64/

      - name: Get version
        id: version
        shell: bash
        run: |
          if [ -n "${{ inputs.version }}" ]; then
            echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
          else
            echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
          fi

      - name: Setup Windows SDK
        uses: ChristopheLav/windows-sdk-install@v1
        with:
          version-sdk: "22621"

      - name: Create MSIX packages
        shell: pwsh
        run: |
          $version = "${{ steps.version.outputs.version }}"
          # MSIX requires 4-part version
          $msixVersion = "$version.0"
          if ($version -match '^\d+\.\d+$') {
            $msixVersion = "$version.0.0"
          } elseif ($version -match '^\d+\.\d+\.\d+$') {
            $msixVersion = "$version.0"
          }
          
          # Extract binaries
          Expand-Archive -Path "${{ env.BINARY_NAME }}-x86_64-pc-windows-msvc.zip" -DestinationPath x64
          Expand-Archive -Path "arm64/${{ env.BINARY_NAME }}-aarch64-pc-windows-msvc.zip" -DestinationPath arm64-extracted
          
          # Create x64 package structure
          New-Item -ItemType Directory -Force -Path msix-x64
          Copy-Item x64/${{ env.BINARY_NAME }}.exe msix-x64/
          
          # Create AppxManifest for x64
          @"
          <?xml version="1.0" encoding="utf-8"?>
          <Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
                   xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
                   xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
                   xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10">
            <Identity Name="JSONStructure.jstruct"
                      Publisher="CN=JSON Structure"
                      Version="$msixVersion"
                      ProcessorArchitecture="x64" />
            <Properties>
              <DisplayName>jstruct</DisplayName>
              <PublisherDisplayName>JSON Structure Contributors</PublisherDisplayName>
              <Description>JSON Structure schema validation CLI</Description>
              <Logo>Assets\StoreLogo.png</Logo>
            </Properties>
            <Resources>
              <Resource Language="en-us" />
            </Resources>
            <Dependencies>
              <TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.22621.0" />
            </Dependencies>
            <Capabilities>
              <rescap:Capability Name="runFullTrust" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" />
            </Capabilities>
            <Applications>
              <Application Id="jstruct" Executable="jstruct.exe" EntryPoint="Windows.FullTrustApplication">
                <uap:VisualElements DisplayName="jstruct"
                                    Description="JSON Structure CLI"
                                    BackgroundColor="transparent"
                                    Square150x150Logo="Assets\Square150x150Logo.png"
                                    Square44x44Logo="Assets\Square44x44Logo.png">
                </uap:VisualElements>
                <Extensions>
                  <uap3:Extension Category="windows.appExecutionAlias">
                    <uap3:AppExecutionAlias>
                      <desktop:ExecutionAlias Alias="jstruct.exe" />
                    </uap3:AppExecutionAlias>
                  </uap3:Extension>
                </Extensions>
              </Application>
            </Applications>
          </Package>
          "@ | Out-File -Encoding utf8 msix-x64/AppxManifest.xml
          
          # Create placeholder assets
          New-Item -ItemType Directory -Force -Path msix-x64/Assets
          
          # Create simple PNG placeholders (1x1 transparent)
          $pngHeader = [byte[]](0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A)
          # Minimal valid PNG
          $minPng = [Convert]::FromBase64String("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==")
          [IO.File]::WriteAllBytes("msix-x64/Assets/StoreLogo.png", $minPng)
          [IO.File]::WriteAllBytes("msix-x64/Assets/Square150x150Logo.png", $minPng)
          [IO.File]::WriteAllBytes("msix-x64/Assets/Square44x44Logo.png", $minPng)
          
          # Build MSIX using makeappx
          $sdkPath = Get-ChildItem "C:\Program Files (x86)\Windows Kits\10\bin\*\x64\makeappx.exe" | 
                     Sort-Object { [version]($_.Directory.Parent.Name) } -Descending | 
                     Select-Object -First 1
          & $sdkPath.FullName pack /d msix-x64 /p "${{ env.BINARY_NAME }}-$version-x64.msix" /o
          
          # Create ARM64 package
          New-Item -ItemType Directory -Force -Path msix-arm64
          Copy-Item arm64-extracted/${{ env.BINARY_NAME }}.exe msix-arm64/
          
          # Update manifest for ARM64
          (Get-Content msix-x64/AppxManifest.xml) -replace 'ProcessorArchitecture="x64"', 'ProcessorArchitecture="arm64"' |
            Out-File -Encoding utf8 msix-arm64/AppxManifest.xml
          
          Copy-Item msix-x64/Assets msix-arm64/Assets -Recurse
          
          & $sdkPath.FullName pack /d msix-arm64 /p "${{ env.BINARY_NAME }}-$version-arm64.msix" /o

      - name: Upload MSIX x64
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-x64.msix
          path: "*-x64.msix"

      - name: Upload MSIX ARM64
        uses: actions/upload-artifact@v4
        with:
          name: ${{ env.BINARY_NAME }}-arm64.msix
          path: "*-arm64.msix"

  # Create GitHub Release
  release:
    name: Create Release
    needs: [build, package-deb, package-rpm, package-macos, package-msix]
    runs-on: ubuntu-22.04
    if: startsWith(github.ref, 'refs/tags/v') || github.event_name == 'workflow_dispatch'
    permissions:
      contents: write
    steps:
      - name: Download all artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts

      - name: Get version
        id: version
        run: |
          if [ -n "${{ inputs.version }}" ]; then
            echo "version=${{ inputs.version }}" >> $GITHUB_OUTPUT
          else
            echo "version=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
          fi

      - name: Prepare release files
        run: |
          mkdir release
          find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" -o -name "*.deb" -o -name "*.rpm" -o -name "*.pkg" -o -name "*.msix" \) -exec cp {} release/ \;
          ls -la release/

      - name: Create checksums
        run: |
          cd release
          sha256sum * > SHA256SUMS.txt
          cat SHA256SUMS.txt

      - name: Create Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ github.event_name == 'workflow_dispatch' && format('v{0}', inputs.version) || github.ref_name }}
          name: jstruct v${{ steps.version.outputs.version }}
          draft: false
          prerelease: ${{ contains(steps.version.outputs.version, '-') }}
          generate_release_notes: true
          files: |
            release/*
          body: |
            ## Installation

            ### Linux (Debian/Ubuntu)
            ```bash
            sudo dpkg -i jstruct_${{ steps.version.outputs.version }}_amd64.deb
            ```

            ### Linux (Fedora/RHEL)
            ```bash
            sudo rpm -i jstruct-${{ steps.version.outputs.version }}-1.x86_64.rpm
            ```

            ### macOS
            ```bash
            # Using PKG installer
            sudo installer -pkg jstruct-${{ steps.version.outputs.version }}-universal.pkg -target /

            # Or manually
            tar -xzf jstruct-${{ steps.version.outputs.version }}-macos-universal.tar.gz
            sudo mv jstruct /usr/local/bin/
            ```

            ### Windows
            Download and run the MSIX installer, or extract the ZIP and add to PATH.

            ### From source
            ```bash
            cargo install json-structure --features cli
            ```

            ## Verification
            ```bash
            # Verify checksums
            sha256sum -c SHA256SUMS.txt
            ```