Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
DevIos01 authored Dec 22, 2023
2 parents 76a7533 + 312162b commit d05aa3d
Show file tree
Hide file tree
Showing 11 changed files with 1,459 additions and 11 deletions.
19 changes: 16 additions & 3 deletions .github/scripts/extract_percentages.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ def extract_similarity_percentage(html_file):
def process_html_files(directory, threshold=50):
log("Processing HTML files for plagiarism results...")
high_plagiarism_detected = False
high_plagiarism_files = []
for filename in os.listdir(directory):
if filename.endswith(".html"):
file_path = os.path.join(directory, filename)
percentage = extract_similarity_percentage(file_path)
if percentage is not None and percentage >= threshold:
log(f"High plagiarism detected - {filename.replace('.html', '.js')}: {percentage}%")
high_plagiarism_files.append(filename.replace('.html', '.js') + ": " + str(percentage) + "%")
high_plagiarism_detected = True
return high_plagiarism_detected, high_plagiarism_files

return high_plagiarism_detected
def write_to_markdown(file_path, lines):
with open(file_path, 'w') as md_file:
for line in lines:
md_file.write(line + '\n')

def main():
if len(sys.argv) != 2:
Expand All @@ -41,12 +47,19 @@ def main():
sys.exit(1)

saved_dir_path = sys.argv[1]
log(f"Received saved directory path: {saved_dir_path}")
if process_html_files(saved_dir_path):
high_plagiarism_detected, high_plagiarism_files = process_html_files(saved_dir_path)

markdown_lines = ["# Plagiarism Report"]
if high_plagiarism_detected:
log("High plagiarism percentages detected.")
markdown_lines.append("## High plagiarism percentages detected in the following files:")
markdown_lines.extend(high_plagiarism_files)
write_to_markdown("plagiarism_report.md", markdown_lines)
sys.exit(1)
else:
log("No high plagiarism percentages detected.")
markdown_lines.append("No high plagiarism percentages detected.")
write_to_markdown("plagiarism_report.md", markdown_lines)

if __name__ == "__main__":
main()
25 changes: 20 additions & 5 deletions .github/workflows/check_plagiarism.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,21 @@ 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 }}"
js_files=$(git diff --name-only --diff-filter=AM $base_sha..$head_sha | grep 'games/.*\.js$' | xargs)
echo "FILES=$js_files" >> $GITHUB_ENV
echo "Pull Request Base SHA: ${{ github.event.pull_request.base.sha }}"
echo "Pull Request Head SHA: ${{ github.event.pull_request.head.sha }}"
echo "Running git diff..."
git diff --name-only --diff-filter=AM --find-renames --find-copies ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
echo "Filtering JS files in games/ directory..."
js_files=$(git diff --name-only --diff-filter=AM --find-renames --find-copies ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | grep 'games/.*\.js$' | xargs)
echo "Found JS files: $js_files"
if [ -z "$js_files" ]; then
echo "No JavaScript files found in the changes."
else
echo "FILES=$js_files" >> $GITHUB_ENV
fi
- name: Run Plagiarism Detection Script
if: env.FILES != ''
run: python .github/scripts/plagiarism_check.py ${{ env.FILES }} games output_dir saved_dir

- name: Extract and Display Similarity Percentages
Expand All @@ -45,6 +54,12 @@ jobs:
name: compare50-results
path: saved_dir/

- name: Upload Plagiarism Report as Artifact
uses: actions/upload-artifact@v3
with:
name: plagiarism-report
path: plagiarism_report.md

- name: Check for High Plagiarism Percentages
if: steps.extract-percentages.outcome == 'failure'
run: echo "Plagiarism percentage over threshold detected."
76 changes: 76 additions & 0 deletions .github/workflows/workflow_run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Send Plagiarism Result On CI Complete

permissions:
actions: read
contents: read

on:
workflow_run:
workflows: ["Plagiarism Checker"]
types:
- completed

jobs:
on_pr_finish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Download Plagiarism Report Artifact
uses: actions/download-artifact@v3
with:
name: plagiarism-report

- name: Post Markdown as Comment
uses: actions/github-script@v7
env:
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const path = require('path');
console.log("Reading the Markdown report from the artifact...");
const markdownContent = fs.readFileSync(path.join(process.env.GITHUB_WORKSPACE, 'plagiarism_report.md'), 'utf8');
console.log("Fetching associated workflow run...");
const runId = process.env.WORKFLOW_RUN_ID;
console.log(`Looking for workflow run with ID: ${runId}`);
const runs = await github.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'check_plagiarism',
});
console.log(`Workflow runs fetched: ${runs.data.total_count}`);
runs.data.workflow_runs.forEach(run => {
console.log(`Run ID: ${run.id}, Name: ${run.name}, Event: ${run.event}, Status: ${run.status}`);
});
const associatedRun = runs.data.workflow_runs.find(run => run.id == runId);
if (!associatedRun) {
console.log("No associated workflow run found.");
return;
}
console.log(`Operating on workflow: ${associatedRun.name}, ID: ${associatedRun.id}`);
if (!associatedRun.pull_requests || associatedRun.pull_requests.length == 0) {
console.log("No associated pull request found for this workflow run.");
return;
}
const prNumber = associatedRun.pull_requests[0].number;
console.log(`Found associated pull request: #${prNumber}`);
console.log("Posting the Markdown content as a comment...");
await github.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: markdownContent
});
console.log("Comment posted successfully.");
Loading

0 comments on commit d05aa3d

Please sign in to comment.