A GitHub Action that populates JSON templates with configuration values. Ideal for setting up distinct environments, such as development and production, for cloud-hosted applications.
- Define a JSON template with placeholders marked as
$variableName
for single value replacements, or use backtick strings with${variableName}
for in-string replacements. - Supply a configuration JSON file containing values for these placeholders.
- The action will output a new JSON file with all placeholders replaced by the corresponding values from the configuration.
Include the action in your workflow configuration:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Populate JSON Template
uses: hughack/json-simple-template@v0.2.0
with:
config-file: 'path/to/config.json'
template-file: 'path/to/template.json'
output-file: 'path/to/output.json'
Assuming a web application needs different configurations for its development and production cloud environments.
Template File (template.json
):
{
"databaseEndpoint": $dbEndpoint,
"assetsDomain": `https://${assetDomain}`,
"loggingLevel": $logLevel,
"cache": {
"type": $cacheType,
"duration": $cacheDuration
}
}
{
"dbEndpoint": "https://dev-db.mysite.cloud",
"assetDomain": "dev-assets.mysite.cloud",
"logLevel": "verbose",
"cacheType": "memory",
"cacheDuration": 3600
}
{
"dbEndpoint": "https://db.mysite.cloud",
"assetDomain": "assets.mysite.cloud",
"logLevel": "error",
"cacheType": "redis",
"cacheDuration": 86400
}
Output for Development:
{
"databaseEndpoint": "https://dev-db.mysite.cloud",
"assetsDomain": "https://dev-assets.mysite.cloud",
"loggingLevel": "verbose",
"cache": {
"type": "memory",
"duration": 3600
}
}
Output for Production:
{
"databaseEndpoint": "https://db.mysite.cloud",
"assetsDomain": "https://assets.mysite.cloud",
"loggingLevel": "error",
"cache": {
"type": "redis",
"duration": 86400
}
}