-
Notifications
You must be signed in to change notification settings - Fork 335
CHANGE: Add CI job to check Editor references in Runtime code #2413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jfreire-unity
wants to merge
8
commits into
develop
Choose a base branch
from
add-check-runtime-editor-refs-gha-workflow
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d3f13fb
Add workflow to do text-based check for Editor references in Runtime …
jfreire-unity b8af166
Fix bash script
jfreire-unity ceba02f
Make sure to install ripgrep on CI
jfreire-unity 43214cc
Fix colors on failure
jfreire-unity bd1173b
Replaced ripgrep with normal grep so we don't have to install anything
jfreire-unity 87a8374
Update .github/workflows/check-runtime-editor-refs.yml
jfreire-unity a35fa44
Update check-runtime-editor-refs.sh
jfreire-unity d426d9e
Fix InputSettings editor dependency
jfreire-unity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| - opened | ||
| - synchronize | ||
| - reopened | ||
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/bin/bash | ||
| [ -n "$BASH_VERSION" ] || { echo "ERROR: This script requires bash. Run with: bash $0" >&2; exit 1; } | ||
| set -euo pipefail | ||
|
|
||
| RUNTIME_DIR="Packages/com.unity.inputsystem/InputSystem/Runtime" | ||
|
|
||
| # POSIX ERE patterns for grep -E, compatible with macOS (BSD grep) and Ubuntu (GNU grep). | ||
| # No \b word boundaries — not portable across both. False positive risk is negligible | ||
| # since no real identifiers contain these namespace roots as substrings. | ||
| # (\.[A-Za-z0-9_]+)* covers sub-namespaces (UnityEditor.UI, …Editor.Tools, …). | ||
| # Add more lines as needed, e.g. 'UnityEditorInternal(\.[A-Za-z0-9_]+)*' | ||
| FORBIDDEN_REGEX=( | ||
| 'UnityEditor(\.[A-Za-z0-9_]+)*' | ||
| 'UnityEngine\.InputSystem\.Editor(\.[A-Za-z0-9_]+)*' | ||
| ) | ||
|
|
||
| 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. | ||
| Edit FORBIDDEN_REGEX in this script to add patterns. | ||
|
|
||
| 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 "${RED}ERROR: Runtime directory not found: $RUNTIME_DIR${NC}" >&2; exit 1; } | ||
|
|
||
| COMBINED=$(IFS='|'; echo "${FORBIDDEN_REGEX[*]}") | ||
|
|
||
| GREP_OUTPUT=$(grep -rnw --include='*.cs' --color=never -E "$COMBINED" "$RUNTIME_DIR" || true) | ||
|
|
||
| if [ "$INCLUDE_COMMENTS" = false ]; then | ||
| VIOLATIONS=$(echo "$GREP_OUTPUT" | grep -Ev ':[0-9]+:[[:space:]]*//' || true) | ||
| else | ||
| VIOLATIONS="$GREP_OUTPUT" | ||
| fi | ||
|
|
||
| if [ -z "$VIOLATIONS" ]; then | ||
| echo "${GREEN}PASS: No Editor namespace references found in Runtime code.${NC}" | ||
| exit 0 | ||
| fi | ||
|
|
||
| VIOLATION_COUNT=$(echo "$VIOLATIONS" | wc -l | tr -d ' ') | ||
| echo "${RED}FAIL: Found $VIOLATION_COUNT Editor namespace reference(s) in Runtime code:${NC}" | ||
| echo "" | ||
| echo "$VIOLATIONS" | ||
| echo "" | ||
| echo "${RED}Active patterns:${NC}" | ||
| for re in "${FORBIDDEN_REGEX[@]}"; do | ||
| printf ' \033[0;31m%s\033[0m\n' "$re" | ||
| done | ||
| exit 1 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.