Repository navigation
105 lines (94 loc) · 3.9 KB
/
Copy pathduplicate-code.yml
File metadata and controls
105 lines (94 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: Duplicate-code audit
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- "**/*.ts"
- "**/*.tsx"
- "**/*.js"
- "**/*.jsx"
- "**/*.mjs"
- "**/*.mts"
- "!**/*.test.*"
- "!**/*.spec.*"
- "!**/__tests__/**"
- "!**/__fixtures__/**"
- "**/package.json"
- "pnpm-lock.yaml"
- ".jscpd.json"
- ".nvmrc"
- ".github/workflows/duplicate-code.yml"
schedule:
# Retain the full audit alongside the advisory PR comparisons.
- cron: "47 6 * * 3"
workflow_dispatch:
concurrency:
group: duplicate-code-${{ github.workflow }}-${{ github.event.pull_request.number && format('pr-{0}', github.event.pull_request.number) || github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
jscpd:
name: duplicated production code
runs-on: ubuntu-latest
timeout-minutes: 10
# PR findings and tool failures stay advisory; scheduled failures stay visible.
continue-on-error: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# Analyze the submitted head, with the immutable base available locally.
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0
- uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
cache: pnpm
- run: pnpm install --frozen-lockfile
- name: Audit duplicate production code
# upload-artifact skips hidden paths, so the report cannot live in the
# gitignored .jscpd-report directory local runs use.
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
comparison=()
if [ -n "$BASE_SHA" ]; then
comparison=(--baseline-from-ref "$BASE_SHA")
fi
pnpm check-duplicates "${comparison[@]}" --fail-on-empty \
--reporters ai,html,markdown,json --output "$RUNNER_TEMP/jscpd-report"
- name: Summarize duplicate-code report
if: always()
env:
BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
node --input-type=module <<'JS'
import { appendFileSync, existsSync, readFileSync } from "node:fs";
import { join } from "node:path";
const report = join(process.env.RUNNER_TEMP, "jscpd-report", "jscpd-report.json");
const base = process.env.BASE_SHA;
let summary = "## Duplicate-code audit\n\n";
if (!existsSync(report)) {
summary += "The scan did not produce a report. Check the job logs for the failure.\n";
} else {
const { statistics: { total } } = JSON.parse(readFileSync(report, "utf8"));
if (base) {
summary += `New clone regions: **${total.newClones}** against base \`${base}\`.\n\n`;
summary += `New duplicated lines: **${total.newDuplicatedLines}**.\n\n`;
summary += "This PR report is advisory and does not block merging.\n\n";
}
summary += `Full scan: ${total.clones} clone regions, ${total.duplicatedLines} duplicated lines in ${total.sources} files.\n\n`;
summary += "Download the duplicate-code-report artifact for HTML, Markdown and JSON details.\n";
}
appendFileSync(process.env.GITHUB_STEP_SUMMARY, summary);
JS
- name: Upload duplicate-code report
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: duplicate-code-report
path: ${{ runner.temp }}/jscpd-report
if-no-files-found: error
retention-days: 14