Repository: Automattic/pocket-casts-ios
File: .buildkite/commands/should-skip-job.sh (Shell)

Code before:
  "*.po"
  "*.pot"
  "*.txt"
  ".gitignore"
  "config/Version.xcconfig"
  "fastlane/**"
  "Gemfile"
  "Gemfile.lock"
)

LOCALIZATION_PATTERNS=(
  "**/*.strings"
  "**/*.stringsdict"
)

# Check if arguments are valid
if [ -z "${1:-}" ] || [ "$1" != "--job-type" ] || [ -z "${2:-}" ]; then
  echo "Error: Must specify --job-type [build|localization]"
  buildkite-agent step cancel
  exit 15
fi

# Function to display skip message and create annotation
show_skip_message() {
  local job_type=$1
  local message="Skipping ${BUILDKITE_LABEL:-Job} - no relevant files changed"
  local context="skip-$(echo "${BUILDKITE_LABEL:-$job_type}" | sed -E -e 's/[^[:alnum:]]+/-/g' | tr A-Z a-z)"
  
  echo "$message" | buildkite-agent annotate --style "info" --context "$context"
  echo "$message"
}

job_type="$2"
case "$job_type" in
  "localization")
    # Check if any localization files have changed
    # Return true (skip) if NO localization files have changed
    if ! pr_changed_files --any-match "${LOCALIZATION_PATTERNS[@]}"; then
      show_skip_message "$job_type"
      exit 0
    fi
    exit 1
    ;;
  "build")
    # We should skip if changes are limited to documentation, tooling, and non-code files
    # We'll let the job run (won't skip) if PR includes changes in localization files though
    PATTERNS=("${COMMON_PATTERNS[@]}")
    if pr_changed_files --all-match "${PATTERNS[@]}"; then
      show_skip_message "$job_type"
      exit 0
    fi

Review comment (suggestion):
After looking at the annotations in https://github.com/Automattic/pocket-casts-android/pull/4002 and here, I wonder if it might be best to use the past tense.

<img alt="image" src="https://github.com/user-attachments/assets/6ed4273e-314a-42e4-a861-d03164ca31d1" width=300/>

My reasoning is that "Skipping..." makes sense in the logs, but when one looks at the build annotation, the skipping has already happened.

```suggestion
  local message="Skipped ${BUILDKITE_LABEL:-Job} - no relevant files changed"
```

Code after:
  "*.po"
  "*.pot"
  "*.txt"
  ".gitignore"
  "config/Version.xcconfig"
  "fastlane/**"
  "Gemfile"
  "Gemfile.lock"
)

LOCALIZATION_PATTERNS=(
  "**/*.strings"
  "**/*.stringsdict"
)

# Define constants for job types
BUILD="build"
LOCALIZATION="localization"

# Check if arguments are valid
if [ -z "${1:-}" ] || [ "$1" != "--job-type" ] || [ -z "${2:-}" ]; then
  echo "Error: Must specify --job-type [$BUILD|$LOCALIZATION]"
  buildkite-agent step cancel
  exit 15
fi

# Function to display skip message and create annotation
show_skip_message() {
  local job_type=$1
  local message="Skipped ${BUILDKITE_LABEL:-Job} - no relevant files changed"
  local context="skip-$(echo "${BUILDKITE_LABEL:-$job_type}" | sed -E -e 's/[^[:alnum:]]+/-/g' | tr A-Z a-z)"
  
  echo "$message" | buildkite-agent annotate --style "info" --context "$context"
  echo "$message"
}

job_type="$2"
case "$job_type" in
  $LOCALIZATION)
    # Check if any localization files have changed
    # Return true (skip) if NO localization files have changed
    if ! pr_changed_files --any-match "${LOCALIZATION_PATTERNS[@]}"; then
      show_skip_message "$job_type"
      exit 0
    fi
    exit 1
    ;;
  $BUILD)
    # We should skip if changes are limited to documentation, tooling, and non-code files
    # We'll let the job run (won't skip) if PR includes changes in localization files though
    PATTERNS=("${COMMON_PATTERNS[@]}")