CI/CD Integration
Baseline + Check Workflow (Recommended)
Section titled “Baseline + Check Workflow (Recommended)”The baseline workflow lets you record accepted clones and gate on new ones:
# Step 1: Record current clones (commit the baseline file)art-dupl baseline . -t 5
# Step 2: CI gate — exits 1 only if NEW clones are foundart-dupl check . -t 5The baseline file (.art-dupl-baseline.json) contains accepted clone signatures. New clones not in the baseline cause check to exit with code 1.
GitHub Actions
Section titled “GitHub Actions”name: Code Duplication Checkon: [push, pull_request]
jobs: clone-check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: go-version: "1.26"
- name: Install art-dupl run: go install github.com/LarsArtmann/art-dupl/cmd/art-dupl@latest
- name: Check for new clones run: art-dupl check . -t 5
- name: Generate report on failure if: failure() run: | art-dupl --html -t 5 > clone-report.html echo "::warning::New clones detected. See clone-report.html"
- name: Upload SARIF if: always() run: | art-dupl --sarif -t 5 > results.sarif
- uses: github/codeql-action/upload-sarif@v3 if: always() with: sarif_file: results.sarifA ready-made template is included at templates/github-actions-duplicate-check.yml.
SARIF Upload
Section titled “SARIF Upload”Upload clone results to the GitHub Security tab:
- name: Generate SARIF run: art-dupl --sarif -t 10 > results.sarif
- uses: github/codeql-action/upload-sarif@v3 with: sarif_file: results.sarifPre-commit Hook
Section titled “Pre-commit Hook”Using pre-commit framework
Section titled “Using pre-commit framework”A template is included at templates/pre-commit-hook.yaml:
repos: - repo: https://github.com/LarsArtmann/art-dupl rev: latest hooks: - id: art-dupl args: ["-t", "10"]Using Git hooks directly
Section titled “Using Git hooks directly”#!/bin/shecho "Running clone detection..."art-dupl --json -t 10 > /tmp/art-dupl-check.jsonCLONES=$(jq '.summary.total_clones' /tmp/art-dupl-check.json)
if [ "$CLONES" -gt 0 ]; then echo "Found $CLONES clone groups. Run 'art-dupl --html -t 10 > report.html' for details." echo "Run 'art-dupl baseline . -t 10' to accept current state." exit 1fiJSON Pipeline Integration
Section titled “JSON Pipeline Integration”# Extract clone countTOTAL=$(art-dupl --json -t 15 | jq '.summary.total_clones')
# Fail if too many clonesif [ "$TOTAL" -gt 50 ]; then echo "Too many clones: $TOTAL" exit 1fi
# List affected filesart-dupl --json -t 15 | jq -r '.clone_groups[].clones[].filename' | sort -u