diff --git a/ci/affects-files.sh b/ci/affects-files.sh index 6657266768..5fad922593 100755 --- a/ci/affects-files.sh +++ b/ci/affects-files.sh @@ -3,23 +3,26 @@ # Checks if a CI build affects one or more path patterns. Each command-line # argument is checked in series. # -# Bash regular expresses are permitted in the pattern, and the colon (':') -# character is guaranteed to appear before and after each affected file (and thus -# can be used as an anchor), eg: -# .rs: -- any file or directory ending in .rs -# .rs -- also matches foo.rs.bar -# :snap/ -- anything under the snap/ subdirectory -# snap/ -- also matches foo/snap/ +# Bash regular expressions are permitted in the pattern: +# ./affects-files.sh .rs$ -- any file or directory ending in .rs +# ./affects-files.sh .rs -- also matches foo.rs.bar +# ./affects-files.sh ^snap/ -- anything under the snap/ subdirectory +# ./affects-files.sh snap/ -- also matches foo/snap/ # +set -e +cd "$(dirname "$0")"/.. if ci/is-pr.sh; then affectedFiles="$(buildkite-agent meta-data get affected_files)" echo "Affected files in this PR: $affectedFiles" + IFS=':' read -ra files <<< "$affectedFiles" for pattern in "$@"; do - if [[ ":$affectedFiles:" =~ $pattern ]]; then - exit 0 - fi + for file in "${files[@]}"; do + if [[ $file =~ $pattern ]]; then + exit 0 + fi + done done exit 1 diff --git a/ci/pr-snap.sh b/ci/pr-snap.sh index 41aff8acdf..7d7c0ef262 100755 --- a/ci/pr-snap.sh +++ b/ci/pr-snap.sh @@ -1,12 +1,11 @@ #!/usr/bin/env bash -set -e # # Only run snap.sh for pull requests that modify files under /snap # - +set -e cd "$(dirname "$0")"/.. -ci/affects-files.sh :snap/ || { +ci/affects-files.sh ^snap/ || { echo "Skipping snap build as no files under /snap were modified" exit 0 } diff --git a/ci/test-bench.sh b/ci/test-bench.sh index 908bc60c01..771186716d 100755 --- a/ci/test-bench.sh +++ b/ci/test-bench.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -e - cd "$(dirname "$0")/.." annotate() { @@ -10,10 +9,10 @@ annotate() { } ci/affects-files.sh \ - .rs: \ - ci/test-bench.sh: \ + .rs$ \ + ci/test-bench.sh \ || { - annotate --style info --context coverage-info \ + annotate --style info --context test-bench \ "Bench skipped as no .rs files were modified" exit 0 } diff --git a/ci/test-coverage.sh b/ci/test-coverage.sh index 7545dc41a2..ddf1b3a923 100755 --- a/ci/test-coverage.sh +++ b/ci/test-coverage.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash set -e - cd "$(dirname "$0")/.." annotate() { @@ -10,11 +9,11 @@ annotate() { } ci/affects-files.sh \ - .rs: \ - ci/test-coverage.sh: \ - scripts/coverage.sh: \ + .rs$ \ + ci/test-coverage.sh \ + scripts/coverage.sh \ || { - annotate --style info --context coverage-info \ + annotate --style info --context test-coverage \ "Coverage skipped as no .rs files were modified" exit 0 }