All Projects â†’ hkdobrev â†’ run-if-changed

hkdobrev / run-if-changed

Licence: MIT license
Run a command if a file changes via Git hooks

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to run-if-changed

Slimjim
SlimJim is a simple auto update script utilizing Slim (a PHP micro-framework), incron (inotify cron system), and GitHub/BitBucket post-receive-hook
Stars: ✭ 98 (+292%)
Mutual labels:  git-hooks
Husky.Net
Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
Stars: ✭ 394 (+1476%)
Mutual labels:  git-hooks
prepare-commit-msg
Automatically prefix commit messages with the current branch issue number
Stars: ✭ 28 (+12%)
Mutual labels:  git-hooks
Wp Enforcer
Git hooks to encourage well-written WordPress.
Stars: ✭ 107 (+328%)
Mutual labels:  git-hooks
Simple Git Hooks
A simple git hooks manager for small projects
Stars: ✭ 179 (+616%)
Mutual labels:  git-hooks
commithelper
A tool to create and lint commit messages
Stars: ✭ 35 (+40%)
Mutual labels:  git-hooks
Talisman
By hooking into the pre-push hook provided by Git, Talisman validates the outgoing changeset for things that look suspicious - such as authorization tokens and private keys.
Stars: ✭ 1,155 (+4520%)
Mutual labels:  git-hooks
pre-commit-opa
Pre-commit git hooks for Open Policy Agent (OPA) and Rego development
Stars: ✭ 53 (+112%)
Mutual labels:  git-hooks
git-open-pull
convert a github issue into a pull request
Stars: ✭ 51 (+104%)
Mutual labels:  git-workflow
git-remind
Never forget to git commit and push
Stars: ✭ 86 (+244%)
Mutual labels:  git-workflow
Git Good Commit
Git hook to help you write good commit messages, with no external dependencies.
Stars: ✭ 128 (+412%)
Mutual labels:  git-hooks
Yarnhook
Run `yarn install`, `npm install` or `pnpm install` on git hooks automatically
Stars: ✭ 177 (+608%)
Mutual labels:  git-hooks
pre-commit-hooks-safety
A pre-commit hook to check your Python dependencies against safety-db
Stars: ✭ 69 (+176%)
Mutual labels:  git-hooks
Git Guppy
Simple git-hook integration for your gulp workflows.
Stars: ✭ 105 (+320%)
Mutual labels:  git-hooks
captain-git-hook
✅ define git hooks as scripts in your package.json
Stars: ✭ 25 (+0%)
Mutual labels:  git-hooks
Php Backslasher
[Git hook] Tool to add all PHP internal functions and constants to its namespace by adding backslash to them.
Stars: ✭ 79 (+216%)
Mutual labels:  git-hooks
k8s-security-configwatch
Git action to generate security lint report for Kubernetes workload YAML files on PR
Stars: ✭ 27 (+8%)
Mutual labels:  git-workflow
pre-commit-hooks
git pre-commit hooks
Stars: ✭ 71 (+184%)
Mutual labels:  git-hooks
git-workflow-zh
如何安全地使用 Git 的指导方案
Stars: ✭ 85 (+240%)
Mutual labels:  git-workflow
precommit-hook
Automatically check your python code on every commit. 🔍 ✔️
Stars: ✭ 16 (-36%)
Mutual labels:  git-hooks

🔃 run-if-changed Build Status npm version

Run a command if a file changes via Git hooks. Useful for lock files or build systems to keep dependencies and generated files up to date when changing branches, pulling or commiting.

Inspired by lint-staged and recommended to be used with husky.

State of the project

run-if-changed is functional as-is, but it's still quite basic and rough as it has just been published. So issues, feature requests and pull requests are most welcome!

Installation and setup

In package.json:

"husky": {
    "hooks": {
        "post-commit": "run-if-changed",
        "post-checkout": "run-if-changed",
        "post-merge": "run-if-changed",
        "post-rewrite": "run-if-changed"
    }
}

Install with Yarn:

yarn add --save-dev husky @hkdobrev/run-if-changed
Recommended setup:
"run-if-changed": {
    "yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
}

Install with npm:

npm install --save-dev husky @hkdobrev/run-if-changed
Recommended setup:
"run-if-changed": {
    "package-lock.json": "npm install --prefer-offline --no-audit"
}

Why

The use case for run-if-changed is mostly for a team working on a project and push and pull code in different branches. When you share dependencies, database migrations or compilable code in the shared Git repository often some commands need to be run when a file or folder gets updated.

Check out the common use cases.

Configuration

  • run-if-changed object in your package.json
  • .run-if-changedrc file in JSON or YML format
  • run-if-changed.config.js file in JS format

See cosmiconfig for more details on what formats are supported.

Configuration should be an object where each key is a file or directory match pattern and the value is either a single command or an array of commands to run if the file have changed since the last Git operation.

What commands are supported?

Supported are any executables installed locally or globally via npm or Yarn as well as any executable from your $PATH.

Using globally installed scripts is discouraged, since run-if-changed may not work for someone who doesn't have it installed.

run-if-changed is using npm-which to locate locally installed scripts. So in your .run-if-changedrc you can write:

{
  "src": "webpack"
}

Sequences of commands are supported. Pass an array of commands instead of a single one and they will run sequentially.

Use cases

Install or update dependencies when lock file changes

If you use a dependency manager with a lock file like npm, Yarn, Composer, Bundler or others, you would usually add a dependency and the dependency manager would install it and add it to the lock file in a single run. However, when someone else has updated a dependency and you pull new code or checkout their branch you need to manually run the install command of your dependency manager.

Here's example configuration of run-if-changed:

When using Yarn:

package.json:

{
    "run-if-changed": {
        "yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
    }
}

.run-if-changedrc:

{
    "yarn.lock": "yarn install --prefer-offline --pure-lockfile --color=always"
}
When using npm:

package.json:

{
    "run-if-changed": {
        "package-lock.json": "npm install --prefer-offline --no-audit"
    }
}

.run-if-changedrc:

{
    "package-lock.json": "npm install --prefer-offline --no-audit"
}
When using Composer:

package.json:

{
    "run-if-changed": {
        "composer.lock": "composer install --ignore-platform-reqs --ansi"
    }
}
When using Bundler:

package.json:

{
    "run-if-changed": {
        "Gemfile.lock": "bundle install"
    }
}

Run database migrations if there are new migrations

If you keep database migrations in your repository, you'd usually want to run them when you check out a branch or pull from master.

package.json:

{
    "run-if-changed": {
        "migrations": "./console db:migrate --allow-no-migration --no-interaction"
    }
}

The above example assumes PHP Doctrine migrations.

Compile sources in a build folder after pulling new code.

package.json:

{
    "run-if-changed": {
        "src": "yarn build"
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].