Skip to content

JSON to Variables Setter

GitHub Marketplace

Overview

JSON to Variables Setter (json2vars-setter) is a GitHub Action that parses a JSON file and sets its values as output variables in GitHub Actions workflows. This action streamlines the management of matrix testing configurations and other workflow variables, making your CI/CD processes more maintainable and adaptable.

By centralizing your configuration in JSON files, you gain the ability to easily manage and update testing environments across multiple workflows, reducing duplication and maintenance overhead.

Key Features

  • JSON Parsing: Convert JSON files into GitHub Actions output variables for use in your workflows
  • Dynamic Version Management: Automatically update your testing matrix with latest language versions from official sources
  • Version Caching: Cache version information to reduce API calls and improve workflow performance
  • Support for Multiple Languages: Compatible with Python, Ruby, Node.js, Go, and Rust
  • Flexible Configuration: Maintain a single source of truth for your matrix testing environments

Supported Matrix Components

Languages Actions Example Test Status
Python setup-python Python Test
Ruby setup-ruby Ruby Test
Node.js setup-node Node.js Test
Go setup-go Go Test
Rust rust-toolchain Rust Test

Quick Start

See Basic Usage Examples for details.

jobs:
  set_variables:
    runs-on: ubuntu-latest
    outputs:
      os: ${{ steps.json2vars.outputs.os }}
      versions_python: ${{ steps.json2vars.outputs.versions_python }}
      ghpages_branch: ${{ steps.json2vars.outputs.ghpages_branch }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4.2.2

      - name: Set variables from JSON
        id: json2vars
        uses: 7rikazhexde/json2vars-setter@v1.0.1
        with:
          json-file: .github/json2vars-setter/sample/matrix.json

  run_tests:
    needs: set_variables
    strategy:
      matrix:
        os: ${{ fromJson(needs.set_variables.outputs.os) }}
        python-version: ${{ fromJson(needs.set_variables.outputs.versions_python) }}
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4.2.2
        with:
          fetch-depth: 0

      - name: Set up Python
        uses: actions/setup-python@v5.5.0
        with:
          python-version: ${{ matrix.python-version }}
      # Other steps

Components

The action consists of three main components that work together to provide a powerful, flexible solution:

graph TD
    subgraph "JSON to Variables Setter"
        A[JSON to Variables Parser ] -->|Reads| B[Matrix JSON File]
        A -->|Sets| C[GitHub Actions Outputs]

        D[Dynamic Matrix Updater] -->|Updates| B
        D -->|Fetches from| E[GitHub API]

        F[Version Cache Manager] -->|Caches| G[Version Information]
        F -->|Fetches from| E
        F -->|Generates| B
    end

    C -->|Used by| I[GitHub Workflows]

    classDef core fill:#43a047,stroke:#2e7d32,stroke-width:2px,color:#fff
    classDef file fill:#ffca28,stroke:#fb8c00,stroke-width:1px,color:#333333
    classDef output fill:#42a5f5,stroke:#1976d2,stroke-width:1px
    classDef external fill:#78909c,stroke:#546e7a,stroke-width:1px
    classDef api fill:#e91e63,stroke:#c2185b,stroke-width:1px,color:#fff

    class A,D,F core
    class B,G file
    class C output
    class I external
    class E api
  1. JSON to Variables Parser (json_to_github_output.py): Core component that parses JSON and converts it to GitHub Actions outputs. Makes your configuration data accessible throughout your workflow.

  2. Dynamic Matrix Updater (update_matrix_dynamic.py): Updates your matrix configuration with the latest or stable language versions. Ensures your CI/CD tests run against current language versions without manual updates.

  3. Version Cache Manager (cache_version_info.py): Manages cached version information to optimize API usage. Reduces external API calls by intelligently caching data, improving workflow performance and reliability.

Learn More