Skip to content

Commit

Permalink
Release v1.0.0 (#9)
Browse files Browse the repository at this point in the history
Created by RobertDeRose

Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and github-actions[bot] authored Nov 17, 2024
1 parent 64f1649 commit f39d170
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- id: esh-template-check
name: ESH Template Check
description: Pre-processes ESH templates, renders them with test cases, and runs optional shellcheck.
language: docker_image
entry: docker.io/robertderose/esh-template-check:v1.0.0
files: \.esh$
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# ESH Template Check Pre-Commit Hook

This pre-commit hook processes [`esh`](https://github.com/jirutka/esh) templates, renders them with test cases specified
in `YAML` front matter, and optionally runs [`shellcheck`](https://github.com/koalaman/shellcheck) on the generated
files.

## Features

- Parses YAML front matter to extract test cases and `shellcheck` arguments.
- Preprocesses ESH templates for each test case.
- Runs `shellcheck` with specified arguments, if provided.

## Setup

To use this hook in your repository:

1. Add this repo to your `.pre-commit-config.yaml`:

```yaml
- repo: https://github.com/RobertDeRose/esh-template-check
rev: v1.0.0
hooks:
- id: esh-template-check
```
### Supported Arguments
- **-k**
- Keep the generated output after running. Stores generated output in `esh_template_output`
- If you enable keeping the output, it is recommended add the above directory to your `.gitignore` file
- **-v**
- Enable verbose output when an error occurs
- **-s=SHELL**
- Override the Shell that ESH will use, by default uses Bash

### Supported Front Matter

- **check_args**
- This should be a string that will be passed in as the arguments to shellcheck
- **test_cases**
- This is an array of key/value pairs to be set as variables for the **template**

## Example Template

```bash
#!/bin/bash
<%# --- -%>
<%# check_args: -s bash -%>
<%# test_cases: -%>
<%# - VAR1: one -%>
<%# VAR2: two -%>
<%# - VAR1: a -%>
<%# VAR2: b -%>
<%# - VAR1: 1 -%>
<%# VAR2: 2 -%>
<%# --- -%>
<% if [[ "${VAR1}" =~ ^(one|a)$ ]]; then -%>
<%= "# Generating script for ${VAR2}" %>
hello_world() {
local name
<% if [[ "${VAR1}" == "one" ]]; then %>
name="Rob"
<% elif [[ "${VAR1}" == "a" ]]; then %>
name="Bob"
<% fi %>
echo "Hello ${name} you got ${VAR2}"
}
```

0 comments on commit f39d170

Please sign in to comment.