Add this workflow to .github/workflows/duplicate-logic.yml:
name: Duplicate Logic Detection
on:
pull_request:
paths: ['**/*.py']
jobs:
check-duplicates:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: ArthurMor4is/duplicate-logic-detector-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}- name: Detect Duplicate Logic with Custom Settings
uses: ArthurMor4is/duplicate-logic-detector-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
post-comment: true
fail-on-duplicates: false| Parameter | Description | Required | Default |
|---|---|---|---|
github-token |
GitHub token for API access | ✅ | ${{ github.token }} |
pr-number |
Pull request number | ❌ | ${{ github.event.number }} |
repository |
Repository name (owner/repo) | ❌ | ${{ github.repository }} |
base-ref |
Base reference for comparison | ❌ | ${{ github.base_ref }} |
head-ref |
Head reference for comparison | ❌ | ${{ github.head_ref }} |
post-comment |
Post findings as PR comment | ❌ | true |
fail-on-duplicates |
Fail if high-confidence duplicates found | ❌ | false |
The action automatically:
- Detects Changed Files: Identifies Python files modified in the PR
- Extracts Functions: Parses functions from changed files using AST analysis
- Compares Against Existing Code: Uses token-based Jaccard similarity
- Reports Findings: Creates detailed reports and optional PR comments
- Uploads Artifacts: Stores analysis results for review
See the examples/ directory for complete workflow examples:
basic-usage.yml- Simple setupreusable-workflow.yml- Using the reusable workflowdjango-project.yml- Django-specific configuration
The action provides these outputs:
duplicates-found: boolean - Whether duplicates were detectedmatch-count: number - Total number of matches foundreport-path: string - Path to detailed report
Use outputs in subsequent steps:
- name: Check results
if: steps.duplicates.outputs.duplicates-found == 'true'
run: |
echo "Found ${{ steps.duplicates.outputs.match-count }} duplicates"- No duplicates detected: The action uses conservative similarity thresholds by default
- Action fails: Check that your repository has Python files and proper token permissions
- Missing PR comments: Ensure
post-commentis set totrueand the token has write permissions
Enable debug logging:
env:
ACTIONS_STEP_DEBUG: trueThe action uploads analysis results as GitHub Actions artifacts:
duplicate-logic-report.json- Detailed JSON reportduplicate-logic-report.md- Human-readable Markdown report
Access these from the Actions run page under "Artifacts".
The action is designed for fast execution with minimal dependencies:
- Runtime Dependencies: Only
richfor console output - Installation Time: ~10-15 seconds using
uvpackage manager - Memory Usage: Low footprint with efficient AST analysis
- Execution Time: Typically 30-60 seconds for medium-sized repositories
The action automatically manages its dependencies using:
# Fast dependency installation with uv
- name: Install dependencies
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
export PATH="$HOME/.local/bin:$PATH"
uv pip install --system -e ".[runtime]"- Python: 3.11+ (automatically installed by the action)
- Git: Required for file change detection
- Memory: ~100MB RAM during execution
- Disk Space: ~50MB for dependencies and temporary files