Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/check-runtime-editor-refs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Check Editor references in Runtime code

on:
pull_request:
types:
- edited
- opened
- synchronize
Comment thread
jfreire-unity marked this conversation as resolved.
Outdated
branches: [ "develop" ]

workflow_dispatch:

jobs:
check-runtime-editor-refs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Check Runtime code has no Editor namespace references
run: bash check-runtime-editor-refs.sh
64 changes: 64 additions & 0 deletions check-runtime-editor-refs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env bash
set -euo pipefail

RUNTIME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/Packages/com.unity.inputsystem/InputSystem/Runtime"
Comment thread
jfreire-unity marked this conversation as resolved.
Outdated

# PCRE2 regexes — \b prevents matching identifiers that merely contain these strings.
# (\.[A-Za-z0-9_]+)* covers sub-namespaces (UnityEditor.UI, …Editor.Tools, …).
# Add more lines as needed, e.g. '\bUnityEditorInternal(\.[A-Za-z0-9_]+)*\b'
FORBIDDEN_REGEX=(
'\bUnityEditor(\.[A-Za-z0-9_]+)*\b'
'\bUnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*\b'
)

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

INCLUDE_COMMENTS=false
for arg in "$@"; do
case "$arg" in
--include-comments) INCLUDE_COMMENTS=true ;;
--help)
cat <<EOF
Usage: $(basename "$0") [OPTIONS]

Check that Runtime code has no Editor namespace dependencies.
Patterns are PCRE2; edit FORBIDDEN_REGEX in this script to add roots.

Options:
--include-comments Also flag references inside XML doc and // comments
--help Show this help
EOF
exit 0 ;;
*) echo "Unknown option: $arg"; exit 1 ;;
esac
done

[ -d "$RUNTIME_DIR" ] || { echo -e "${RED}ERROR: Runtime directory not found: $RUNTIME_DIR${NC}" >&2; exit 1; }

COMBINED=$(IFS='|'; echo "${FORBIDDEN_REGEX[*]}")

if [ "$INCLUDE_COMMENTS" = false ]; then
PATTERN="^(?!\s*//).*(?:$COMBINED)"
Comment thread
jfreire-unity marked this conversation as resolved.
Outdated
else
PATTERN="(?:$COMBINED)"
fi

VIOLATIONS=$(rg --type cs --line-number --no-heading --color never --pcre2 "$PATTERN" "$RUNTIME_DIR" 2>/dev/null || true)
Comment thread
jfreire-unity marked this conversation as resolved.
Outdated

if [ -z "$VIOLATIONS" ]; then
echo -e "${GREEN}PASS: No Editor namespace references found in Runtime code.${NC}"
exit 0
fi

VIOLATION_COUNT=$(echo "$VIOLATIONS" | wc -l | tr -d ' ')
echo -e "${RED}FAIL: Found $VIOLATION_COUNT Editor namespace reference(s) in Runtime code:${NC}"
echo ""
echo "$VIOLATIONS"
Comment thread
jfreire-unity marked this conversation as resolved.
echo ""
echo -e "${RED}Active patterns:${NC}"
for re in "${FORBIDDEN_REGEX[@]}"; do
printf ' \033[0;31m%s\033[0m\n' "$re"
done
exit 1
Loading