Write File Content

Action ID: harmonix:fs:write
NPM Package:

@aws/plugin-scaffolder-backend-aws-apps-for-backstage

Description

Writes supplied content to a file at the specified location

Input Schema

PropertyTypeDescriptionRequired
pathstring-
contentstring-
formatJsonContentboolean-

Output Schema

PropertyTypeDescriptionRequired
pathstring-

Usage Examples

Write a README for the generated service

Creates a README.md after fetching template files with fetch:template. Use this to add project documentation tailored from template parameters.

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

  - id: write-readme
    action: harmonix:fs:write
    input:
      path: README.md
      content: |
        # ${{ parameters.componentId }}

        ${{ parameters.description }}

        - Owner ${{ parameters.owner }}
        - Visibility ${{ parameters.visibility }}

        Getting started

        1. Install dependencies
           npm ci

        2. Run locally
           npm start
      formatJsonContent: false

Write and prettify a JSON service config

Generates a JSON config file and enforces pretty formatting by setting formatJsonContent to true. Use this when you need consistent JSON formatting across environments after fetch:template.

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

  - id: write-config
    action: harmonix:fs:write
    input:
      path: services/${{ parameters.componentId }}/config/service.json
      content: |
        {"serviceName":"${{ parameters.componentId }}","port":8080,"logLevel":"info","features":{"caching":true,"tracing":false}}
      formatJsonContent: true

Generate a complete package.json with formatted JSON

Writes a package.json with values from template parameters and ensures stable formatting. Use this to replace or create package metadata during scaffold after fetch:template.

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

  - id: write-package
    action: harmonix:fs:write
    input:
      path: package.json
      content: |
        {
          "name": "@${{ parameters.owner }}/${{ parameters.componentId }}",
          "version": "0.1.0",
          "private": true,
          "type": "module",
          "description": "${{ parameters.description }}",
          "scripts": {
            "build": "tsc -p tsconfig.json",
            "start": "node dist/index.js",
            "dev": "nodemon --watch src --exec ts-node src/index.ts",
            "test": "jest"
          },
          "engines": {
            "node": ">=18"
          },
          "license": "Apache-2.0"
        }
      formatJsonContent: true

Create a bootstrap shell script

Adds a setup script to initialize local development. Use this to write multi line bash scripts that run after cloning the generated repository with content written as plain text.

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

  - id: write-setup-script
    action: harmonix:fs:write
    input:
      path: scripts/setup.sh
      content: |
        #!/usr/bin/env bash
        set -euo pipefail

        echo "Setting up ${{ parameters.componentId }}"
        npm ci

        echo "Creating environment file"
        cat > .env <<EOF
        SERVICE_NAME=${{ parameters.componentId }}
        OWNER=${{ parameters.owner }}
        PORT=8080
        EOF

        echo "Setup complete"
      formatJsonContent: false

Add a GitHub Actions workflow file

Creates a CI workflow YAML under .github after fetching the template with fetch:template. Use this to provision a default pipeline for the new service.

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

  - id: write-ci-workflow
    action: harmonix:fs:write
    input:
      path: .github/workflows/ci.yml
      content: |
        name: ci

        on:
          push:
            branches: [ main ]
          pull_request:

        jobs:
          build:
            runs-on: ubuntu-latest
            steps:
              - uses: actions/checkout@v4
              - uses: actions/setup-node@v4
                with:
                  node-version: 20
              - name: Install
                run: npm ci
              - name: Lint
                run: npm run lint --if-present
              - name: Test
                run: npm test -- --ci --reporters=default --reporters=jest-junit
              - name: Build
                run: npm run build --if-present
      formatJsonContent: false