diff --git a/ci/affects-files.sh b/ci/affects-files.sh new file mode 100755 index 0000000000..6657266768 --- /dev/null +++ b/ci/affects-files.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# +# 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/ +# + +if ci/is-pr.sh; then + affectedFiles="$(buildkite-agent meta-data get affected_files)" + echo "Affected files in this PR: $affectedFiles" + + for pattern in "$@"; do + if [[ ":$affectedFiles:" =~ $pattern ]]; then + exit 0 + fi + done + + exit 1 +fi + +# affected_files metadata is not currently available for non-PR builds, so assume +# the worse (affected) +exit 0 diff --git a/ci/buildkite.yml b/ci/buildkite.yml index 9f49916848..1b9986c9a4 100644 --- a/ci/buildkite.yml +++ b/ci/buildkite.yml @@ -29,6 +29,7 @@ steps: - command: "ci/pr-snap.sh" timeout_in_minutes: 20 name: "snap" + branches: "pull/*" - wait - trigger: "solana-secondary" branches: "!pull/*" diff --git a/ci/pr-snap.sh b/ci/pr-snap.sh index 116c8ed9fd..41aff8acdf 100755 --- a/ci/pr-snap.sh +++ b/ci/pr-snap.sh @@ -4,16 +4,11 @@ set -e # Only run snap.sh for pull requests that modify files under /snap # -cd "$(dirname "$0")" +cd "$(dirname "$0")"/.. -if ./is-pr.sh; then - affected_files="$(buildkite-agent meta-data get affected_files)" - echo "Affected files in this PR: $affected_files" - if [[ ! ":$affected_files:" =~ :snap/ ]]; then - echo "Skipping snap build as no files under /snap were modified" - exit 0 - fi - exec ./snap.sh -else - echo "Skipping snap build as this is not a pull request" -fi +ci/affects-files.sh :snap/ || { + echo "Skipping snap build as no files under /snap were modified" + exit 0 +} + +exec ci/snap.sh diff --git a/ci/test-coverage.sh b/ci/test-coverage.sh index b3cf53868d..7545dc41a2 100755 --- a/ci/test-coverage.sh +++ b/ci/test-coverage.sh @@ -9,15 +9,15 @@ annotate() { } } -if ci/is-pr.sh; then - affectedFiles="$(buildkite-agent meta-data get affected_files)" - echo "Affected files in this PR: $affectedFiles" - if [[ ! ":$affectedFiles:" =~ \.rs: ]]; then - annotate --style info --context coverage-info \ - "Coverage skipped as no .rs files were modified" - exit 0 - fi -fi +ci/affects-files.sh \ + .rs: \ + ci/test-coverage.sh: \ + scripts/coverage.sh: \ +|| { + annotate --style info --context coverage-info \ + "Coverage skipped as no .rs files were modified" + exit 0 +} source ci/upload-ci-artifact.sh ci/version-check-with-upgrade.sh nightly