GitHub Action
action-config-levels
This action is designed to create a configuration consisting of different levels of configuration files.
During the merging of configuration files, objects that are at higher levels are overridden by objects that are at lower levels. In the same way, objects and lists can be supplemented with each lower level of configuration. The type of merging is determined by the parameters of the action.
For example, we have the following file structure in our project:
project/
├── .github/
│ ...
├── group1/
│ ├── common.yml
│ ├── dev.yml
│ └── prod.yml
├── group2/
│ ├── common.yml
│ ├── dev.yml
│ └── prod.yml
├── common.yml
├── dev.yml
└── prod.yml
Whereat the level of the folder "project" the general configuration is defined.
The groupX
folders define a specific configuration for each group.
Due to the imaginary environment variables env.GROUP
and env.ENV
we can get different configurations as a result of merging the contents of files.
- uses: blablacar/action-config-levels@master
id: config
with:
patterns: |
- common.yml
- ${{ env.ENV }}.yml
- ${{ env.GROUP }}/common.yml
- ${{ env.GROUP }}/${{ env.ENV }}.yml
- run: echo '${{ steps.config.outputs.result }}'
Configuration files have more weight, which is lower in the list.
common.yml | dev.yml | group1/common.yml | group1/dev.yml | Result |
---|---|---|---|---|
--- project: hello |
--- environment: dev logging: INFO |
--- logging: DEBUG |
--- project: World hosts: - boo - foo |
{ "project": "World", "environment": "dev", "logging": "DEBUG", "hosts": ["boo", "foo"] } |
Required A list of path patterns to possible configuration files. This field contains a string with a list in YAML format.
The file path may contain special patterns, such as *
and **
.
For more on patterns that can be used in the patterns
parameter, see Glob Primer.
Way to merge objects [deep, overwrite, off].
deep
— merge objects deeplyoverwrite
— overwrite objects that are at the rootoff
— use the lowest level configuration file
Default: deep
.
Way to merge arrays [concatenating, overwrite]. Also affects the type of array merge when merging objects.
Default: concatenating
.
Way to merge plain text [concatenating, overwrite].
Default: concatenating
.
Output each property of the object as JSON.
Default: false
.
If loop
is defined, then the action is repeated as many times as the number of rows in the variable's content.
All found mentions of {{ item }}
in the pattern are replaced with a row from the loop
variable.
The iterative execution of the action returns the object as JSON, where the key contains a row,
and the value is the result of the execution of the action according to the pattern.
Also it has output for each row as a serialized key with value in JSON if output_properties
is enabled.
Example:
- uses: blablacar/action-config-levels@master
id: config
with:
patterns: |
- {{ item }}/common.yml
- {{ item }}/${{ env.ENV }}.yml
loop: |
dir1
dir2/subdir
- run: echo '${{ steps.config.outputs.result }}'
- run: echo '${{ steps.config.outputs.dir1 }}'
- run: echo '${{ steps.config.outputs.dir2_subdir }}'
The format in which the list is passed to the loop
text
— each row is an item of a listjson
— list in JSON formatyaml
— list in YAML format
Default: text
.
Object path to the value that acts as the key. Helps set the key by which the result will be available if the item contains an object. Otherwise, the index is used as the key.
Merged configuration in JSON or plain text format.
The format is determined automatically based on file suffixes.
.yml
, .yaml
, and .json
files are converted to objects.
Returns each property of an object in a separate output.
Properties are returned when the output_properties
input parameter is set to true
.
The scripts and documentation in this project are released under the MIT License