Coder Social home page Coder Social logo

nsxsoft / action-read-yaml Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pietrobolcato/action-read-yaml

0.0 1.0 0.0 964 KB

Custom github action used to read yaml files, supporting multiple keys and variable replacements

JavaScript 100.00%

action-read-yaml's Introduction

Read YAML Github action

This action reads a .yaml file, and sets one output for every key it has. These outputs can be used in later steps, which allows a yaml file to function as a configuration file within a Github workflow.

Furthermore it supports variables interpolation, using the $(var) syntax. This allows for complex dependencies and relationship between keys, enabling great flexibility when creating the yaml file.

Finally, it supports hierarchy of nested values, representing the output through dot notation.

For more information, check the example below.

Example usage

Two examples are provided in the examples folder.

Basic config

The config file contains the following keys:

namespace: namespace_example
location: location_example
environment: dev

resource_group_name: $(namespace)-$(location)-$(environment) # this will be replaced with the variables above

Note that the key resource_group_name uses variable interpolation. The key value will resolve to: namespace_example-location_example-dev.

The action reads the yaml file as following:

name: helpers-read-yaml

on:
  push:
  workflow_dispatch:

jobs:
  read-yaml:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3

      - name: read-yaml-file
        uses: pietrobolcato/[email protected]
        id: read_action_js
        with:
          config: ${{ github.workspace }}/examples/config_example.yaml

      - name: use-yaml-file
        run: |
          echo namespace: ${{ steps.read_action_js.outputs['namespace'] }}
          echo location: ${{ steps.read_action_js.outputs['location'] }}
          echo environment: ${{ steps.read_action_js.outputs['environment'] }}
          echo resource_group_name: ${{ steps.read_action_js.outputs['resource_group_name'] }}

And outputs:

namespace: namespace_example
location: location_example
environment: dev
resource_group_name: namespace_example-location_example-dev

Nested config

The config file contains the following keys:

name: example
environment:
  name: example
  permissions:
    - name: example
      permission: read
    - name: example2
      permission: write
deployment:
  code:
    source:
      libs: path/to/libs
      entry: path/to/entry

Note that this is contained nested values. The action reads the yaml file in the same way as the example above, and outputs:

name: example
environment.name: example
environment.permissions.0.name: example
environment.permissions.0.permission: read
environment.permissions.1.name: example2
environment.permissions.1.permission: write
deployment.code.source.libs: path/to/libs
deployment.code.source.entry: path/to/entry

action-read-yaml's People

Contributors

pietrobolcato avatar

Watchers

 avatar

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.