Skip to content

Implement TypeScript-based GitHub Action for template processing with YAML data#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-64c66cb7-f81c-4914-8c7d-831107ed8d3a
Draft

Implement TypeScript-based GitHub Action for template processing with YAML data#1
Copilot wants to merge 2 commits intomainfrom
copilot/fix-64c66cb7-f81c-4914-8c7d-831107ed8d3a

Conversation

Copy link

Copilot AI commented Aug 28, 2025

This PR implements a complete GitHub Action that generates context-aware files from templates using YAML data as the source of truth. The action supports multiple template syntaxes, complex data structures, and various output options.

Key Features

Template Processing:

  • Support for multiple template syntaxes: Mustache ({{ }}), Shell (${ }), and ERB/Ruby (<%= %>)
  • Advanced placeholder replacement algorithm that handles nested objects and arrays
  • Depth-based processing to correctly handle complex data structures

Data Source Flexibility:

  • Fetch templates from current repository or external GitHub repositories
  • Support for specific branches, tags, or default branch selection
  • Recursive directory processing for batch template operations
  • YAML data parsing with full object hierarchy support

Array Handling:
The action implements sophisticated array processing:

# Data
skills: ["JavaScript", "Python", "Go"]
projects:
  - name: "Project A"
    language: "JavaScript"
  - name: "Project B" 
    language: "Python"
# Template
Skills: {{ .skills }}
Projects: {{ .projects }}
Details: {{ .projects[0].name }} uses {{ .projects[0].language }}

Arrays are automatically expanded by duplicating template lines, with primitive arrays replaced directly and object arrays converted to indexed placeholders for further processing.

Output Options:

  • Artifact: Upload processed files as GitHub artifacts
  • Branch: Create a new branch with processed files
  • PR: Create branch and open pull request
  • Merge: Create branch, open PR, and auto-merge

Implementation Details

The action is built with modern TypeScript and uses:

  • @actions/core and @actions/github for GitHub Actions integration
  • @octokit/rest for authenticated GitHub API calls
  • js-yaml for YAML parsing
  • mustache for template rendering
  • @vercel/ncc for building a single distributable file

The core algorithm processes placeholders in depth-order iterations, ensuring that nested structures are handled correctly and arrays are properly expanded before processing their contained elements.

Usage Example

- name: Generate configuration files
  uses: lufomatics/replaceholders@v1
  with:
    data-path: 'config/values.yml'
    template-path: 'templates/app-config.yaml'
    output-path: 'generated/'
    output-type: 'artifact'
    template-syntax: 'mustache'

This implementation provides a robust foundation for template-based file generation workflows, enabling teams to maintain centralized configuration data while generating context-specific files across different environments and use cases.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: mellolucas <54722857+mellolucas@users.noreply.github.com>
Copilot AI changed the title [WIP] Create a GitHub action that receives inputs for data-path as string, template-syntax as string, template-repo as string, template-branch as string, template-tag as string, template-path as string, recurse as Boolean, output-type as string, output-path ... Implement TypeScript-based GitHub Action for template processing with YAML data Aug 28, 2025
Copilot AI requested a review from mellolucas August 28, 2025 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants