GitHub Action
templ-generator-action
v1
Latest version
This GitHub Action is designed for projects using the templ
templating language.
The templ-generator-action
streamlines the process of code generation by automating the conversion of .templ
files into Go source code,
ensuring that your project's templated code is always up-to-date with your templates.
To use the templ-generator-action
in your workflow, follow these steps:
- Set the
contents-permission
of the defaultGITHUB_TOKEN
towrite
. This is required to commit new changes to the repository. - Add the
templ-generator-action
step in your job, after other steps that might modify.templ
files.
Here's an example workflow configuration:
name: Generate templ Code
on: push
jobs:
generate-templ-code:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the
# added or changed files to the repository.
contents: write
steps:
- uses: actions/checkout@v4
# Format, generate and commit all changed .templ and generated .go files back to the repository
- name: Generate templ code
uses: capthiron/templ-generator-action@v1
Note
The Action has to be used in a Job that runs on a UNIX system (e.g. ubuntu-latest
).
The following is an extended example with all available options.
- name: Generate templ code
uses: capthiron/templ-generator-action@v1
with:
# Optional: The directory where to look for .templ files.
# Default is "."
directory: "templates"
# Optional: Flag to enable or disable committing changes.
# Default is "true"
commit: "false"
# Optional: Custom commit message for the generated code.
# Default is "chore: Generate templ code"
commit-message: "chore: Generate templ code from .templ files"
# Optional: Flag to enable or disable formatting the generated code.
# Default is "true"
format: "false"
# Optional: Flag to enable or disable setting up Go.
# If set to "false", the action requires Go to be already installed.
# Default is "true"
setup-go: "true"
# Optional: The Go version to use.
# Default is "stable"
go-version: "1.22" # Replace with your desired Go version
# Optional: The templ version to use.
# Default is "latest"
templ-version: "v0.2.543" # Replace with your desired templ version
For more details on inputs, see the action.yml file in this repository.
This project is licensed under the MIT License - see the LICENSE file for details.