diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-16 10:35:18 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-11-16 10:35:18 +0000 |
commit | 875bae16d0d3c1f026d658ab430878a73e3ac438 (patch) | |
tree | 4e201a08d9bea5276e8a8de5393aaba24b9dbb5c | |
parent | 85ec04eaaa5ac257164a7719c2f0f9fd2c4eda15 (diff) | |
parent | 9bea3c0fbb6c16adcdccf7044583415bda8234c1 (diff) | |
download | gitlab-ce-875bae16d0d3c1f026d658ab430878a73e3ac438.tar.gz |
Merge branch 'allow-to-use-glob-for-ci-changes-detection' into 'master'
Add glob for CI changes detection
See merge request gitlab-org/gitlab-ce!23128
-rw-r--r-- | changelogs/unreleased/added-glob-for-ci-changes-detection.yml | 5 | ||||
-rw-r--r-- | doc/ci/yaml/README.md | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/build/policy/changes.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/ci/build/policy/changes_spec.rb | 12 |
4 files changed, 20 insertions, 1 deletions
diff --git a/changelogs/unreleased/added-glob-for-ci-changes-detection.yml b/changelogs/unreleased/added-glob-for-ci-changes-detection.yml new file mode 100644 index 00000000000..887c6ef0346 --- /dev/null +++ b/changelogs/unreleased/added-glob-for-ci-changes-detection.yml @@ -0,0 +1,5 @@ +--- +title: Added glob for CI changes detection +merge_request: 23128 +author: Kirill Zaitsev +type: added diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index aab5f268ef9..2a667c985da 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -476,6 +476,7 @@ docker build: - Dockerfile - docker/scripts/* - dockerfiles/**/* + - more_scripts/*.{rb,py,sh} ``` 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: - The `Dockerfile` file. - Any of the files inside `docker/scripts/` 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:** There are some caveats when using this feature with new branches and tags. See diff --git a/lib/gitlab/ci/build/policy/changes.rb b/lib/gitlab/ci/build/policy/changes.rb index 7bf51519752..1663c875426 100644 --- a/lib/gitlab/ci/build/policy/changes.rb +++ b/lib/gitlab/ci/build/policy/changes.rb @@ -14,7 +14,7 @@ module Gitlab pipeline.modified_paths.any? do |path| @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 diff --git a/spec/lib/gitlab/ci/build/policy/changes_spec.rb b/spec/lib/gitlab/ci/build/policy/changes_spec.rb index ab401108c84..523d00c1272 100644 --- a/spec/lib/gitlab/ci/build/policy/changes_spec.rb +++ b/spec/lib/gitlab/ci/build/policy/changes_spec.rb @@ -49,6 +49,12 @@ describe Gitlab::Ci::Build::Policy::Changes do expect(policy).to be_satisfied_by(pipeline, seed) 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 policy = described_class.new(%w[some/*.rb]) @@ -61,6 +67,12 @@ describe Gitlab::Ci::Build::Policy::Changes do expect(policy).not_to be_satisfied_by(pipeline, seed) 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 before do pipeline.before_sha = Gitlab::Git::BLANK_SHA |