Skip to content

Lehoczky/render-nunjucks-template-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Render nunjucks template

CI status check dist status formatted with prettier

A GitHub action to render nunjucks templates.

Usage

Inline template

name: Example

on:
  workflow_dispatch:

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - name: Check out Git repository ⏬
        uses: actions/checkout@v4

      - name: Render template string 🎬
        id: render-template-string
        uses: Lehoczky/[email protected]
        with:
          template: "Hello {{ username | capitalize }}"
          vars: |
            { 
              "username": "john" 
            }

      - name: Print output 📽
        run: echo "${{ steps.render-template-string.outputs.result }}"

Template from file

name: Example

on:
  workflow_dispatch:

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - name: Check out Git repository ⏬
        uses: actions/checkout@v4

      - name: Render template string 🎬
        id: render-template-string
        uses: Lehoczky/[email protected]
        with:
          template-path: .github/templates/example.njk
          vars: |
            { 
              "username": "john" 
            }

      - name: Print output 📽
        run: echo "${{ steps.render-template-string.outputs.result }}"

Using injected context

The GitHub action context and env variables are automatically injected into the templates for convenience:

- name: Render template string 🎬
  id: render-template-string
  uses: Lehoczky/[email protected]
  with:
    template: |
      GitHub context:
      {{ context | dump(2) }}

      Env:
      {{ env | dump(2) }}

Inputs

name description default
template Nunjucks template string ""
template-path Path to nunjucks template file ""
vars Variables to use in template in JSON format {}
auto-escape Controls if output with dangerous characters are escaped automatically true
trim-blocks Automatically remove trailing newlines from a block/tag false
lstrip-blocks Automatically remove leading whitespace from a block/tag false

Either template or template-path is required. If both of them are defined, template-path takes precedence.

To learn more about auto-escape, trim-blocks and lstrip-block, see the official Nunjucks documentation: https://mozilla.github.io/nunjucks/api.html#configure

Outputs

name description
result Rendered file content

Development docs

See development.md