CI/CD Integration Guide

Integrate JSON-RPC tools into your continuous integration and deployment workflows

On this page

Need the CLI tool?

Get our command-line tools for CI/CD integration.

CLI Documentation

Overview

Integrating JSON-RPC tools into your CI/CD pipeline helps ensure that your API implementations remain compliant with the JSON-RPC specification throughout the development lifecycle. This guide covers how to set up automated JSON-RPC validation, testing, and generation in popular CI/CD systems.

By automating these checks, you can catch protocol errors early in the development process, ensure consistency across multiple services, and maintain high-quality API documentation.

Benefits of CI/CD Integration

Early Error Detection

Catch JSON-RPC specification violations before they reach production

Consistent Implementation

Ensure all team members follow the same JSON-RPC standards

Automated Documentation

Generate and update API documentation automatically

Compatibility Testing

Verify backward compatibility when updating APIs

GitHub Actions Integration

To integrate JSON-RPC validation into your GitHub Actions workflow:

Example Workflow

name: JSON-RPC Validation

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  validate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          
      - name: Install dependencies
        run: npm install @jsonrpc-tools/validator
        
      - name: Validate JSON-RPC definitions
        run: npx jsonrpc-validator ./src/api/**/*.json --schema=2.0

Advanced Configuration

For more complex setups, you can create a custom GitHub Action that runs multiple JSON-RPC tools:

name: JSON-RPC CI Pipeline

on:
  push:
    branches: [ main ]
    
jobs:
  jsonrpc-pipeline:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: '18'
          
      - name: Install dependencies
        run: |
          npm install @jsonrpc-tools/validator
          npm install @jsonrpc-tools/generator
          npm install @jsonrpc-tools/tester
      
      - name: Validate JSON-RPC schemas
        run: npx jsonrpc-validator ./schemas/**/*.json
      
      - name: Generate client code
        run: npx jsonrpc-codegen ./schemas/**/*.json --output=./generated --language=typescript
      
      - name: Run integration tests
        run: npx jsonrpc-tester ./tests/integration/**/*.test.js

GitLab CI Integration

For GitLab CI/CD pipelines, add JSON-RPC validation as a job in your .gitlab-ci.yml file:

stages:
  - validate
  - test
  - build
  - deploy

jsonrpc-validation:
  stage: validate
  image: node:18-alpine
  script:
    - npm install @jsonrpc-tools/validator
    - npx jsonrpc-validator ./src/api/**/*.json
  artifacts:
    paths:
      - validation-report.json
    expire_in: 1 week

jsonrpc-test:
  stage: test
  image: node:18-alpine
  script:
    - npm install @jsonrpc-tools/tester
    - npx jsonrpc-tester ./tests/api/**/*.test.js
  dependencies:
    - jsonrpc-validation

Jenkins Integration

For Jenkins, you can create a pipeline stage for JSON-RPC validation in your Jenkinsfile:

pipeline {
    agent {
        docker {
            image 'node:18-alpine'
        }
    }
    stages {
        stage('Checkout') {
            steps {
                checkout scm
            }
        }
        stage('Install Dependencies') {
            steps {
                sh 'npm install @jsonrpc-tools/validator'
                sh 'npm install @jsonrpc-tools/tester'
            }
        }
        stage('Validate JSON-RPC') {
            steps {
                sh 'npx jsonrpc-validator ./src/api/**/*.json --reporter=junit'
                junit 'jsonrpc-validation-results.xml'
            }
        }
        stage('Test JSON-RPC API') {
            steps {
                sh 'npx jsonrpc-tester ./tests/api/**/*.test.js'
            }
        }
    }
    post {
        always {
            archiveArtifacts artifacts: 'jsonrpc-validation-results.xml', fingerprint: true
        }
    }
}

Azure DevOps Integration

To set up JSON-RPC validation in Azure DevOps pipelines, create a azure-pipelines.yml file:

trigger:
  - main
  - develop

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '18.x'
  displayName: 'Install Node.js'

- script: |
    npm install @jsonrpc-tools/validator
    npm install @jsonrpc-tools/generator
  displayName: 'Install JSON-RPC tools'

- script: |
    npx jsonrpc-validator ./src/api/**/*.json --reporter=junit
  displayName: 'Validate JSON-RPC Schemas'

- task: PublishTestResults@2
  inputs:
    testResultsFormat: 'JUnit'
    testResultsFiles: 'jsonrpc-validation-results.xml'
    mergeTestResults: true
    testRunTitle: 'JSON-RPC Validation'

- script: |
    npx jsonrpc-codegen ./src/api/**/*.json --output=./src/generated --language=typescript
  displayName: 'Generate Client Code'
  condition: succeeded()

Pre-commit Hooks

You can also set up local pre-commit hooks to validate JSON-RPC files before they're committed:

Using Husky and lint-staged

First, install the necessary packages:

npm install --save-dev husky lint-staged @jsonrpc-tools/validator

Then configure Husky and lint-staged in your package.json:

{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/api/**/*.json": [
      "jsonrpc-validator"
    ]
  }
}

Tip: Pre-commit hooks are great for catching issues early, but make sure they run quickly to avoid disrupting the development workflow.

Best Practices

Fail Fast, Fail Early

Place JSON-RPC validation early in your CI/CD pipeline to catch issues before running time-consuming tests or builds.

Generate Meaningful Reports

Configure your tools to output detailed reports that help developers quickly identify and fix issues.

Version Your JSON-RPC Schemas

Store JSON-RPC method definitions in versioned schema files and validate against them.

Automate Code Generation

Generate client and server code from validated JSON-RPC schemas to ensure implementation matches the specification.

Integration Testing

Include JSON-RPC integration tests that verify both the format and behavior of your API endpoints.

Note: Remember to balance validation thoroughness with pipeline performance. For large projects, consider running comprehensive validation only on stable branches while using faster checks for feature branches.