Skip to content

Load a text file and replace mustache style variables. Returns modified text as an output for use in other actions.

License

Notifications You must be signed in to change notification settings

skills/action-text-variables

Repository files navigation

Text Variables Action πŸ“

License: MIT GitHub release Continuous Integration

Replace mustache style variables ({{ variable }}) in text templates. Returns modified text as an output for use in other actions.

Use Cases πŸ’‘

  • Dynamic Content Creation: Build customized Issue or PR descriptions beyond GitHub's built-in templating
  • Consistent Formatting: Maintain a uniform style for comments on issues and pull requests
  • Variable Replacement: Easily inject variables into any text content (files, issues, PRs, comments, wiki pages)

Basic Usage πŸš€

Direct Text with JSON Variables

steps:
  - name: Build comment using template
    id: build-comment
    uses: skills/action-text-variables@v1
    with:
      template-text: 'Hello {{ login }}, nice to meet you!'
      template-vars: >
        {
          "login": "${{ github.actor }}"
        }

  - name: Do something with result
    run: echo "${{ steps.build-comment.outputs.updated-text }}"

Direct Text with YAML Variables

steps:
  - name: Build comment using template
    id: build-comment
    uses: skills/action-text-variables@v1
    with:
      template-text: 'Hello {{ login }}, nice to meet you!'
      template-vars: |
        login: ${{ github.actor }}

  - name: Do something with result
    run: echo "${{ steps.build-comment.outputs.updated-text }}"

Inputs βš™οΈ

Provide the template as a file or directly as text. If both are provided, the file will be ignored.

Input Name Description Required
template-file The path to a text file to load as the template. No*
template-text The template text with variable placeholders. No*
template-vars A YAML dictionary or JSON object. Yes

*One of either template-file or template-text must be provided.

Outputs πŸ“€

Output Name Description
updated-text The text content with variables replaced.

Examples πŸ”₯

Use Template From Same Repository

steps:
  - name: Checkout
    uses: actions/checkout@v4

  - name: Build comment using template
    id: build-comment
    uses: skills/action-text-variables@v1
    with:
      template-file: my-files/my-template.md
      template-vars: >
        {
          "login": "${{ github.actor }}"
        }

  - name: Do something with result
    run: echo "${{ steps.build-comment.outputs.updated-text }}"

Use Template From Another Repository

steps:
  - name: Get templates from another repository
    uses: actions/checkout@v4
    with:
      repository: skills/exercise-toolkit
      path: exercise-toolkit

  - name: Show available templates
    run: ls -R exercise-toolkit/markdown-templates

  - name: Build comment using template
    id: build-comment
    uses: skills/action-text-variables@v1
    with:
      template-file: exercise-toolkit/markdown-templates/step-feedback/lesson-finished.md
      template-vars: >
        {
          "login": "${{ github.actor }}",
          "repo_full_name": "${{ github.repository }}"
        }

  - name: Do something with result
    run: echo "${{ steps.build-comment.outputs.updated-text }}"

About

Load a text file and replace mustache style variables. Returns modified text as an output for use in other actions.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •