From 3252136c1fe3746be7c33ade211fd34a6e9d8f0f Mon Sep 17 00:00:00 2001 From: Tyler Wilding Date: Wed, 13 Sep 2023 23:31:08 -0600 Subject: [PATCH] CI: check for removed goal_src code that we want or need to perserve (#2987) --- .github/workflows/inform-pages-repo.yaml | 11 ++-- .github/workflows/linting.yaml | 10 ++++ .github/workflows/linux-build-clang.yaml | 11 ++-- .github/workflows/linux-build-gcc.yaml | 11 ++-- .gitignore | 1 + .vscode/opengoal.code-snippets | 6 --- goal_src/jak2/engine/collide/collide-mesh.gc | 2 - goal_src/jak2/levels/castle/castle-obs.gc | 2 - goal_src/jak2/levels/city/helldog/helldog.gc | 2 - .../jak2/levels/city/palace/ctypal-obs.gc | 2 - goal_src/jak2/levels/common/airlock.gc | 2 - goal_src/jak2/levels/palace/pal-obs.gc | 2 - scripts/ci/lint-gsrc-removals.py | 51 +++++++++++++++++++ 13 files changed, 80 insertions(+), 33 deletions(-) create mode 100644 scripts/ci/lint-gsrc-removals.py diff --git a/.github/workflows/inform-pages-repo.yaml b/.github/workflows/inform-pages-repo.yaml index 385b6d752..0ea3f904a 100644 --- a/.github/workflows/inform-pages-repo.yaml +++ b/.github/workflows/inform-pages-repo.yaml @@ -25,11 +25,12 @@ jobs: uses: actions/checkout@v3 - name: Install Package Dependencies - run: > - sudo apt install build-essential cmake - clang gcc g++ lcov make nasm libxrandr-dev - libxinerama-dev libxcursor-dev libpulse-dev - libxi-dev zip ninja-build + run: | + sudo apt update + sudo apt install build-essential cmake \ + clang gcc g++ lcov make nasm libxrandr-dev \ + libxinerama-dev libxcursor-dev libpulse-dev \ + libxi-dev zip ninja-build libgl1-mesa-dev - name: Setup Buildcache uses: mikehardy/buildcache-action@v2.1.0 diff --git a/.github/workflows/linting.yaml b/.github/workflows/linting.yaml index 6e11a5736..7ce2100e8 100644 --- a/.github/workflows/linting.yaml +++ b/.github/workflows/linting.yaml @@ -40,6 +40,16 @@ jobs: - name: Checkout Repository uses: actions/checkout@v3 + - name: Install Python Dependencies + run: pip install unidiff colorama + + - name: Check for Removed goal_src/ Code + # FYI - if you run this `git diff` on windows, it creates a utf-16 LE file + run: | + git fetch origin + git diff origin/master > lint-changes.diff + python ./scripts/ci/lint-gsrc-removals.py + - name: Check for Unresolved Conflicts run: python ./scripts/gsrc/check-for-conflicts.py diff --git a/.github/workflows/linux-build-clang.yaml b/.github/workflows/linux-build-clang.yaml index 5a9ca794d..5da6345e2 100644 --- a/.github/workflows/linux-build-clang.yaml +++ b/.github/workflows/linux-build-clang.yaml @@ -32,11 +32,12 @@ jobs: uses: actions/checkout@v3 - name: Install Package Dependencies - run: > - sudo apt install build-essential cmake - clang gcc g++ lcov make nasm libxrandr-dev - libxinerama-dev libxcursor-dev libpulse-dev - libxi-dev zip ninja-build libgl1-mesa-dev + run: | + sudo apt update + sudo apt install build-essential cmake \ + clang gcc g++ lcov make nasm libxrandr-dev \ + libxinerama-dev libxcursor-dev libpulse-dev \ + libxi-dev zip ninja-build libgl1-mesa-dev - name: Setup Buildcache uses: mikehardy/buildcache-action@v2.1.0 diff --git a/.github/workflows/linux-build-gcc.yaml b/.github/workflows/linux-build-gcc.yaml index 33aca7dfe..8a805d634 100644 --- a/.github/workflows/linux-build-gcc.yaml +++ b/.github/workflows/linux-build-gcc.yaml @@ -28,11 +28,12 @@ jobs: uses: actions/checkout@v3 - name: Install Package Dependencies - run: > - sudo apt install build-essential cmake - clang gcc g++ lcov make nasm libxrandr-dev - libxinerama-dev libxcursor-dev libpulse-dev - libxi-dev zip ninja-build libgl1-mesa-dev + run: | + sudo apt update + sudo apt install build-essential cmake \ + clang gcc g++ lcov make nasm libxrandr-dev \ + libxinerama-dev libxcursor-dev libpulse-dev \ + libxi-dev zip ninja-build libgl1-mesa-dev - name: Setup Buildcache uses: mikehardy/buildcache-action@v2.1.0 diff --git a/.gitignore b/.gitignore index 84bf811ae..3884a00c7 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ __pycache__/ /jak2-*.json /TODO.md unifont-15.0.03.ttf +*.diff diff --git a/.vscode/opengoal.code-snippets b/.vscode/opengoal.code-snippets index 45975a679..14e90aac3 100644 --- a/.vscode/opengoal.code-snippets +++ b/.vscode/opengoal.code-snippets @@ -17,12 +17,6 @@ "body": [";; og:ignore-form:${1:substr}"], "description": "If the provided substr is found in the starting line of a form, the entire form will be omitted when copying decompiled code into the file" }, - "og:update-with-merge": { - "scope": "opengoal", - "prefix": ["og:update-with-merge"], - "body": [";; og:update-with-merge"], - "description": "The file will be updated with a git merge-file instead of naive copy-paste" - }, "og:preserve-this": { "scope": "opengoal", "prefix": ["og:preserve-this"], diff --git a/goal_src/jak2/engine/collide/collide-mesh.gc b/goal_src/jak2/engine/collide/collide-mesh.gc index 765ac6a52..e7733066b 100644 --- a/goal_src/jak2/engine/collide/collide-mesh.gc +++ b/goal_src/jak2/engine/collide/collide-mesh.gc @@ -25,8 +25,6 @@ a single mesh, so it's limited to tests like single foreground mesh vs. sphere. Another limitation is that triangles don't have per-tri pat info. |# -;; og:update-with-merge - ;; DECOMP BEGINS diff --git a/goal_src/jak2/levels/castle/castle-obs.gc b/goal_src/jak2/levels/castle/castle-obs.gc index ee313b48d..0c63cef11 100644 --- a/goal_src/jak2/levels/castle/castle-obs.gc +++ b/goal_src/jak2/levels/castle/castle-obs.gc @@ -5,8 +5,6 @@ ;; name in dgo: castle-obs ;; dgos: CAS -;; og:update-with-merge:substr - ;; DECOMP BEGINS (define *cas-conveyor-room-id* 0) diff --git a/goal_src/jak2/levels/city/helldog/helldog.gc b/goal_src/jak2/levels/city/helldog/helldog.gc index 4ca533b47..7a6a04bec 100644 --- a/goal_src/jak2/levels/city/helldog/helldog.gc +++ b/goal_src/jak2/levels/city/helldog/helldog.gc @@ -13,8 +13,6 @@ ) ) -;; og:update-with-merge - ;; DECOMP BEGINS (defmethod draw hud-helldog ((obj hud-helldog)) diff --git a/goal_src/jak2/levels/city/palace/ctypal-obs.gc b/goal_src/jak2/levels/city/palace/ctypal-obs.gc index be795fe20..19062f060 100644 --- a/goal_src/jak2/levels/city/palace/ctypal-obs.gc +++ b/goal_src/jak2/levels/city/palace/ctypal-obs.gc @@ -5,8 +5,6 @@ ;; name in dgo: ctypal-obs ;; dgos: CPA -;; og:update-with-merge:substr - ;; DECOMP BEGINS (deftype water-anim-ctypal (water-anim) diff --git a/goal_src/jak2/levels/common/airlock.gc b/goal_src/jak2/levels/common/airlock.gc index 77a8f3b9e..2d5caaa3a 100644 --- a/goal_src/jak2/levels/common/airlock.gc +++ b/goal_src/jak2/levels/common/airlock.gc @@ -5,8 +5,6 @@ ;; name in dgo: airlock ;; dgos: GAME, COMMON -;; og:update-with-merge - ;; DECOMP BEGINS (deftype com-airlock (process-drawable) diff --git a/goal_src/jak2/levels/palace/pal-obs.gc b/goal_src/jak2/levels/palace/pal-obs.gc index 8a5d35156..2a57ffc66 100644 --- a/goal_src/jak2/levels/palace/pal-obs.gc +++ b/goal_src/jak2/levels/palace/pal-obs.gc @@ -5,8 +5,6 @@ ;; name in dgo: pal-obs ;; dgos: PAE, PAC -;; og:update-with-merge:substr - ;; DECOMP BEGINS (deftype pal-falling-plat (process-drawable) diff --git a/scripts/ci/lint-gsrc-removals.py b/scripts/ci/lint-gsrc-removals.py new file mode 100644 index 000000000..b43adb627 --- /dev/null +++ b/scripts/ci/lint-gsrc-removals.py @@ -0,0 +1,51 @@ +# Gets the diff between this PR and `origin/master` +# If there are any 'og:preserve-this' lines removed, the script returns 1 + +import unidiff +from colorama import Fore + +with open("lint-changes.diff", encoding="utf-8") as f: + diff = f.read() + +patch_set = unidiff.PatchSet.from_string(diff) + +flagged_deletions = [] + +for patched_file in patch_set: + file_path = patched_file.path + for hunk in patched_file: + for line in hunk: + if line.is_removed and "og:preserve-this" in line.value.strip(): + flagged_deletions.append( + { + "file": file_path, + "line_num": line.source_line_no, + "deletion": line.value.strip(), + } + ) + +print(flagged_deletions) + +if len(flagged_deletions) > 0: + print( + Fore.RED + + "Flagged goal_src code has been deleted, either you made a mistake or you better know what you're doing!" + Fore.RESET + ) + for flagged_deletion in flagged_deletions: + print( + " - {}{}{}:{}{}{} - {}{}{}".format( + Fore.CYAN, + flagged_deletion["file"], + Fore.RESET, + Fore.GREEN, + flagged_deletion["line_num"], + Fore.RESET, + Fore.RED, + flagged_deletion["deletion"], + Fore.RESET, + ) + ) + print(Fore.RESET) + exit(1) +print("No flagged goal_src code was deleted (hopefully!)") +exit(0)