Getting Started
This guide will help you set up and use the JSON to Variables Setter action in your GitHub workflow.
Prerequisites
- A GitHub repository where you want to implement the action
- Basic understanding of GitHub Actions workflows
Installation
As this is a GitHub Action, there's no installation required. You simply reference the action in your workflow file.
Basic Setup
Step 1: Create a JSON Configuration File
First, create a JSON file to define your matrix testing environment. By default, the action looks for this file at .github/json2vars-setter/matrix.json
.
Here's a basic example:
You only need to include the languages your project uses. For example, if your project only uses Python, you don't need to include other languages like Ruby or Node.js.
Step 2: Configure Your Workflow
Add the JSON to Variables Setter action to your workflow file. Here's a basic example:
Important
Make sure to define the outputs at the job level if you plan to use them in other jobs.
Step 3: Use the Generated Variables
Now you can use the variables in your workflow. There are several ways to access them:
Within the Same Job
With a Matrix Strategy
Available Outputs
The action provides the following outputs:
Output | Description |
---|---|
os |
List of operating systems |
versions_python |
List of Python versions |
versions_ruby |
List of Ruby versions |
versions_nodejs |
List of Node.js versions |
versions_go |
List of Go versions |
versions_rust |
List of Rust versions |
ghpages_branch |
GitHub Pages branch name |
How to refer to Output in subsequent steps or jobs
- When accessing list variables (like
os
orversions_python
), always use thefromJson()
function to parse the JSON string. - For shell scripts, use single quotes (
'
) around the JSON string to preserve its structure. - If you don't define a language in your JSON file, its corresponding output will be an empty array.
- You can create language-specific JSON files (e.g.,
python_project_matrix.json
) for different projects.
Next Steps
- Learn about JSON to Variables transformation
- Explore Dynamic Version Updates to automatically keep your matrix up-to-date
- Check out Version Caching to optimize your workflow performance