Read And Parse File

Action ID: roadiehq:utils:fs:parse
NPM Package:

@roadiehq/scaffolder-backend-module-utils

Description

Reads a file from the workspace and optionally parses it

Input Schema

PropertyTypeDescriptionRequired
pathstring-
parserstring-

Output Schema

PropertyTypeDescriptionRequired
contentany-

Usage Examples

Parse package.json to set repository description and topics

Reads package.json from the generated workspace and parses it as JSON. Use this to populate the GitHub repository description and topics before registering the component. This example fits after fetch:template and before publish:github and [catalog:register](/backstage/scaffolder-actions/catal og-register/).

Copy
steps:
  - id: fetch-base
  - action: fetch:template
    input:
      url: ./skeleton
      targetPath: .
      values:
        name: ${{ parameters.name }}
        owner: ${{ parameters.owner }}
        repoHost: github.com

  - id: parse_package
    action: roadiehq:utils:fs:parse
    input:
      path: package.json
      parser: json

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.repoOwner }}&repo=${{ parameters.repoName }}
      defaultBranch: main
      description: ${{ steps.parse_package.output.content.name }} v${{ steps.parse_package.output.content.version }}
      repoVisibility: private
      topics: ${{ steps.parse_package.output.content.keywords }}

  - id: register
    action: catalog:register
    input:
      catalogInfoUrl: ${{ steps.publish.output.repoContentsUrl }}/catalog-info.yaml

Parse multi-document Kubernetes manifest to drive publishing and optional files

Parses a multi-document YAML file and uses values from the first document to describe the repo. It also conditionally copies monitoring files if a Service resource is present. Place this after fetch:template and before publish:github and catalog:register.

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

  - id: parse_k8s
    action: roadiehq:utils:fs:parse
    input:
      path: k8s/manifests.yaml
      parser: multiyaml

  - id: add-monitoring
    if: ${{ steps.parse_k8s.output.content[1].kind == "Service" }}
    action: fetch:template
    input:
      url: ./addons/monitoring
      targetPath: monitoring/
      values:
        serviceName: ${{ steps.parse_k8s.output.content[1].metadata.name }}

  - id: publish
    action: publish:github
    input:
      repoUrl: github.com?owner=${{ parameters.repoOwner }}&repo=${{ parameters.repoName }}
      defaultBranch: main
      description: Deploys ${{ steps.parse_k8s.output.content[0].metadata.name }} in namespace ${{ steps.parse_k8s.output.content[0].metadata.namespace }}
      repoVisibility: public

  - id: register
    action: catalog:register
    input:
      catalogInfoUrl: ${{ steps.publish.output.repoContentsUrl }}/catalog-info.yaml