Skip to content

Commit

Permalink
Add samplr pre-commit hook and script
Browse files Browse the repository at this point in the history
  • Loading branch information
thamudi committed Nov 8, 2023
1 parent b819619 commit c013682
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
entry: ./scripts/validate-eslint.sh
language: script
stages: [commit]
- id: run-samplr
name: Runs the command line samplr to generate sample files
description: "A script to generate sample files."
entry: ./scripts/samplr/run-samplr.sh
language: script
stages: [commit]
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This repository contains JOSA's custom pre-commit hooks.
- [Validate Flux](#validate-flux) - A script to validate Flux custom resources and Kustomize overlays.
- [Validate Eslint](#validate-eslint) - A script to validate eslint rules on Javascript and Typescript files.

- [Run Samplr](#run-samplr) - A script to generate sample files.

___

## validate-flux
Expand Down Expand Up @@ -78,3 +80,33 @@ pre-commit install -t pre-commit
```

___

## run-samplr

This script runs the command [samplr](https://github.com/unmultimedio/samplr) to generate `.sample` files in your repo. Please refer to the [config](./scripts/samplr/.samplr.yml) in this repo to understand which files are supported.

### Prerequisites

You need the following to be installed on your machine before running this pre-commit script.

- [samplr v0.2.1](https://github.com/unmultimedio/samplr/releases/tag/v0.2.1)

### Usage

Add this to your .pre-commit-config.yaml:

```yaml
- repo: https://github.com/jordanopensource/pre-commit-hooks
rev: v0.1.0 # Use the ref you want to point at
hooks:
- id: run-samplr
# - id: ...
```

After the configuration is added, you'll need to run

```bash
pre-commit install -t pre-push
```

___
20 changes: 20 additions & 0 deletions scripts/samplr/.samplr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
######################
# samplr configuration
######################

# Want to include a header that indicates this is an autogenerated file?
autogencomments: true

# regex matches for filenames that you want to include or exclude from
# the samplr generation. Be careful to indent using spaces.
# For a file to be sampled, it has to meet both requirements: be included and not excluded.
excludes:
- \.sample # It's a good idea to exclude all *.sample* files, otherwise it will behave recursively
- \.go$ # Most of the times, the code files won't need samples
- ^vendor # Dependencies shouldn't be sampled
- ^node-modules # Dependencies shouldn't be sampled
includes:
- ^config # Matches files like ./config/setup.yml or ./configuration/script.sh
- \.yml$ # Matches all .yml files in the project
- Dockerfile # Matches all Dockerfile in the project
- .env # Matches all env files in the project
25 changes: 25 additions & 0 deletions scripts/samplr/run-samplr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

###############################
########### CREDITS: ##########
# https://github.com/unmultimedio/samplr#5-set-up-a-githook-optional
########## MODIFIED: ##########
# t.hamoudi
######### MAINTAINED: #########
# [email protected]
###############################

###############################
# Prerequisites
# - samplr v0.2.1
###############################
###### INSTALLATION GUIDE #####
# https://github.com/unmultimedio/samplr/blob/master/INSTALL.md
###############################

set -e

# Run samplr command to generate sample files
samplr
# List all changed and not-ignored files, with a filename that matches with ".sample", and add it to the commit
git ls-files -mo --exclude-standard | grep "\.sample" | xargs git add

0 comments on commit c013682

Please sign in to comment.