From ca8f3513483a03dce0b83ad6d1943150f3d1e134 Mon Sep 17 00:00:00 2001 From: DevIos01 Date: Tue, 19 Dec 2023 02:45:29 +0100 Subject: [PATCH 1/5] Revert "Trying pull_request_target instead of pull_request (Test) - Plgiarism Workflow" This reverts commit c92074edbb0eab5bbb06ac8814605987e5415a8c. --- .github/workflows/check_plagiarism.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check_plagiarism.yml b/.github/workflows/check_plagiarism.yml index 89e78da5cb..8ec0c1efb1 100644 --- a/.github/workflows/check_plagiarism.yml +++ b/.github/workflows/check_plagiarism.yml @@ -1,14 +1,11 @@ name: Plagiarism Checker on: - pull_request_target: + pull_request: paths: - "games/**/*.js" -permissions: - contents: read - issues: write - pull-requests: write +permissions: write-all jobs: plagiarism-check: @@ -18,7 +15,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - name: Set up Python From 3b30e11b04c25dd302eb8690447ca87ff32d25c3 Mon Sep 17 00:00:00 2001 From: DevIos01 Date: Tue, 19 Dec 2023 03:10:21 +0100 Subject: [PATCH 2/5] Fix For Plagiarism --- .github/workflows/check_plagiarism.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/check_plagiarism.yml b/.github/workflows/check_plagiarism.yml index 8ec0c1efb1..ae15adefc8 100644 --- a/.github/workflows/check_plagiarism.yml +++ b/.github/workflows/check_plagiarism.yml @@ -1,7 +1,7 @@ name: Plagiarism Checker on: - pull_request: + pull_request_target: paths: - "games/**/*.js" @@ -15,6 +15,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: + ref: ${{ github.event.pull_request.head.ref }} fetch-depth: 0 - name: Set up Python @@ -28,15 +29,20 @@ jobs: - name: Get list of changed files id: changed-files run: | - base_sha="${{ github.event.pull_request.base.sha }}" - head_sha="${{ github.event.pull_request.head.sha }}" + base_sha="${{ github.base_ref }}" + head_sha="${{ github.sha }}" js_files=$(git diff --name-only --diff-filter=AM $base_sha..$head_sha | grep 'games/.*\.js$' | xargs) echo "FILES=$js_files" >> $GITHUB_ENV - name: Run Plagiarism Detection Script env: FILES: ${{ env.FILES }} - run: python .github/scripts/plagiarism_check.py $FILES games output_dir saved_dir + run: | + IFS=' ' read -ra FILES_ARRAY <<< "$FILES" + for FILE in "${FILES_ARRAY[@]}"; do + python .github/scripts/plagiarism_check.py "$FILE" games output_dir saved_dir + done + shell: /usr/bin/bash -e {0} - name: Extract and Display Similarity Percentages run: python .github/scripts/extract_percentages.py saved_dir/ From 6520b50feb2f012957a056bea0fbe30d6708fae4 Mon Sep 17 00:00:00 2001 From: DevIos01 Date: Tue, 19 Dec 2023 03:21:59 +0100 Subject: [PATCH 3/5] debuged --- .github/workflows/check_plagiarism.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check_plagiarism.yml b/.github/workflows/check_plagiarism.yml index ae15adefc8..ac412edf25 100644 --- a/.github/workflows/check_plagiarism.yml +++ b/.github/workflows/check_plagiarism.yml @@ -27,12 +27,12 @@ jobs: run: pip install compare50 beautifulsoup4 - name: Get list of changed files - id: changed-files run: | base_sha="${{ github.base_ref }}" head_sha="${{ github.sha }}" js_files=$(git diff --name-only --diff-filter=AM $base_sha..$head_sha | grep 'games/.*\.js$' | xargs) echo "FILES=$js_files" >> $GITHUB_ENV + echo "Detected JS files: $js_files" - name: Run Plagiarism Detection Script env: @@ -40,6 +40,7 @@ jobs: run: | IFS=' ' read -ra FILES_ARRAY <<< "$FILES" for FILE in "${FILES_ARRAY[@]}"; do + echo "Processing file: $FILE" python .github/scripts/plagiarism_check.py "$FILE" games output_dir saved_dir done shell: /usr/bin/bash -e {0} From bb646a3e6cd6215116de7d33018c9699d697a89c Mon Sep 17 00:00:00 2001 From: Shubham Panth Date: Mon, 18 Dec 2023 21:35:57 +0100 Subject: [PATCH 4/5] Quote The File Paths To Handle Special Characters (#1314) --- .github/scripts/plagiarism_check.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/scripts/plagiarism_check.py b/.github/scripts/plagiarism_check.py index d1917aceb1..bf855003c7 100644 --- a/.github/scripts/plagiarism_check.py +++ b/.github/scripts/plagiarism_check.py @@ -24,14 +24,15 @@ def run_compare50(single_file, directory, output_dir, saved_dir_base): command = [ "compare50", - single_file, - file, - "--output", output_dir, + f'"{single_file}"', + f'"{file}"', + "--output", f'"{output_dir}"', "--max-file-size", str(1024 * 1024 * 100), "--passes", "text" ] - subprocess.run(command, check=True) + command_str = ' '.join(command) + subprocess.run(command_str, shell=True, check=True) match_file = os.path.join(output_dir, "match_1.html") From f1c6e21b0bfd74258e100e3ad3a09602fb23b118 Mon Sep 17 00:00:00 2001 From: DevIos01 Date: Tue, 19 Dec 2023 01:05:07 +0100 Subject: [PATCH 5/5] Plagiarism File Fix & Debug Logs --- .github/scripts/plagiarism_check.py | 10 ++++++++++ .github/workflows/check_plagiarism.yml | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/scripts/plagiarism_check.py b/.github/scripts/plagiarism_check.py index bf855003c7..bdf38ffdae 100644 --- a/.github/scripts/plagiarism_check.py +++ b/.github/scripts/plagiarism_check.py @@ -57,6 +57,16 @@ def main(): output_dir = sys.argv[3] saved_dir_base = sys.argv[4] + print(f"Received arguments:") + print(f"Single file: {single_file}") + print(f"Directory: {directory}") + print(f"Output directory: {output_dir}") + print(f"Saved directory base: {saved_dir_base}") + + print(f"All files in directory '{directory}':") + for f in glob.glob(os.path.join(directory, "*.js")): + print(f) + run_compare50(single_file, directory, output_dir, saved_dir_base) if __name__ == "__main__": diff --git a/.github/workflows/check_plagiarism.yml b/.github/workflows/check_plagiarism.yml index 1da9ed82c3..0c192caff1 100644 --- a/.github/workflows/check_plagiarism.yml +++ b/.github/workflows/check_plagiarism.yml @@ -31,7 +31,9 @@ jobs: echo "FILES=$js_files" >> $GITHUB_ENV - name: Run Plagiarism Detection Script - run: python .github/scripts/plagiarism_check.py ${{ env.FILES }} games output_dir saved_dir + env: + FILES: ${{ env.FILES }} + run: python .github/scripts/plagiarism_check.py $FILES games output_dir saved_dir - name: Extract and Display Similarity Percentages run: python .github/scripts/extract_percentages.py saved_dir/