Coder Social home page Coder Social logo

thdk / is-affected Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 0.0 558 KB

Build optimisation tool to run commands on feature branches only if they affect files matching a given glob.

JavaScript 62.71% TypeScript 36.86% Dockerfile 0.44%
git build-tool build-optimizer nodegit node

is-affected's Introduction

is-affected

Build optimisation tool to run commands on feature branches only if they affect files matching a given glob.

Cloud Build

CLI

Usage: is-affected [options]

runs command only if the git diff since the fork point from master branch contains files matching glob

Options:
  -V, --version           output the version number
  --pattern [pattern...]  provide one or more patterns to check file paths from git diff against
  --repo <repo>           git directory (default: "./")
  --cmd <cmd>             the command to be run if diff matches glob
  --cwd <cwd>             working directory to be used to run command
  --main <mainBranch>     name of the main branch of your repo, used when no --since is provided to find the merge base commit (default: "origin/master")
  --since <since>         commit to diff with
  -h, --help              display help for command

Example

To run npm run build only if the git diff between your current branch head and the base commit on the master branch contains files matching glob app/client/**.

npx is-affected --pattern app/client/** --cmd "npm run build" --cwd "app/client"

Javascript API

const { isAffected, exec } = require("is-affected");

const build = async () => {
	const shouldBuild = await isAffected(
		"app/client/**",
	);

	if (shouldBuild) {
		await exec("npm run build", "app/client");
	}
};

build();

or with options object (using defaults here):

const shouldBuild = await isAffected(
		"app/client/**", // see match patterns below
		{
			repo: "./",
			cmd: "npm run build",
			cwd: process.cwd(),
			mainBranch: "origin/master",
			since: undefined,
		},
	);

Match patterns

A match means that the git diff contains paths that match the pattern and your code is 'affected'.

Negated pattern

You can use a negated pattern: !src/scripts

This will ignore changes in the src/scripts folder. If your diff contains only changes in src/scripts then your code will not be marked as 'affected'.

Multiple patterns

A normal pattern (aka non negated) will add paths to the match list. Negated patterns will remove paths from the list. Your code is 'affected' when the list is not empty after the last pattern has been evaluated.

const shouldBuild = await isAffected([
    	'src/**',
    	'!src/tests/**',
]);

or using cli:

npx is-affected --pattern src/** !src/tests/**

Note that if your shell is automatically expanding glob patterns you should escape the asterix:

npx is-affected --pattern src/\** !src/tests/\**

The above example will monitor all paths in the src folder except for those in the tests subfolder.

is-affected's People

Contributors

thdk avatar

Watchers

 avatar  avatar  avatar

is-affected's Issues

Include dot files

When a file starting with a dot exists in the diff, and the file matches the pattern and if this file is the only changed file, then is-affected should return true.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.