Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 18, 2021. It is now read-only.

GitHub Action that saves time and money in monorepo environments

License

NotificationsYou must be signed in to change notification settings

crossnokaye/has-changed-path

 
 

Repository files navigation

has-changed-path status

This action outputs whether a path or combination of paths has changed in the previous commit.

It solves a common issue among monorepo setups: conditional actions. Deploying a project that did not change in the previous commit could be a waste of time and resources.

With this action,you know if a deployment or any other job needs to run based on the changed paths of the most recent commit.

It differs fromGitHub's paths as our action is meant to be used inside your job steps, not at the root of your workflow file (seethis issue).

My recommendation is to put this action in a workflow that runs on every push tomaster.

Inputs

  • paths (required): Path to detect changes. It's possible to pass one path, a combination or a wildcard. Valid options include:packages/front,packages/front packages/shared,packages/**/tests. See workflow examples below for more information.

Outputs

  • changed: boolean indicating if the paths changed at the latest commit

Example workflows

Important info:

Notice thatyou must configurefetch-depth in youractions/checkout@v2. That's because their default option now is to fetch only the latest commit instead of all history (more info)

If you want to fetch all history, passfetch-depth: 0.

For monorepo packages, where history tends to be larger than single repos, it may take a while fetching all of it. That's why we usedfetch-depth: 100 in the examples. It will fetch the latest 100 commits.

Detecting a simple one-path change:

name:Conditional Deployon:pushjobs:build:runs-on:ubuntu-lateststeps:      -uses:actions/checkout@v2with:fetch-depth:100      -uses:marceloprado/has-changed-path@v2id:changed-frontwith:paths:packages/front      -name:Deploy frontif:steps.changed-front.outputs.changed == 'true'run:/deploy-front.sh

Detecting changes in multiple paths:

Useful when you have dependencies between packages (eg./common package used in/front and/server).Below, the output would be truthy for any given change insidepackages/frontorpackages/common.

name:Conditional Deployon:pushjobs:build:runs-on:ubuntu-lateststeps:      -uses:actions/checkout@v2with:fetch-depth:100      -uses:marceloprado/has-changed-path@v2id:changed-frontwith:paths:packages/front packages/common      -name:Deploy frontif:steps.changed-front.outputs.changed == 'true'run:/deploy-front.sh

Detecting a one-path change with checkout multiple repos:

name:Conditional Deployon:pushjobs:build:runs-on:ubuntu-lateststeps:      -uses:actions/checkout@v2with:fetch-depth:100path:main      -uses:actions/checkout@v2with:fetch-depth:100repsitory:my-org/my-toolspath:my-tools      -uses:marceloprado/has-changed-path@v2id:changed-mainwith:paths:packages/frontenv:SOURCE:main      -uses:marceloprado/has-changed-path@v2id:changed-my-toolswith:paths:somewhere/elseenv:SOURCE:my-tools      -name:Deploy mainif:steps.changed-main.outputs.changed == 'true'run:/deploy-main.sh      -name:Deploy my toolsif:steps.changed-my-tools.outputs.changed == 'true'run:/deploy-my-tools.sh

How it works?

The action itself is pretty simple - take a look atsrc/hasChanged.js ;) .

Basically, we compare the latest HEAD with the previous one usinggit diff command. This allows us to effectively detect changes in most cases (squashed merges and merges with merge commit).

The algorithm works very similar withNetlify's default way for detecting changes in monorepo builds.

Contribute

Have any thoughts or suggestions? Please, open an issue and I'll be happy to improve this action!

About

GitHub Action that saves time and money in monorepo environments

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript100.0%

[8]ページ先頭

©2009-2025 Movatter.jp