From c01368268ca1cc66fd2611ff0ffc4dbd7c98457b Mon Sep 17 00:00:00 2001 From: thamudi Date: Wed, 8 Nov 2023 18:01:01 +0300 Subject: [PATCH] Add samplr pre-commit hook and script --- .pre-commit-hooks.yaml | 6 ++++++ README.md | 32 ++++++++++++++++++++++++++++++++ scripts/samplr/.samplr.yml | 20 ++++++++++++++++++++ scripts/samplr/run-samplr.sh | 25 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 scripts/samplr/.samplr.yml create mode 100755 scripts/samplr/run-samplr.sh diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index 119a44c..6d0f877 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -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] diff --git a/README.md b/README.md index 0123faf..07d8586 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 +``` + +___ diff --git a/scripts/samplr/.samplr.yml b/scripts/samplr/.samplr.yml new file mode 100644 index 0000000..9fab9f8 --- /dev/null +++ b/scripts/samplr/.samplr.yml @@ -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 \ No newline at end of file diff --git a/scripts/samplr/run-samplr.sh b/scripts/samplr/run-samplr.sh new file mode 100755 index 0000000..5ebda4d --- /dev/null +++ b/scripts/samplr/run-samplr.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +############################### +########### CREDITS: ########## +# https://github.com/unmultimedio/samplr#5-set-up-a-githook-optional +########## MODIFIED: ########## +# t.hamoudi +######### MAINTAINED: ######### +# admin@josa.ngo +############################### + +############################### +# 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