From aadd9b3f3f0b6a691dd52788434f0e584c914d76 Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Fri, 15 Dec 2023 11:44:32 +0000 Subject: [PATCH 1/8] Add isOwner checks to hologram parenting funcs --- lua/entities/gmod_wire_expression2/core/hologram.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index eff492bc5f..5cabaf40e3 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1227,6 +1227,10 @@ e2function void holoParent(index, entity ent) local Holo = CheckIndex(self, index) if not Holo then return end + if not E2Lib.isOwner(self, ent) then + return self:throw("You do not have permission to parent to this entity", nil) + end + if not Check_Parents(Holo.ent, ent) then return end Parent_Hologram(Holo, ent, nil) @@ -1237,6 +1241,10 @@ e2function void holoParentAttachment(index, entity ent, string attachmentName) local Holo = CheckIndex(self, index) if not Holo then return end + if not E2Lib.isOwner(self, ent) then + return self:throw("You do not have permission to parent to this entity", nil) + end + Parent_Hologram(Holo, ent, attachmentName) end From 748ec83bdb91939697b6b8c035ed8ca4bbdc6075 Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Fri, 15 Dec 2023 17:50:42 +0000 Subject: [PATCH 2/8] Move owner check before checkindex --- lua/entities/gmod_wire_expression2/core/hologram.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 5cabaf40e3..e5c1df114a 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1224,13 +1224,13 @@ end e2function void holoParent(index, entity ent) if not IsValid(ent) then return end - local Holo = CheckIndex(self, index) - if not Holo then return end - if not E2Lib.isOwner(self, ent) then return self:throw("You do not have permission to parent to this entity", nil) end + local Holo = CheckIndex(self, index) + if not Holo then return end + if not Check_Parents(Holo.ent, ent) then return end Parent_Hologram(Holo, ent, nil) @@ -1238,13 +1238,13 @@ end e2function void holoParentAttachment(index, entity ent, string attachmentName) if not IsValid(ent) then return end - local Holo = CheckIndex(self, index) - if not Holo then return end - if not E2Lib.isOwner(self, ent) then return self:throw("You do not have permission to parent to this entity", nil) end + local Holo = CheckIndex(self, index) + if not Holo then return end + Parent_Hologram(Holo, ent, attachmentName) end From 84f9b0ff4da59d55232c6effbf7106dce54c3c6f Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:09:13 +0000 Subject: [PATCH 3/8] Implement TAS DevX --- .editorconfig | 14 ++++++ .gitattributes | 19 +------- .github/pull_request_template.md | 29 ++++++++++++ .github/workflows/canary.yml | 25 ---------- .github/workflows/deploy.yml | 23 ---------- .github/workflows/lint.yml | 37 --------------- .github/workflows/lua.yml | 50 ++++++++++++++++++++ .github/workflows/push_feature.yml | 9 ++++ .github/workflows/push_release.yml | 21 +++++++++ .github/workflows/stale.yml | 29 ------------ .glualint.json | 73 ++++++++++++------------------ stylua.toml | 7 +++ 12 files changed, 160 insertions(+), 176 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/pull_request_template.md delete mode 100644 .github/workflows/canary.yml delete mode 100644 .github/workflows/deploy.yml delete mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/lua.yml create mode 100644 .github/workflows/push_feature.yml create mode 100644 .github/workflows/push_release.yml delete mode 100644 .github/workflows/stale.yml create mode 100644 stylua.toml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..984088edf3 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +root = true + +[*] +indent_style = tab +indent_size = 4 + +end_of_line = lf +insert_final_newline = true + +trim_trailing_whitespace = true + +[*.{yml,yaml,json}] +indent_style = space +indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 9a8d916de1..a9017f46e7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,17 +1,2 @@ -*.fgd text -*.json text -*.lua text -*.md text -*.sh text -*.txt text -*.vmt text - -*.jpg binary -*.mdl binary -*.phy binary -*.vtf binary -*.vtx binary -*.vvd binary -*.wav binary - -* text=auto +# Enforce UNIX line endings +* text=auto eol=lf diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000000..b7e58d25c2 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,29 @@ + + +## Issue + + + +Resolves # + +## Changes + + + +## Impact + + + +## Testing + + + +## Helpful Links + +[Discord](https://discord.tasevers.com) diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml deleted file mode 100644 index 3506378daf..0000000000 --- a/.github/workflows/canary.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: Deploy Canary to Workshop - -on: - push: - branches: [ master ] - workflow_dispatch: - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@master - - - name: Embed version - run: | - echo -e "\ncachedversion = \"Canary ${GITHUB_SHA:0:7}\"" >> lua/wire/server/wirelib.lua - - - uses: wiremod/gmod-upload@master - with: - id: 3066780663 - changelog: ${{ github.event.head_commit.message }} - env: - STEAM_USERNAME: ${{ secrets.WIRETEAM_WORKSHOP_USERNAME }} - STEAM_PASSWORD: ${{ secrets.WIRETEAM_WORKSHOP_PASSWORD }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 3f683db030..0000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Deploy to Workshop - -on: - workflow_dispatch: - -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@master - - - name: Embed version - run: | - echo -e "\ncachedversion = \"Workshop ${GITHUB_SHA:0:7}\"" >> lua/wire/server/wirelib.lua - - - uses: wiremod/gmod-upload@master - with: - id: 160250458 - changelog: "Deployment via Github to commit ${GITHUB_SHA:0:7}" - env: - STEAM_USERNAME: ${{ secrets.WIRETEAM_WORKSHOP_USERNAME }} - STEAM_PASSWORD: ${{ secrets.WIRETEAM_WORKSHOP_PASSWORD }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index 1d73022b28..0000000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Lint - -on: - pull_request: - paths: - - "lua/**" - workflow_dispatch: - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@master - - uses: leafo/gh-actions-lua@v10 - with: - luaVersion: "luajit-2.1.0-beta3" - - - name: Get any changed files - id: changed-files - uses: tj-actions/changed-files@v36 - with: - files: | - **.lua - - - name: Run E2 Extension Preprocessor - run: | - lua .github/workflows/preprocess.lua ${{ steps.changed-files.outputs.all_changed_files }} - - - name: Download GluaFixer - run: | - curl -o glualint.zip -L https://github.com/FPtje/GLuaFixer/releases/download/1.24.6/glualint-1.24.6-x86_64-linux.zip - unzip glualint.zip - - - name: Lint Code - run: | - ./glualint ${{ steps.changed-files.outputs.all_changed_files }} diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml new file mode 100644 index 0000000000..d7d7496ade --- /dev/null +++ b/.github/workflows/lua.yml @@ -0,0 +1,50 @@ +name: Lua CI + +on: + workflow_call: + +jobs: + format: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: JohnnyMorganz/stylua-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + version: latest + args: --check ./lua + + lint: + runs-on: ubuntu-latest + env: + GLUAFIXER_VERSION: 1.26.0 + + steps: + - uses: actions/checkout@v4 + + - uses: leafo/gh-actions-lua@v10 + with: + luaVersion: "luajit-2.1.0-beta3" + + - name: Get any changed files + id: changed-files + uses: tj-actions/changed-files@v36 + with: + files: | + **.lua + + # TODO: Kill this + - name: Run E2 Extension Preprocessor + run: | + lua .github/workflows/preprocess.lua ${{ steps.changed-files.outputs.all_changed_files }} + + - name: Download GLuaFixer + run: | + curl --retry 3 --location https://github.com/FPtje/GLuaFixer/releases/download/$GLUAFIXER_VERSION/glualint-$GLUAFIXER_VERSION-x86_64-linux.zip --output gluafixer.zip + unzip gluafixer.zip + + - name: Lint Code + run: | + ./glualint --output-format github --config .glualint.json lint ./lua diff --git a/.github/workflows/push_feature.yml b/.github/workflows/push_feature.yml new file mode 100644 index 0000000000..381ab85911 --- /dev/null +++ b/.github/workflows/push_feature.yml @@ -0,0 +1,9 @@ +name: Push to non-release branch + +on: + push: + branches-ignore: master + +jobs: + lua: + uses: "./.github/workflows/lua.yml" diff --git a/.github/workflows/push_release.yml b/.github/workflows/push_release.yml new file mode 100644 index 0000000000..9a1eca9496 --- /dev/null +++ b/.github/workflows/push_release.yml @@ -0,0 +1,21 @@ +name: Push to release branch + +on: + push: + branches: master + +jobs: + lua: + uses: "./.github/workflows/lua.yml" + + deploy: + runs-on: ubuntu:latest + needs: [lua] + + environment: production + concurrency: production + + steps: + # TODO: Upgrade this to v2 deployment when bundling added + - name: Post to webhook + run: curl --fail-with-body -X POST ${{ secrets.DEPLOYER_WEBHOOK }}/${{ github.event.repository.name }} diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index c67325a8df..0000000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,29 +0,0 @@ -# This workflow warns and then closes issues and PRs that have had no activity for a specified amount of time. -# -# You can adjust the behavior by modifying this file. -# For more information, see: -# https://github.com/actions/stale -name: Mark stale issues and pull requests - -on: - schedule: - - cron: '43 19 * * *' - -jobs: - stale: - - runs-on: ubuntu-latest - permissions: - issues: write - pull-requests: write - - steps: - - uses: actions/stale@v5 - with: - repo-token: ${{ secrets.GITHUB_TOKEN }} - days-before-issue-stale: -1 - days-before-issue-close: -1 - stale-pr-message: "This pull request has been marked as stale as there haven't been any changes in the past month. It will be closed in 15 days." - stale-pr-label: "Stale" - days-before-pr-stale: 30 - days-before-pr-close: 45 diff --git a/.glualint.json b/.glualint.json index 22f13bd0c5..f1249c59a1 100644 --- a/.glualint.json +++ b/.glualint.json @@ -1,47 +1,30 @@ { - "lint_maxScopeDepth": 9, - "lint_syntaxErrors": true, - "lint_syntaxInconsistencies": true, - "lint_deprecated": true, - "lint_trailingWhitespace": true, - "lint_whitespaceStyle": false, - "lint_beginnerMistakes": false, - "lint_emptyBlocks": true, - "lint_shadowing": false, - "lint_gotos": true, - "lint_goto_identifier": true, - "lint_doubleNegations": true, - "lint_redundantIfStatements": false, - "lint_redundantParentheses": true, - "lint_duplicateTableKeys": true, - "lint_profanity": true, - "lint_unusedVars": true, - "lint_unusedParameters": false, - "lint_unusedLoopVars": false, - "lint_inconsistentVariableStyle": false, - "lint_spaceBetweenParens": false, - "lint_spaceBetweenBrackets": false, - "lint_spaceBetweenBraces": false, - "lint_ignoreFiles": [], - "lint_spaceBeforeComma": false, - "lint_spaceAfterComma": false, - "lint_maxLineLength": 0, + "lint_maxScopeDepth": 7, + "lint_syntaxErrors": true, + "lint_syntaxInconsistencies": true, + "lint_deprecated": true, + "lint_trailingWhitespace": true, + "lint_whitespaceStyle": true, + "lint_beginnerMistakes": true, + "lint_emptyBlocks": true, + "lint_shadowing": true, + "lint_gotos": true, + "lint_goto_identifier": true, + "lint_doubleNegations": true, + "lint_redundantIfStatements": true, + "lint_redundantParentheses": true, + "lint_duplicateTableKeys": true, + "lint_profanity": true, + "lint_unusedVars": true, + "lint_unusedParameters": true, + "lint_unusedLoopVars": true, + "lint_inconsistentVariableStyle": false, + "lint_spaceBetweenParens": false, + "lint_spaceBetweenBrackets": false, + "lint_spaceBetweenBraces": false, + "lint_ignoreFiles": [], + "lint_spaceBeforeComma": false, + "lint_spaceAfterComma": false, - "prettyprint_spaceBetweenParens": false, - "prettyprint_spaceBetweenBrackets": false, - "prettyprint_spaceBetweenBraces": false, - "prettyprint_spaceEmptyParens": false, - "prettyprint_spaceEmptyBraces": false, - "prettyprint_spaceAfterLabel": false, - "prettyprint_spaceBeforeComma": false, - "prettyprint_spaceAfterComma": true, - "prettyprint_semicolons": false, - "prettyprint_cStyle": false, - "prettyprint_removeRedundantParens": true, - "prettyprint_minimizeParens": false, - "prettyprint_assumeOperatorAssociativity": true, - "prettyprint_rejectInvalidCode": false, - "prettyprint_indentation": " ", - - "log_format": "auto" -} \ No newline at end of file + "log_format": "auto" +} diff --git a/stylua.toml b/stylua.toml new file mode 100644 index 0000000000..4d8c0476b6 --- /dev/null +++ b/stylua.toml @@ -0,0 +1,7 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Tabs" +indent_width = 4 +quote_style = "AutoPreferDouble" +call_parentheses = "Always" +collapse_simple_statement = "Never" From 50eb15c335b3cc8f3f69a732339ddd8d35cc52c5 Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:20:55 +0000 Subject: [PATCH 4/8] Disable code quality checks in deploy job --- .github/workflows/push_release.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/push_release.yml b/.github/workflows/push_release.yml index 9a1eca9496..69aab2a2f7 100644 --- a/.github/workflows/push_release.yml +++ b/.github/workflows/push_release.yml @@ -10,7 +10,8 @@ jobs: deploy: runs-on: ubuntu:latest - needs: [lua] + # TODO: Re-enable this once the whole codebase passes the formatter and linter + #needs: [lua] environment: production concurrency: production From 066998cd7cee98cb1f6bd296de72cd9c4bc40d2e Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Wed, 20 Dec 2023 20:22:34 +0000 Subject: [PATCH 5/8] Fix runs-on property --- .github/workflows/push_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push_release.yml b/.github/workflows/push_release.yml index 69aab2a2f7..abc741e690 100644 --- a/.github/workflows/push_release.yml +++ b/.github/workflows/push_release.yml @@ -9,7 +9,7 @@ jobs: uses: "./.github/workflows/lua.yml" deploy: - runs-on: ubuntu:latest + runs-on: ubuntu-latest # TODO: Re-enable this once the whole codebase passes the formatter and linter #needs: [lua] From 1b23bd0f2e0c22f7dd2dfcb04b4681401af2db7d Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Sat, 6 Jan 2024 09:53:23 +0000 Subject: [PATCH 6/8] Replace getregistry with FindMetaTable --- lua/entities/gmod_wire_expression2/core/e2lib.lua | 9 ++++++--- lua/entities/gmod_wire_expression2/core/player.lua | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/e2lib.lua b/lua/entities/gmod_wire_expression2/core/e2lib.lua index 1dc22b8fc1..8b83137741 100644 --- a/lua/entities/gmod_wire_expression2/core/e2lib.lua +++ b/lua/entities/gmod_wire_expression2/core/e2lib.lua @@ -902,6 +902,9 @@ for funcname, _ in pairs(makeglobal) do _G[funcname] = E2Lib[funcname] end +local PLAYER_METATABLE = FindMetaTable("Player") +local ENTITY_METATABLE = FindMetaTable("Entity") + hook.Add("InitPostEntity", "e2lib", function() -- If changed, put them into the global scope again. registerCallback("e2lib_replace_function", function(funcname, func, oldfunc) @@ -915,7 +918,7 @@ hook.Add("InitPostEntity", "e2lib", function() -- check for a CPPI compliant plugin if SERVER and CPPI then - if debug.getregistry().Player.CPPIGetFriends then + if PLAYER_METATABLE.CPPIGetFriends then E2Lib.replace_function("isFriend", function(owner, player) if owner == nil then return false end if owner == player then return true end @@ -934,7 +937,7 @@ hook.Add("InitPostEntity", "e2lib", function() end) end - if debug.getregistry().Entity.CPPIGetOwner then + if ENTITY_METATABLE.CPPIGetOwner then local _getOwner = E2Lib.getOwner E2Lib.replace_function("getOwner", function(self, entity) if not IsValid(entity) then return end @@ -1258,4 +1261,4 @@ function E2Lib.compileScript(code, owner) end end end -end \ No newline at end of file +end diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 91c2c63006..cc3f7e8b7b 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -509,9 +509,11 @@ end -------------------------------------------------------------------------------- +local PLAYER_METATABLE = FindMetaTable("Player") + __e2setcost(2) -if CPPI and debug.getregistry().Player.CPPIGetFriends then +if CPPI and PLAYER_METATABLE.CPPIGetFriends then local function Trusts(ply, whom) if ply == whom then return true end From 4978ab50460f871a2d01971c2e882f7fba5c04d9 Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Sat, 6 Jan 2024 09:57:39 +0000 Subject: [PATCH 7/8] Remove redundant metatable caching --- lua/entities/gmod_wire_expression2/core/e2lib.lua | 7 ++----- lua/entities/gmod_wire_expression2/core/player.lua | 4 +--- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/e2lib.lua b/lua/entities/gmod_wire_expression2/core/e2lib.lua index 8b83137741..38768987cd 100644 --- a/lua/entities/gmod_wire_expression2/core/e2lib.lua +++ b/lua/entities/gmod_wire_expression2/core/e2lib.lua @@ -902,9 +902,6 @@ for funcname, _ in pairs(makeglobal) do _G[funcname] = E2Lib[funcname] end -local PLAYER_METATABLE = FindMetaTable("Player") -local ENTITY_METATABLE = FindMetaTable("Entity") - hook.Add("InitPostEntity", "e2lib", function() -- If changed, put them into the global scope again. registerCallback("e2lib_replace_function", function(funcname, func, oldfunc) @@ -918,7 +915,7 @@ hook.Add("InitPostEntity", "e2lib", function() -- check for a CPPI compliant plugin if SERVER and CPPI then - if PLAYER_METATABLE.CPPIGetFriends then + if FindMetaTable("Player").CPPIGetFriends then E2Lib.replace_function("isFriend", function(owner, player) if owner == nil then return false end if owner == player then return true end @@ -937,7 +934,7 @@ hook.Add("InitPostEntity", "e2lib", function() end) end - if ENTITY_METATABLE.CPPIGetOwner then + if FindMetaTable("Entity").CPPIGetOwner then local _getOwner = E2Lib.getOwner E2Lib.replace_function("getOwner", function(self, entity) if not IsValid(entity) then return end diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index cc3f7e8b7b..7951ab7a56 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -509,11 +509,9 @@ end -------------------------------------------------------------------------------- -local PLAYER_METATABLE = FindMetaTable("Player") - __e2setcost(2) -if CPPI and PLAYER_METATABLE.CPPIGetFriends then +if CPPI and FindMetaTable("Player").CPPIGetFriends then local function Trusts(ply, whom) if ply == whom then return true end From 2d91ee7ed9d2aa0809e29d9aab1f37f15a4846cb Mon Sep 17 00:00:00 2001 From: Derpius <49565664+Derpius@users.noreply.github.com> Date: Sat, 6 Jan 2024 10:04:26 +0000 Subject: [PATCH 8/8] Bump changed files action version to v41 --- .github/workflows/lua.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lua.yml b/.github/workflows/lua.yml index d7d7496ade..0a74d1bc57 100644 --- a/.github/workflows/lua.yml +++ b/.github/workflows/lua.yml @@ -30,7 +30,7 @@ jobs: - name: Get any changed files id: changed-files - uses: tj-actions/changed-files@v36 + uses: tj-actions/changed-files@v41 with: files: | **.lua