-
Notifications
You must be signed in to change notification settings - Fork 737
ci(lint): expand jscpd to use branch comparison #5862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
ca3c3ec
implement dynamic branch comparison technique
Hweinstock e7357c0
add clone on purpose
Hweinstock 0f89bcb
decrease min line threshold
Hweinstock 1b5c45c
undo intentional change
Hweinstock a8e4860
copy paste method to another file
Hweinstock 53d3973
remove cloned method
Hweinstock c20f035
merge in master
Hweinstock 6cc3651
adjust threshold
Hweinstock c77d7ce
undo config change
Hweinstock 868f8f2
rename step in CI
Hweinstock e447610
try to remove extra dep
Hweinstock 281beab
change to run on pull request event only
Hweinstock e270d24
Merge branch 'master' into lint/noCopyPaste2
Hweinstock c813b63
remove cancel
Hweinstock 3c9efa8
remove types node + comment
Hweinstock 9eacfb6
Merge branch 'master' into lint/noCopyPaste2
Hweinstock edc09f3
increase threshold
Hweinstock 115d6bd
Merge branch 'master' into lint/noCopyPaste2
Hweinstock 75cb2d6
ignore scripts
Hweinstock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # github actions: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-nodejs | ||
| # setup-node: https://github.com/actions/setup-node | ||
|
|
||
| name: Copy-Paste Detection | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [master, feature/*, staging] | ||
|
|
||
| jobs: | ||
| jscpd: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| node-version: [18.x] | ||
| env: | ||
| NODE_OPTIONS: '--max-old-space-size=8192' | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Use Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
|
|
||
| - name: Fetch fork upstream | ||
| run: | | ||
| git remote add forkUpstream https://github.com/${{ github.event.pull_request.head.repo.full_name }} # URL of the fork | ||
| git fetch forkUpstream # Fetch fork | ||
|
|
||
| - name: Determine base and target branches for comparison. | ||
| run: | | ||
| echo "CURRENT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV | ||
| echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV | ||
| - run: git diff --name-only origin/$TARGET_BRANCH forkUpstream/$CURRENT_BRANCH > diff_output.txt | ||
| - run: | | ||
| npm install -g jscpd | ||
|
|
||
| - run: jscpd --config "$GITHUB_WORKSPACE/.github/workflows/jscpd.json" | ||
|
|
||
| - if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: unfiltered-jscpd-report | ||
| path: ./jscpd-report.json | ||
|
|
||
| - name: Filter jscpd report for changed files | ||
| run: | | ||
| if [ ! -f ./jscpd-report.json ]; then | ||
| echo "jscpd-report.json not found" | ||
| exit 1 | ||
| fi | ||
| echo "Filtering jscpd report for changed files..." | ||
| CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' diff_output.txt) | ||
| echo "Changed files: $CHANGED_FILES" | ||
| jq --argjson changed_files "$CHANGED_FILES" ' | ||
| .duplicates | map(select( | ||
| (.firstFile?.name as $fname | $changed_files | any(. == $fname)) or | ||
| (.secondFile?.name as $sname | $changed_files | any(. == $sname)) | ||
| )) | ||
| ' ./jscpd-report.json > filtered-jscpd-report.json | ||
| cat filtered-jscpd-report.json | ||
|
|
||
| - name: Check for duplicates | ||
| run: | | ||
| if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then | ||
| echo "filtered_report_exists=true" >> $GITHUB_ENV | ||
| else | ||
| echo "filtered_report_exists=false" >> $GITHUB_ENV | ||
| fi | ||
| - name: upload filtered report (if applicable) | ||
| if: env.filtered_report_exists == 'true' | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: filtered-jscpd-report | ||
| path: ./filtered-jscpd-report.json | ||
|
|
||
| - name: Fail and log found duplicates. | ||
| if: env.filtered_report_exists == 'true' | ||
| run: | | ||
| cat ./filtered-jscpd-report.json | ||
| echo "Duplications found, failing the check." | ||
| exit 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| { | ||
| "pattern": "packages/**/*.ts", | ||
| "ignore": ["**node_modules**", "**dist**"], | ||
| "ignore": ["**node_modules**", "**dist**", "*/scripts/*"], | ||
| "gitignore": true, | ||
| "threshold": 1.34, | ||
| "minLines": 15 | ||
| "threshold": 3.0, | ||
| "minLines": 3, | ||
| "output": "./", | ||
| "reporters": ["json"] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be
**/scripts/**There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, verified you are correct. Here's the followup: #5930