Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
file-text

GitHub Action

Render Template

v1.5

Render Template

file-text

Render Template

Renders file based on template and passed variables

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Render Template

uses: chuhlomin/render-template@v1.5

Learn more about this action in chuhlomin/render-template

Choose a version

Render Template

main release

GitHub Action to render file based on template and passed variables.

Inputs

  • template – path to Go template file
  • vars – template variables in YAML format
  • vars_path – Path to YAML file with variables
  • result_path – (optional) desired path to result file

You must set either vars or vars_path, or you may set both of them (vars values will take precedence over vars_path).

Output

result – rendered template

Example

kube.template.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .deployment }}
  labels:
    app: {{ .app }}
spec:
  replicas: 3
  selector:
    matchLabels:
      app: {{ .app }}
  template:
    metadata:
      labels:
        app: {{ .app }}
    spec:
      containers:
      - name: {{ .app }}
        image: {{ .image }}
        ports:
        - containerPort: 80

.github/workflows/main.yml

name: main
on:
  push:
    branches:
      - main
env:
  DOCKER_IMAGE: username/image
  DEPLOYMENT_NAME: nginx-deployment
jobs:
  main:
    runs-on: ubuntu-latest
    steps:
      ...
      - name: Render template
        id: render_template
        uses: chuhlomin/render-template@v1.5
        with:
          template: kube.template.yml
          vars: |
            image: ${{ env.DOCKER_IMAGE }}:${{ github.sha }}
            deployment: ${{ env.DEPLOYMENT_NAME }}
            app: nginx

      - name: Deploy
        timeout-minutes: 4
        run: |-
          echo '${{ steps.render_template.outputs.result }}' | kubectl apply -f -
          kubectl rollout status deployment/$DEPLOYMENT_NAME