Skip to content
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Latest commit

Β 

History

1,623 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

JSON to Variables Setter

JSON to Variables Setter
Project Info

GitHub Marketplace Docs License: MIT
Test on PR Python
uv Ruff Checked with mypy ty typos pre-commit
zizmor gitleaks

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.

Table of Contents

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, Rust, PHP, .NET (C#), Java, Deno, Bun, Zig, Elixir, Dart, Swift, Julia, Crystal, Haskell, OCaml, Kotlin, Flutter, and the Clang/LLVM and GCC C++ compilers
  • 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
PHP setup-php PHP Test
.NET setup-dotnet .NET Test
Java setup-java Java Test
Deno setup-deno Deno Test
Bun setup-bun Bun Test
Zig setup-zig Zig Test
Elixir setup-beam Elixir Test
Dart setup-dart Dart Test
Swift setup-swift Swift Test
Julia setup-julia Julia Test
Crystal install-crystal Crystal Test
Haskell setup-haskell Haskell Test
OCaml setup-ocaml OCaml Test
Kotlin kotlin-compiler Kotlin Test
Clang/LLVM setup-cpp Clang Test
GCC setup-cpp GCC Test
Flutter flutter-action Flutter Test

πŸ“– Per-language details β€” supported OS, versions, and the setup action each example drives β€” are on the Languages section of the documentation.

Sample Workflows

Beyond the per-language tests above, these runnable use-case samples live in this repository and execute on real GitHub Actions. The green badge is proof you can reproduce the result, then copy the files into your own project β€” no local setup required to gain confidence.

Use case Status What it demonstrates Files
Single source of truth Sample: Single Source of Truth One JSON parsed once, then consumed by an independent test matrix and a separate lint job β€” define versions in one place, use them everywhere workflow README
Monorepo Sample: Monorepo Several projects in one repo, each with its own matrix JSON (Python backend + Node.js frontend) and an independent test matrix workflow README
Template from cache Sample: Template (cache) Generate a matrix from an existing version cache with no API calls (template-only), trimmed via output-count workflow README
Version cache Sample: Version Cache Drive a multi-version matrix from a committed cache (use-cache) β€” zero API calls on a cache hit, auto-refresh when cache-max-age is exceeded workflow README
Dynamic update (scheduled) Sample: Dynamic Update Weekly scheduled maintenance: fetch the latest language versions from the live API (update-matrix) and rebuild the matrix β€” side-effect-free (no commit) workflow README
Conditional matrix Sample: Conditional Matrix Pick the matrix by event β€” a light, fast matrix on pull requests and the full cross-OS matrix on schedule / dispatch workflow README
Reusable workflow Sample: Reusable Workflow Define the matrix once in a workflow_call library and consume its outputs from a caller β€” maintain the version set in one place workflow README

Quick Start

Note

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@v7.0.1

      - name: Set variables from JSON
        id: json2vars
        uses: 7rikazhexde/json2vars-setter@v1.13.0
        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@v7.0.1
        with:
          fetch-depth: 0

      - name: Set up Python
        uses: actions/setup-python@v7.0.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:

Mermaid Diagram

  1. JSON to Variables Parser: Core component that parses JSON and converts it to GitHub Actions outputs
  2. Dynamic Matrix Updater: Updates your matrix configuration with the latest or stable language versions
  3. Version Cache Manager: Manages cached version information to optimize API usage

Documentation

For detailed information, please check the Documentation Site.

The documentation includes:

  • Getting Started guide
  • Detailed feature explanations
  • Usage examples
  • Complete reference of all configuration options

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

JSON to Variables Setter (json2vars-setter) is a GitHub Action designed to parse a JSON file and set the resulting variables (such as operating systems, Python versions, and GitHub Pages branch) as outputs in a GitHub Actions workflow.

Topics

Resources

Contributing

Stars

3 stars

Watchers

1 watching

Forks

Releases

Used by

Contributors

Languages