Skip to content

ci(jscpd): check changed lines instead of changed files to avoid false positives #195

ci(jscpd): check changed lines instead of changed files to avoid false positives

ci(jscpd): check changed lines instead of changed files to avoid false positives #195

# 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: Determine if local
run: echo "IS_LOCAL=false" >> $GITHUB_ENV
- name: Fetch fork upstream
if: ${{ env.IS_LOCAL == 'false' }}
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: |
if [[ $IS_LOCAL == 'false' ]]; then
echo "CURRENT_BRANCH=${{ github.head_ref }}" >> $GITHUB_ENV
echo "TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
else
echo "CURRENT_BRANCH=${{ github.ref_name }}" >> $GITHUB_ENV
echo "TARGET_BRANCH=master" >> $GITHUB_ENV
fi
- name: Print base and target branches for comparison.
run: |
echo "CURRENT_BRANCH=$CURRENT_BRANCH"
echo "TARGET_BRANCH=$TARGET_BRANCH"
- name: Compare target and current branches.
run: |
if [[ $IS_LOCAL == 'false' ]]; then
git diff origin/$TARGET_BRANCH forkUpstream/$CURRENT_BRANCH > diff_output.txt
else
git diff origin/$TARGET_BRANCH $CURRENT_BRANCH > diff_output.txt
fi
- run: npm install -g jscpd
- run: jscpd --config "$GITHUB_WORKSPACE/.github/workflows/jscpd.json"
- if: ${{ env.IS_LOCAL == 'false' }}
uses: actions/upload-artifact@v4
with:
name: unfiltered-jscpd-report
path: ./jscpd-report.json
- name: Check for duplicates
run: node "$GITHUB_WORKSPACE/.github/workflows/filterDuplicates.js" diff_output.txt jscpd-report.json