Skip to content

Commit f6f5fda

Browse files
committed
clean up script
1 parent 3d19085 commit f6f5fda

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

.github/workflows/lintdupe.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
11
const fs = require('fs/promises')
22

3+
async function getCloneCount(jsonFile) {
4+
const result = JSON.parse(await fs.readFile(jsonFile, 'utf8'))
5+
return result.statistics.total.clones
6+
}
7+
38
async function main() {
49
console.log(`In args with: ${process.argv}`)
510
const masterJson = process.argv[2]
611
const branchJson = process.argv[3]
712
console.log(`master report located at ${masterJson}`)
813
console.log(`branch report located at ${branchJson}`)
914

10-
const masterResult = JSON.parse(await fs.readFile(masterJson, 'utf8'))
11-
const branchResult = JSON.parse(await fs.readFile(branchJson, 'utf8'))
12-
13-
console.log('master')
14-
console.log(masterResult)
15-
console.log('branch')
16-
console.log(branchResult)
17-
18-
const masterClones = masterResult.statistics.total.clones
19-
const branchClones = branchResult.statistics.total.clones
15+
const masterClones = await getCloneCount(masterJson)
16+
const branchClones = await getCloneCount(branchJson)
2017

2118
console.log(`total clones on master is: ${masterClones}`)
2219
console.log(`total clones on branch is: ${branchClones}`)
2320

2421
if (masterClones < branchClones) {
25-
console.log('introducing new duplicate code!')
22+
console.log(`❌ Copy-Paste Test failed, increasing clone count by ${masterClones - branchClones}`)
2623
process.exit(1)
2724
} else {
28-
console.log('pass')
25+
console.log(`✅ Copy-Paste Test passed`)
2926
}
3027
}
3128

.github/workflows/node.js.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ jobs:
8080
git checkout ${{ github.ref }}
8181
npx jscpd --pattern "packages/**/*.ts" --ignore "**node_modules**,**dist**,**test**" --gitignore --reporters json --output branch
8282
- name: Compare clone count across master and new branch
83-
run: |
84-
node "$GITHUB_WORKSPACE/.github/workflows/lintdupe.js" master/jscpd-report.json branch/jscpd-report.json
83+
run: node "$GITHUB_WORKSPACE/.github/workflows/lintdupe.js" master/jscpd-report.json branch/jscpd-report.json
8584

8685
macos:
8786
needs: lint-commits

0 commit comments

Comments
 (0)