2018-12-18 17:33:28 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
#
|
|
|
|
# Checks if a CI build affects one or more path patterns. Each command-line
|
|
|
|
# argument is checked in series.
|
|
|
|
#
|
2018-12-18 17:33:28 -08:00
|
|
|
# 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/
|
2018-12-18 17:33:28 -08:00
|
|
|
#
|
2018-12-18 17:33:28 -08:00
|
|
|
set -e
|
|
|
|
cd "$(dirname "$0")"/..
|
2018-12-18 17:33:28 -08:00
|
|
|
|
2019-06-06 12:20:47 -07:00
|
|
|
if [[ -n $CI_PULL_REQUEST ]]; then
|
2018-12-18 17:33:28 -08:00
|
|
|
affectedFiles="$(buildkite-agent meta-data get affected_files)"
|
|
|
|
echo "Affected files in this PR: $affectedFiles"
|
|
|
|
|
2018-12-18 17:33:28 -08:00
|
|
|
IFS=':' read -ra files <<< "$affectedFiles"
|
2018-12-18 17:33:28 -08:00
|
|
|
for pattern in "$@"; do
|
2018-12-18 17:33:28 -08:00
|
|
|
for file in "${files[@]}"; do
|
|
|
|
if [[ $file =~ $pattern ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
2018-12-18 17:33:28 -08:00
|
|
|
done
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# affected_files metadata is not currently available for non-PR builds, so assume
|
|
|
|
# the worse (affected)
|
|
|
|
exit 0
|