JSONata YAML Transform

Action ID: roadiehq:utils:jsonata:yaml:transform
NPM Package:

@roadiehq/scaffolder-backend-module-utils

Description

Allows performing JSONata operations and transformations on a YAML file in the workspace.

Input Schema

PropertyTypeDescriptionRequired
asstring-
pathstring-
loadAllboolean-
expressionstring-

Output Schema

PropertyTypeDescriptionRequired
resultobject-

Usage Examples

Extract image and app name from Helm values.yaml

Extracts fields from a Helm values file and returns a compact object you can use in later steps via steps.values_info.outputs.result. Use this after fetch:template and before publishing.

Copy
steps:
  - id: fetch
    action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        name: ${{ parameters.name }}
        owner: ${{ user.entity.ref }}

  - id: values_info
    action: roadiehq:utils:jsonata:yaml:transform
    input:
      path: chart/values.yaml
      expression: |
        {
          "image": $.image.repository & ":" & $.image.tag,
          "appName": $.name
        }
      as: object

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme&repo=${{ parameters.name }}
      defaultBranch: main

Summarize Deployments in a multi-document Kubernetes manifest

Parses a multi-document YAML (separated by ---), filters Deployment objects, and returns their names and images. Use loadAll true when working with k8s bundles fetched via fetch:template.

Copy
steps:
  - id: fetch
    action: fetch:template
    input:
      url: ./k8s
      targetPath: .
      values:
        serviceName: ${{ parameters.name }}

  - id: k8s_deployments
    action: roadiehq:utils:jsonata:yaml:transform
    input:
      path: k8s/resources.yaml
      loadAll: true
      expression: |
        $map($[kind='Deployment'], function($d) {
          {
            "name": $d.metadata.name,
            "image": $d.spec.template.spec.containers[0].image
          }
        })
      as: object

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme&repo=${{ parameters.name }}
      defaultBranch: main

Extract ownership and system metadata from catalog-info.yaml

Reads Backstage catalog metadata from catalog-info.yaml to expose owner, system, lifecycle, and component name via the result output. Useful for validating metadata before catalog:register.

Copy
steps:
  - id: fetch
    action: fetch:template
    input:
      url: ./service
      targetPath: .
      values:
        name: ${{ parameters.name }}
        owner: ${{ parameters.owner }}

  - id: catalog_meta
    action: roadiehq:utils:jsonata:yaml:transform
    input:
      path: catalog-info.yaml
      expression: |
        {
          "owner": $.spec.owner,
          "system": $.spec.system,
          "lifecycle": $.spec.lifecycle,
          "component": $.metadata.name
        }
      as: object

  - id: register
    action: catalog:register
    input:
      repoContentsUrl: https://github.com/acme/${{ parameters.name }}/blob/main
      catalogInfoPath: /catalog-info.yaml

Generate a ConfigMap YAML string from app config values

Builds a new Kubernetes ConfigMap from an app config file and returns it as a YAML string in result. Use when you need to generate manifests for later commit or deployment after fetch:template.

Copy
steps:
  - id: fetch
    action: fetch:template
    input:
      url: ./app
      targetPath: .
      values:
        name: ${{ parameters.name }}

  - id: configmap_yaml
    action: roadiehq:utils:jsonata:yaml:transform
    input:
      path: config/app-config.yaml
      expression: |
        {
          "apiVersion": "v1",
          "kind": "ConfigMap",
          "metadata": { "name": $.app.name & "-config" },
          "data": $.config
        }
      as: string

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme&repo=${{ parameters.name }}
      defaultBranch: main

Pick environment-specific settings using a template parameter

Selects values for a specific environment from a YAML matrix using a template parameter. This is useful for environment-aware scaffolds after fetch:template.

Copy
steps:
  - id: fetch
    action: fetch:template
    input:
      url: ./infra
      targetPath: .
      values:
        env: ${{ parameters.envName }}
        serviceName: ${{ parameters.name }}

  - id: env_selection
    action: roadiehq:utils:jsonata:yaml:transform
    input:
      path: environments.yaml
      expression: |
        (
          $env := "${{ parameters.envName }}";
          $e := $.environments[name=$env][0];
          {
            "selectedUrl": $e.url,
            "replicas": $e.replicas,
            "namespace": $e.namespace
          }
        )
      as: object

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=acme&repo=${{ parameters.name }}
      defaultBranch: main