Giter Club home page Giter Club logo

github-action-config-levels's Introduction

GitHub 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.ymldev.ymlgroup1/common.ymlgroup1/dev.ymlResult
---
project: hello
---
environment: dev
logging: INFO
---
logging: DEBUG
---
project: World
hosts:
- boo
- foo
{
  "project": "World",
  "environment": "dev",
  "logging": "DEBUG",
  "hosts": ["boo", "foo"]
}

Inputs

patterns

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.

merge_object

Way to merge objects [deep, overwrite, off].

  • deep — merge objects deeply
  • overwrite — overwrite objects that are at the root
  • off — use the lowest level configuration file

Default: deep.

merge_array

Way to merge arrays [concatenating, overwrite]. Also affects the type of array merge when merging objects.

Default: concatenating.

merge_plain

Way to merge plain text [concatenating, overwrite].

Default: concatenating.

output_properties

Output each property of the object as JSON.

Default: false.

loop

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 }}'

loop_items_format

The format in which the list is passed to the loop

  • text — each row is an item of a list
  • json — list in JSON format
  • yaml — list in YAML format

Default: text.

loop_items_key

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.

Outputs

result

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.

<object property>

Returns each property of an object in a separate output. Properties are returned when the output_properties input parameter is set to true.

License

The scripts and documentation in this project are released under the MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.