Skip to content
Merged
17 changes: 16 additions & 1 deletion .github/workflows/fast-pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,23 @@ jobs:
scheme: Sentry
run_on_cirrus_labs: true

sentrycrash-import-ratchet:
name: SentryCrash Import Ratchet
if: needs.files-changed.outputs.run_unit_tests_for_prs == 'true'
needs: files-changed
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Check SentryCrash import count
run: ./scripts/check-sentrycrash-imports.sh

fast-checks-required:
needs: [files-changed, fast-xcframework-slices, fast-unit-tests]
needs: [
files-changed,
fast-xcframework-slices,
fast-unit-tests,
sentrycrash-import-ratchet,
]
name: Fast PR Checks
if: always()
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ update-versions:
check-versions:
./scripts/check-tooling-versions.sh

## Check SentryCrash imports
#
# CI ratchet that ensures the number of direct SentryCrash header imports
# from SDK source files does not increase beyond the established baseline.
.PHONY: check-sentrycrash-imports
check-sentrycrash-imports:
@./scripts/check-sentrycrash-imports.sh

# ============================================================================
# BUILDING
# ============================================================================
Expand Down
32 changes: 32 additions & 0 deletions scripts/check-sentrycrash-imports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# CI ratchet: ensures SentryCrash import count doesn't increase in SDK sources.
# Decrease MAX_IMPORTS as phases eliminate imports. Never increase it.

set -euo pipefail

# Source CI utilities for proper logging
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=./ci-utils.sh disable=SC1091
source "$SCRIPT_DIR/ci-utils.sh"

MAX_IMPORTS=59

count=$(grep -rn '#import.*SentryCrash' Sources/Sentry Sources/Swift \
--include='*.m' --include='*.h' --include='*.c' --include='*.mm' \
| grep -vc 'Sources/SentryCrash/' \
Comment thread
itaybre marked this conversation as resolved.
Outdated
| tr -d ' ')
Comment thread
itaybre marked this conversation as resolved.
Outdated

if [ "$count" -gt "$MAX_IMPORTS" ]; then
log_error "SentryCrash import count increased from $MAX_IMPORTS to $count"
log_error "New imports from SDK files into SentryCrash headers are not allowed."
log_error "Use the SentryCrashReporter protocol instead."
echo ""
log_notice "Offending imports:"
grep -rn '#import.*SentryCrash' Sources/Sentry Sources/Swift \
--include='*.m' --include='*.h' --include='*.c' --include='*.mm' \
| grep -v 'Sources/SentryCrash/'
exit 1
fi

log_notice "SentryCrash import ratchet: $count / $MAX_IMPORTS (OK)"
Loading