diff --git a/.goreleaser.yml b/.goreleaser.yml index 67d11ea4..b1b279fd 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -9,15 +9,15 @@ builds: - darwin - windows archive: - # replacements: - # windows: Windows - # darwin: MacOS - # linux: Linux - # 386: i386 - # amd64: x86_64 - # format_overrides: - # - goos: windows - # format: zip + replacements: + windows: Windows + darwin: MacOS + linux: Linux + 386: i386 + amd64: x86_64 + format_overrides: + - goos: windows + format: zip checksum: name_template: '{{ .ProjectName }}_checksums.txt' snapshot: diff --git a/.npm/README.md b/.npm/README.md new file mode 100644 index 00000000..f744d2af --- /dev/null +++ b/.npm/README.md @@ -0,0 +1,265 @@ +![Build Status](https://api.travis-ci.org/Arkweid/hookah.svg?branch=master) + +# Hookah + +Hookah it`s a simple manager of git hooks. + + +Sponsored by Evil Martians + +[![asciicast](https://asciinema.org/a/rupBzaCqin2n3qGlNFM9Agm7f.svg)](https://asciinema.org/a/rupBzaCqin2n3qGlNFM9Agm7f) + +## Installation + +Add Hookah to your system or build it from sources. + +### go +```bash +go get github.com/Arkweid/hookah +``` + +### npm and yarn +```bash +npm i @arkweid/hookah-js --save-dev +# or yarn: +yarn add -D @arkweid/hookah-js + +# Now you can call it: +npx hookah -h +``` +NOTE: if you install it this way you should call it with `npx` for all listed examples below. + +### snap +```bash +sudo snap install --devmode hookah +``` + +### brew +```bash +brew install Arkweid/hookah/hookah +``` + +Or take it from [binaries](https://github.com/Arkweid/hookah/releases) and install manualy + +## Scenarios + +### First time user + +Go to your project directory and run: + + +```bash +hookah install +``` + +It add for you configuration file `hookah.yml` with default directories for hooks sources. +Now we ready to add hooks! For example we want to add pre commit hooks. Lets do that: + + +```bash +hookah add pre-commit +``` + +It will add a hook `.git/hooks/pre-commit`. So every time when you run `git commit` this file will be executed. +That directories also will be created `.hookah` and `.hookah-local`. +Use first one for project/team hooks. Second one for you personal hooks. Add it to `.gitignore` + +Next fill the directory `.hookah/pre-commit` with executables you like + +``` +├───.hookah +│ └───pre-commit +│ ├─── fail_script +│ └─── ok_script +``` + +Example: +```bash +cat > .hookah/pre-commit/fail_script + +#!/bin/sh +exit 1 + +cat > .hookah/pre-commit/ok_script + +#!/bin/sh +exit 0 + +# Now we can commit: +git commit -am "It fail" +``` + +Done! Pretty simple, huh? + +### Complete example +`hookah.yml` +```yml +pre-commit: + commands: + eslint: + glob: "*.{js,ts}" + runner: yarn eslint {staged_files} # hookah run it like "yarn eslint App.js Model.js ..." + rubocop: + tags: backend style + glob: "*.{rb}" + exclude: "application.rb|routes.rb" # simple regexp for more flexibility + runner: bundle exec rubocop {all_files} + govet: + tags: backend style + files: git ls-files -m # we can explicity define scope of files + glob: "*.{go}" + runner: go vet {files} # {files} will be replaced by matched files as arguments + + # If you have script files, you can specify parameters for them + scripts: + "hello.js": + runner: node # hookah run it like "node hello.js" + "any.go": + runner: go run # hookah run it like "go run any.go" + + # Not enough speed? Run all of them in parallel! + # Default: false + parallel: true +``` +If your team have backend and frontend developers, you can skip unnsecesary hooks this way: +`hookah-local.yml` +```yml +pre-commit: + # I am fronted developer. Skip all this backend stuff! + exclude_tags: + - backend + + scripts: + "any.go": + runner: docker exec -it --rm {cmd} # Wrap command from hookah.yml in docker + commands: + govet: + skip: true # You can also skip command with this option +``` + +### I want to run hook groups directly! + +No problem, hookah have command for that: + +```bash +hookah run pre-commit + +# You will see the summary: +[ FAIL ] fail_script +[ OK ] ok_script +``` + +### I want to use my own runner! And I dont want to change team/repository scripts. + +Ok! For example you have `any.go` script. We can run it in this way: + +Add `hookah-local.yml` + +Add it to `.gitignore`. It your personal settings. + +Next customize the `any.go` script: + +```yaml +pre-commit: + "any.go": + runner: "go run" +``` + +Done! Now our script will be executed like this: +```bash +go run any.go +``` + +### I clone the existed repo which use hookah. How can I setup hooks? + +We suppose repo already have the hookah structure. So all of you need it run install: + +```bash +hookah install +``` +Hookah wiil read existed hook groups and reproduce hooks in `.git/hooks` directory. + +### How can I can skip hoookah execution? + +We have env HOOKAH=0 for that + +```bash +HOOKAH=0 git commit -am "Hookah skipped" +``` + +### How can I can skip some tags on the fly? + +We have env HOOKAH_EXCLUDE=tag,tag for that + +```bash +HOOKAH_EXCLUDE=ruby,security git commit -am "Skip some tag checks" +``` + +### How can I run my linter against only modified files? + +No problem. Lets take `rubocop` linter for ruby as example: + +```bash +#!/bin/sh + +git ls-files -m | xargs rubocop +``` + +### I dont like bash. Give me working example for golang + +Ok-ok! This is how `any.go` may looks like: + +```go +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" + + "github.com/Arkweid/hookah/context" +) + +func main() { + files, _ := context.StagedFiles() + files = context.FilterByExt(files, ".rb") + + cmd := exec.Command("rubocop", strings.Join(files, " ")) + + outputBytes, err := cmd.CombinedOutput() + + fmt.Println(string(outputBytes)) + + if err != nil { + os.Exit(1) + } +} +``` +We include context package only for convenience. It`s just few useful functions. + +### Some hooks proved ARGS from git. How can I capture it in my script? +For pure script you can do it like that: + +Example for `prepare-commit-msg` hook: +```bash +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +# ... +``` + +### Can I change directory for script files? +Yes. You can do this through this config keys: +`hookah.yml` +```yml +source_dir: ".hookah" +source_dir_local: ".hookah-local" +``` + +### Uninstall + +```bash +hookah uninstall +``` \ No newline at end of file diff --git a/.npm/bin/hookah-linux b/.npm/bin/hookah-linux new file mode 100755 index 00000000..cd8a0bad Binary files /dev/null and b/.npm/bin/hookah-linux differ diff --git a/.npm/bin/hookah-mac b/.npm/bin/hookah-mac new file mode 100755 index 00000000..6e61ef10 Binary files /dev/null and b/.npm/bin/hookah-mac differ diff --git a/.npm/bin/hookah-win.exe b/.npm/bin/hookah-win.exe new file mode 100755 index 00000000..896ac7d5 Binary files /dev/null and b/.npm/bin/hookah-win.exe differ diff --git a/.npm/bin/index.js b/.npm/bin/index.js new file mode 100755 index 00000000..fea01c47 --- /dev/null +++ b/.npm/bin/index.js @@ -0,0 +1,30 @@ +#!/usr/bin/env node + +var spawn = require('child_process').spawn; +var path = require('path'); + +var command_args = process.argv.slice(2); + +function spawnCommand(binaryExecutable) { + var child = spawn( + path.join(__dirname, binaryExecutable), + command_args, + { stdio: [process.stdin, process.stdout, process.stderr] }); + + child.on('close', function (code) { + if (code !== 0) { + process.exit(1); + } + }); +} + +if (process.platform === 'darwin') { + spawnCommand('hookah-mac'); +} else if (process.platform === 'linux') { + spawnCommand('hookah-linux'); +} else if (process.platform === 'win32') { + spawnCommand('hookah-win.exe'); +} else { + console.log("Unsupported OS"); + process.exit(1); +} diff --git a/.npm/package.json b/.npm/package.json new file mode 100644 index 00000000..b567a450 --- /dev/null +++ b/.npm/package.json @@ -0,0 +1,26 @@ +{ + "name": "@arkweid/hookah-js", + "version": "0.2.1", + "description": "Simple git hooks manager", + "main": "index.js", + "bin": { + "hookah": "./bin/index.js" + }, + "repository": "https://github.com/Arkweid/hookah", + "keywords": [ + "git", + "hook", + "manager" + ], + "author": "Arkweid", + "license": "MIT", + "bugs": { + "url": "https://github.com/Arkweid/hookah-js/issues" + }, + "homepage": "https://github.com/Arkweid/hookah-js#readme", + "os": [ + "darwin", + "linux", + "win32" + ] +} diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 10b1db6c..00000000 --- a/.npmignore +++ /dev/null @@ -1,19 +0,0 @@ -.vscode/ -.hookah-local/ -.hookah/ -/hookah-local.yml -/hookah.yml -hookah - -tmp/ -dist/ -cmd/ -context/ -spec/ -.goreleaser.yml -.travis.yml -Gemfile -Gemfile.lock -go.mod -go.sum -main.go diff --git a/package.json b/package.json deleted file mode 100644 index c7909cfb..00000000 --- a/package.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "name": "@arkweid/hookah-js", - "version": "0.2.0", - "description": "Simple git hooks manager", - "repository": "https://github.com/Arkweid/hookah", - "keywords": [ - "git", - "hook", - "manager" - ], - "author": "Arkweid", - "license": "MIT", - "bugs": { - "url": "https://github.com/Arkweid/hookah/issues" - }, - "homepage": "https://github.com/Arkweid/hookah#readme", - "os": [ - "darwin", - "linux", - "win32" - ], - "scripts": { - "postinstall": "go-npm install", - "preuninstall": "go-npm uninstall" - }, - "goBinary": { - "name": "hookah", - "path": "./bin", - "url": "https://github.com/Arkweid/hookah/releases/download/v{{version}}/hookah_{{version}}_{{platform}}_{{arch}}.tar.gz" - }, - "dependencies": { - "go-npm": "^0.1.9" - } -}