Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test Replaceholders Action

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Create test data
run: |
mkdir -p test-data test-templates test-output
cat > test-data/config.yml << 'EOF'
app:
name: "My Application"
version: "1.0.0"
environment: "production"
features:
- "authentication"
- "logging"
- "monitoring"
EOF

cat > test-templates/app-config.txt << 'EOF'
Application: {{ .app.name }}
Version: {{ .app.version }}
Environment: {{ .environment }}

Features:
{{ .features }}
EOF

- name: Test Replaceholders Action
uses: ./
with:
data-path: 'test-data/config.yml'
template-path: 'test-templates/app-config.txt'
output-path: 'test-output/'
output-type: 'artifact'

- name: Verify output
run: |
if [ -f "test-output/app-config.txt" ]; then
echo "✅ Output file created successfully"
echo "📄 File contents:"
cat test-output/app-config.txt
else
echo "❌ Output file not found"
exit 1
fi
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules/
lib/
*.log
*.tmp
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
coverage/
*.tsbuildinfo
211 changes: 209 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,209 @@
# replaceholder
Effortlessly generate context-aware files from templates using a centralized, highly flexible source of truth
# Replaceholders GitHub Action

Effortlessly generate context-aware files from templates using a centralized, highly flexible source of truth.

## Overview

This GitHub Action allows you to:
- Fetch template files from any GitHub repository
- Load data from YAML files
- Replace placeholders in templates with data values
- Handle complex data structures including arrays and nested objects
- Output results as artifacts, branches, pull requests, or merged changes

## Usage

```yaml
name: Generate Files
on: [push]

jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Generate files from templates
uses: ./
with:
data-path: 'data/config.yml'
template-path: 'templates/my-template.txt'
output-path: 'generated/'
output-type: 'artifact'
```

## Inputs

| Input | Description | Required | Default |
|-------|-------------|----------|---------|
| `data-path` | Path to YAML file containing data for placeholder replacement | Yes | |
| `template-syntax` | Template syntax: `mustache` ({{ }}), `shell` (${ }), `erb` (<%= %>) | No | `mustache` |
| `template-repo` | Repository containing template files | No | Current repository |
| `template-branch` | Branch to fetch template files from | No | Default branch |
| `template-tag` | Tag to fetch template files from | No | |
| `template-path` | Path to template file or directory | Yes | |
| `recurse` | Whether to process directories recursively | No | `false` |
| `output-type` | Output type: `artifact`, `branch`, `pr`, `merge` | No | `artifact` |
| `output-path` | Path where processed files will be placed | Yes | |
| `github-token` | GitHub token for API authentication | No | `${{ github.token }}` |

## Template Syntax

### Mustache (default)
```
Hello {{ .name }}, you are {{ .age }} years old.
```

### Shell
```
Hello ${ .name }, you are ${ .age } years old.
```

### ERB/Ruby
```
Hello <%= .name %>, you are <%= .age %> years old.
```

## Data Structure Handling

### Simple Values
Data:
```yaml
name: "John Doe"
age: 30
```

Template:
```
Name: {{ .name }}
Age: {{ .age }}
```

Result:
```
Name: John Doe
Age: 30
```

### Nested Objects
Data:
```yaml
config:
theme: "dark"
debug: true
```

Template:
```
Theme: {{ .config.theme }}
Debug: {{ .config.debug }}
```

### Arrays of Primitives
Data:
```yaml
skills:
- "JavaScript"
- "Python"
- "Go"
```

Template:
```
Skills:
{{ .skills }}
```

Result:
```
Skills:
JavaScript
Python
Go
```

### Arrays of Objects
Data:
```yaml
projects:
- name: "Project A"
language: "JavaScript"
- name: "Project B"
language: "Python"
```

Template:
```
Projects:
{{ .projects }}

Details:
Name: {{ .projects[0].name }}
Language: {{ .projects[0].language }}
```

Result:
```
Projects:
{{ .projects[0] }}
{{ .projects[1] }}

Details:
Name: Project A
Language: JavaScript
```

## Output Types

### Artifact (default)
Uploads processed files as a GitHub artifact.

### Branch
Creates a new branch with the processed files.

### PR
Creates a new branch and opens a pull request.

### Merge
Creates a branch, opens a PR, and automatically merges it.

## Examples

### Basic Usage
```yaml
- name: Generate config files
uses: ./
with:
data-path: 'config/app.yml'
template-path: 'templates/config.yaml'
output-path: 'generated/'
```

### Process Multiple Templates
```yaml
- name: Generate multiple files
uses: ./
with:
data-path: 'data/values.yml'
template-path: 'templates/'
recurse: true
output-path: 'output/'
output-type: 'branch'
```

### Use External Template Repository
```yaml
- name: Generate from external templates
uses: ./
with:
data-path: 'local-data.yml'
template-repo: 'myorg/templates'
template-branch: 'main'
template-path: 'configs/app.template'
output-path: 'generated/'
output-type: 'pr'
```

## License

This project is licensed under the Apache 2.0 License - see the [LICENSE](LICENSE) file for details.
52 changes: 52 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Replaceholders'
description: 'Generate context-aware files from templates using a centralized, flexible source of truth'
author: 'lufomatics'
branding:
icon: 'file-text'
color: 'blue'

inputs:
data-path:
description: 'Path to YAML file containing data for placeholder replacement'
required: true
template-syntax:
description: 'Template syntax to use: mustache ({{ }}), shell (${ }), erb (<%= %>)'
required: false
default: 'mustache'
template-repo:
description: 'Repository containing template files (defaults to current repository)'
required: false
template-branch:
description: 'Branch to fetch template files from'
required: false
template-tag:
description: 'Tag to fetch template files from'
required: false
template-path:
description: 'Path to template file or directory'
required: true
recurse:
description: 'Whether to process directories recursively'
required: false
default: 'false'
output-type:
description: 'Output type: artifact, branch, pr, merge'
required: false
default: 'artifact'
output-path:
description: 'Path where processed files will be placed'
required: true
github-token:
description: 'GitHub token for API authentication'
required: false
default: ${{ github.token }}

outputs:
files-processed:
description: 'Number of files that were processed'
output-location:
description: 'Location where the processed files were placed'

runs:
using: 'node20'
main: 'dist/index.js'
Loading