render-template

command module
v0.0.0-...-4d7d51a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

README

GitHub Render Template Action

The current version in this repo was based off of render-template commit 0ca0022 (newer than version 1.8)

The chuhlomin/render-template code is licensed under the Apache License 2.0:

A permissive license whose main conditions require preservation of copyright and license notices. Contributors provide an express grant of patent rights. Licensed works, modifications, and larger works may be distributed under different terms and without source code.

Render Template

repo badges are here [`!`[main]`(https://github.com/rwaight/actions/actions/workflows/main.yml/badge.svg)](https://github.com/rwaight/actions/actions/workflows/main.yml)` [`!`[release]`(https://github.com/rwaight/actions/actions/workflows/release.yml/badge.svg)](https://github.com/rwaight/actions/actions/workflows/release.yml)` [`!`[DockerHub]`(https://img.shields.io/badge/docker-hub-4988CC)](https://hub.docker.com/repository/docker/chuhlomin/render-template)`

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

Inputs

Name Description Required
template Path to template true
vars Variables to use in template (in YAML format) false
vars_path Path to YAML file with variables false
result_path Desired path to result file false
timezone Timezone to use in date template function false

You must set at least vars or vars_path.
You may set both of them (vars values will precede over vars_path).

Variables names must be alphanumeric strings (must not contain any hyphens).

There are few template functions available:

  • date – formats timestamp using Go's time layout.
    Example: {{ "2023-05-11T01:42:04Z" | date "2006-01-02" }} will be rendered as 2023-05-11.
    You may use timezone input to set timezone for date function (e.g. timezone: "America/New_York").

  • mdlink – creates markdown link.
    Example: {{ "https://github.com" | mdlink "GitHub" }} will be rendered as [GitHub](https://github.com).

  • number – formats number in English locale.
    Example: {{ 1234567890 | number }} will be rendered as 1,234,567,890.

  • base64 – encodes string to base64.
    Example: {{ "hello" | base64 }} will be rendered as aGVsbG8=.

Outputs

Name Description
result Rendered file content

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: Checkout
        uses: actions/checkout@v4

      <...>

      - name: Render template
        id: render_template
        uses: rwaight/actions/utilities/render-template@v1
        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

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL