diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..ef8f44c55 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,13 @@ +root = true + +[*] + +end_of_line = lf + +[*.{editorconfig,json,yml,lua,txt,md,sh}] + +trim_trailing_whitespace = true +insert_final_newline = true +indent_style = space +indent_size = 4 +charset = utf-8 diff --git a/.github/scripts/check-modified-subtree.sh b/.github/scripts/check-modified-subtree.sh index d268e98c0..8b2983fae 100755 --- a/.github/scripts/check-modified-subtree.sh +++ b/.github/scripts/check-modified-subtree.sh @@ -1,46 +1,119 @@ #!/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! + > These changes originally come from [{project}]({repository}), but are synchronized to DarkRP. + > These files should be edited in the original repositories instead. + > + {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..90c70991e 100644 --- a/.github/workflows/check-modified-subtree.yml +++ b/.github/workflows/check-modified-subtree.yml @@ -1,15 +1,20 @@ -name: check-modified-subtree +name: Check Modified Subtree + on: - pull_request: - branches: - - master + workflow_dispatch: + + 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 + 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