Skip to content
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

[ Maintenance ] Reworked Dependency Checker #3256

Merged
merged 7 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .editorconfig
FPtje marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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
137 changes: 105 additions & 32 deletions .github/scripts/check-modified-subtree.sh
Original file line number Diff line number Diff line change
@@ -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"
PhoneDroid marked this conversation as resolved.
Show resolved Hide resolved
)


# 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
31 changes: 18 additions & 13 deletions .github/workflows/check-modified-subtree.yml
Original file line number Diff line number Diff line change
@@ -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
Loading