Commit 9bea3c0f authored by Kirill Zaitsev's avatar Kirill Zaitsev

Add glob for CI changes detection

parent 97e3d5ce
---
title: Added glob for CI changes detection
merge_request: 23128
author: Kirill Zaitsev
type: added
...@@ -476,6 +476,7 @@ docker build: ...@@ -476,6 +476,7 @@ docker build:
- Dockerfile - Dockerfile
- docker/scripts/* - docker/scripts/*
- dockerfiles/**/* - dockerfiles/**/*
- more_scripts/*.{rb,py,sh}
``` ```
In the scenario above, if you are pushing multiple commits to GitLab to an In the scenario above, if you are pushing multiple commits to GitLab to an
...@@ -485,6 +486,7 @@ one of the commits contains changes to either: ...@@ -485,6 +486,7 @@ one of the commits contains changes to either:
- The `Dockerfile` file. - The `Dockerfile` file.
- Any of the files inside `docker/scripts/` directory. - Any of the files inside `docker/scripts/` directory.
- Any of the files and subfolders inside `dockerfiles` directory. - Any of the files and subfolders inside `dockerfiles` directory.
- Any of the files with `rb`, `py`, `sh` extensions inside `more_scripts` directory.
CAUTION: **Warning:** CAUTION: **Warning:**
There are some caveats when using this feature with new branches and tags. See There are some caveats when using this feature with new branches and tags. See
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
pipeline.modified_paths.any? do |path| pipeline.modified_paths.any? do |path|
@globs.any? do |glob| @globs.any? do |glob|
File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH) File.fnmatch?(glob, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB)
end end
end end
end end
......
...@@ -49,6 +49,12 @@ describe Gitlab::Ci::Build::Policy::Changes do ...@@ -49,6 +49,12 @@ describe Gitlab::Ci::Build::Policy::Changes do
expect(policy).to be_satisfied_by(pipeline, seed) expect(policy).to be_satisfied_by(pipeline, seed)
end end
it 'is satisfied by matching a pattern with a glob' do
policy = described_class.new(%w[some/**/*.{rb,txt}])
expect(policy).to be_satisfied_by(pipeline, seed)
end
it 'is not satisfied when pattern does not match path' do it 'is not satisfied when pattern does not match path' do
policy = described_class.new(%w[some/*.rb]) policy = described_class.new(%w[some/*.rb])
...@@ -61,6 +67,12 @@ describe Gitlab::Ci::Build::Policy::Changes do ...@@ -61,6 +67,12 @@ describe Gitlab::Ci::Build::Policy::Changes do
expect(policy).not_to be_satisfied_by(pipeline, seed) expect(policy).not_to be_satisfied_by(pipeline, seed)
end end
it 'is not satified when pattern with glob does not match' do
policy = described_class.new(%w[invalid/*.{md,rake}])
expect(policy).not_to be_satisfied_by(pipeline, seed)
end
context 'when pipelines does not run for a branch update' do context 'when pipelines does not run for a branch update' do
before do before do
pipeline.before_sha = Gitlab::Git::BLANK_SHA pipeline.before_sha = Gitlab::Git::BLANK_SHA
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment