From 0dfeebccfa3b37755559d037ca8669f7b5eb637e Mon Sep 17 00:00:00 2001 From: PhoneDroid <73050054+PhoneDroid@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:56:01 -0400 Subject: [PATCH 1/7] Reworked dependency script --- .editorconfig | 33 +++++ .github/scripts/check-modified-subtree.sh | 139 ++++++++++++++----- .github/workflows/check-modified-subtree.yml | 43 ++++-- 3 files changed, 168 insertions(+), 47 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..de5e06abb --- /dev/null +++ b/.editorconfig @@ -0,0 +1,33 @@ + +################################################################################ +# # +# Editorconfig # +# # +# This file defines basic file properties that # +# editors / IDEs use when you edit documents. # +# # +# Check https://EditorConfig.org for details. # +# # +################################################################################ + + +root = true + + +[*] + +end_of_line = lf + + +[*.{editorconfig,json,yml,lua,txt,md}] + +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 +charset = utf-8 + + +[*.md] + +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.github/scripts/check-modified-subtree.sh b/.github/scripts/check-modified-subtree.sh index d268e98c0..b600dea80 100755 --- a/.github/scripts/check-modified-subtree.sh +++ b/.github/scripts/check-modified-subtree.sh @@ -1,46 +1,121 @@ #!/usr/bin/env bash -set -o errexit -set -o nounset +# +# Prints a list of errors for any dependencies that have been edited. +# ➞ Dependencies should be edited in their respective repositories +# -# This script will print GitHub errors when files from subtrees have been edited. -# Those files should be edited in their respective repositories. +echo 'Checking for any dependency changes.' -MASTER_REVISION=$(git rev-list --first-parent origin/master | head -n 1) -DIFFED_FILES=$(git diff --name-only "$MASTER_REVISION") +set -o errexit # Exit for any error +set -o nounset # Error when referencing unset vars -FAILED=false -if echo "$DIFFED_FILES" | grep -qP "^gamemode/modules/fpp/pp/"; then - echo "::error::Files from Falco's Prop Protection have been edited. Please submit a PR to https://github.com/fptje/falcos-Prop-protection instead!" - FAILED=true -fi +commit=$( + git rev-list \ + --first-parent origin/master \ + --max-count=1 +) -if echo "$DIFFED_FILES" | grep -qP "^gamemode/libraries/fn.lua"; then - echo "::error::The fn library has been edited. Please submit a PR to https://github.com/fptje/GModFunctional instead!" - FAILED=true -fi +files=$( + git diff \ + --name-only \ + "$commit" +) -if echo "$DIFFED_FILES" | grep -qP "^gamemode/libraries/mysqlite/mysqlite.lua"; then - echo "::error::The MySQLite library has been edited. Please submit a PR to https://github.com/fptje/MySQLite instead!" - FAILED=true -fi -if echo "$DIFFED_FILES" | grep -qP "^gamemode/libraries/simplerr.lua"; then - echo "::error::The Simplerr library has been edited. Please submit a PR to https://github.com/fptje/simplerr instead!" - FAILED=true -fi +# Template for the GitHub summary -if echo "$DIFFED_FILES" | grep -qP "^gamemode/libraries/sh_cami.lua"; then - echo "::error::The CAMI library has been edited. Please submit a PR to https://github.com/glua/CAMI instead!" - FAILED=true -fi +template=" + > [!WARNING] + > Files from **[{project}]({repository})** have been modified! + > ➞ Changes should only be made in its repository + > + {files} + > +" -if echo "$DIFFED_FILES" | grep -qP "^gamemode/modules/fspectate/"; then - echo "::error::Files from FSpectate have been edited. Please submit a PR to https://github.com/fptje/FSpectate instead!" - FAILED=true -fi +# Trim leading space for Markdown compatibility + +template="$( echo "$template" | sed 's/^[[:space:]]*//' )" + + +failed=false + +function check { + + local name="$1" + local path="^$2" + local repo="$3" + + + # Check if any matching files were modified + + local matched=$( + echo "$files" | + grep --perl-regexp "$path" + ) + + + # Ignore if nothing matched + + if [ -z "$matched" ] ; then + return + fi + + + # Append info to GitHub's summary + + local info="$template" + + matched="$(printf -- '> `%s` \n' "$matched")" + + info=${info//\{repository\}/$repo} + info=${info//\{project\}/$name} + info=${info//\{files\}/$matched} -if [[ "$FAILED" = true ]]; then + echo "$info" >> $GITHUB_STEP_SUMMARY + + failed=true +} + + +check "Falco's Prop Protection" \ + 'gamemode/modules/fpp/pp/' \ + 'https://github.com/fptje/falcos-Prop-protection' + + +check "FN Library" \ + 'gamemode/libraries/fn.lua' \ + 'https://github.com/fptje/GModFunctional' + + +check "MySQLite Library" \ + 'gamemode/libraries/mysqlite/mysqlite.lua' \ + 'https://github.com/fptje/MySQLite' + + +check "Simplerr Library" \ + 'gamemode/libraries/simplerr.lua' \ + 'https://github.com/fptje/simplerr' + + +check "CAMI Library" \ + 'gamemode/libraries/sh_cami.lua' \ + 'https://github.com/glua/CAMI' + + +check "FSpectate" \ + 'gamemode/modules/fspectate/' \ + 'https://github.com/fptje/FSpectate' + + +if [[ "$failed" = true ]] ; then + echo 'Some dependencies have been modified!' exit 1 fi + + +echo 'No dependencies have been modified.' + +exit 0 diff --git a/.github/workflows/check-modified-subtree.yml b/.github/workflows/check-modified-subtree.yml index 23bff9f51..941e1adc9 100644 --- a/.github/workflows/check-modified-subtree.yml +++ b/.github/workflows/check-modified-subtree.yml @@ -1,15 +1,28 @@ -name: check-modified-subtree -on: - pull_request: - branches: - - master -jobs: - check-modified-subtree: - runs-on: ubuntu-20.04 - steps: - - uses: actions/checkout@v2 - with: - # Make sure there is access to the master branch - fetch-depth: 0 - clean: false - - run: ./.github/scripts/check-modified-subtree.sh + +name : Check Modified Subtree + + +on : + workflow_dispatch : + + pull_request : + branches : [ master ] + + +jobs : + check : + + runs-on : ubuntu-latest + + steps : + + + + - name : Checkout Repository + uses : actions/checkout@v4 + with : + fetch-depth : 0 # Fetch complete history + clean : false + + - name : Check For Differences + run : ./.github/scripts/check-modified-subtree.sh From f3c8b4787239d8b3ed39e580b1bcd2d73c5af073 Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 21:41:11 +0100 Subject: [PATCH 2/7] Slim down editor config --- .editorconfig | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/.editorconfig b/.editorconfig index de5e06abb..a691e7100 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,24 +1,9 @@ - -################################################################################ -# # -# Editorconfig # -# # -# This file defines basic file properties that # -# editors / IDEs use when you edit documents. # -# # -# Check https://EditorConfig.org for details. # -# # -################################################################################ - - root = true - [*] end_of_line = lf - [*.{editorconfig,json,yml,lua,txt,md}] trim_trailing_whitespace = true @@ -26,8 +11,3 @@ insert_final_newline = true indent_style = space indent_size = 4 charset = utf-8 - - -[*.md] - -trim_trailing_whitespace = false \ No newline at end of file From dd7800abd1e8f68b42db92647e55c15fd44498ff Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 21:46:33 +0100 Subject: [PATCH 3/7] Add sh to editorconfig --- .editorconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.editorconfig b/.editorconfig index a691e7100..ef8f44c55 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ root = true end_of_line = lf -[*.{editorconfig,json,yml,lua,txt,md}] +[*.{editorconfig,json,yml,lua,txt,md,sh}] trim_trailing_whitespace = true insert_final_newline = true From bbedfde7413ae06b262f89b60847e8ed1ba25713 Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 21:54:17 +0100 Subject: [PATCH 4/7] Fix some shellcheck warnings --- .github/scripts/check-modified-subtree.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/scripts/check-modified-subtree.sh b/.github/scripts/check-modified-subtree.sh index b600dea80..aeb80833a 100755 --- a/.github/scripts/check-modified-subtree.sh +++ b/.github/scripts/check-modified-subtree.sh @@ -28,9 +28,9 @@ files=$( template=" > [!WARNING] - > Files from **[{project}]({repository})** have been modified! + > Files from **[{project}]({repository})** have been modified! > ➞ Changes should only be made in its repository - > + > {files} > " @@ -48,10 +48,11 @@ function check { local path="^$2" local repo="$3" - + # Check if any matching files were modified - - local matched=$( + + local matched + matched=$( echo "$files" | grep --perl-regexp "$path" ) @@ -69,12 +70,12 @@ function check { local info="$template" matched="$(printf -- '> `%s` \n' "$matched")" - + info=${info//\{repository\}/$repo} info=${info//\{project\}/$name} info=${info//\{files\}/$matched} - echo "$info" >> $GITHUB_STEP_SUMMARY + echo "$info" >> "$GITHUB_STEP_SUMMARY" failed=true } From 852e592f37cfac18f417c2f35dc61b5aa3152ffa Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 21:56:25 +0100 Subject: [PATCH 5/7] Modify warning description --- .github/scripts/check-modified-subtree.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/scripts/check-modified-subtree.sh b/.github/scripts/check-modified-subtree.sh index aeb80833a..2267ec7af 100755 --- a/.github/scripts/check-modified-subtree.sh +++ b/.github/scripts/check-modified-subtree.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash # -# Prints a list of errors for any dependencies that have been edited. -# ➞ Dependencies should be edited in their respective repositories +# Prints a list of errors for any dependencies that have been edited. +# Dependencies should be edited in their respective repositories # echo 'Checking for any dependency changes.' @@ -24,18 +24,19 @@ files=$( ) -# Template for the GitHub summary +# Template for the GitHub summary template=" > [!WARNING] > Files from **[{project}]({repository})** have been modified! - > ➞ Changes should only be made in its repository + > These changes originally come from [{project}]({repository}), but are synchronized to DarkRP. + > These files should be edited in the original repositories instead. > {files} > " -# Trim leading space for Markdown compatibility +# Trim leading space for Markdown compatibility template="$( echo "$template" | sed 's/^[[:space:]]*//' )" @@ -49,8 +50,7 @@ function check { local repo="$3" - # Check if any matching files were modified - + # Check if any matching files were modified local matched matched=$( echo "$files" | @@ -58,15 +58,13 @@ function check { ) - # Ignore if nothing matched - + # Ignore if nothing matched if [ -z "$matched" ] ; then return fi - # Append info to GitHub's summary - + # Append info to GitHub's summary local info="$template" matched="$(printf -- '> `%s` \n' "$matched")" From 3b5f2d9d9d075afa2cc746128b0c59a1a95dbb48 Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 21:59:53 +0100 Subject: [PATCH 6/7] Possibly fix error --- .github/scripts/check-modified-subtree.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/scripts/check-modified-subtree.sh b/.github/scripts/check-modified-subtree.sh index 2267ec7af..8b2983fae 100755 --- a/.github/scripts/check-modified-subtree.sh +++ b/.github/scripts/check-modified-subtree.sh @@ -51,8 +51,7 @@ function check { # Check if any matching files were modified - local matched - matched=$( + local matched=$( echo "$files" | grep --perl-regexp "$path" ) From 6644a97e734a022763637dbc37c134bb7d3399aa Mon Sep 17 00:00:00 2001 From: Falco Peijnenburg Date: Wed, 20 Mar 2024 22:08:15 +0100 Subject: [PATCH 7/7] Smaller format for action yaml file --- .github/workflows/check-modified-subtree.yml | 48 ++++++++------------ 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/.github/workflows/check-modified-subtree.yml b/.github/workflows/check-modified-subtree.yml index 941e1adc9..90c70991e 100644 --- a/.github/workflows/check-modified-subtree.yml +++ b/.github/workflows/check-modified-subtree.yml @@ -1,28 +1,20 @@ - -name : Check Modified Subtree - - -on : - workflow_dispatch : - - pull_request : - branches : [ master ] - - -jobs : - check : - - runs-on : ubuntu-latest - - steps : - - - - - name : Checkout Repository - uses : actions/checkout@v4 - with : - fetch-depth : 0 # Fetch complete history - clean : false - - - name : Check For Differences - run : ./.github/scripts/check-modified-subtree.sh +name: Check Modified Subtree + +on: + workflow_dispatch: + + pull_request: + branches: [master] + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch complete history + clean: false + + - name: Check For Differences + run: ./.github/scripts/check-modified-subtree.sh