|
32 | 32 | - uses: actions/setup-node@v4 |
33 | 33 | with: |
34 | 34 | node-version: '20' |
| 35 | + - name: Validate Branch name |
| 36 | + if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref != ''}} |
| 37 | + env: |
| 38 | + BRANCH_NAME: ${{ github.event.pull_request.head.ref }} |
| 39 | + run: | |
| 40 | + node "$GITHUB_WORKSPACE/.github/workflows/lintbranch.js" run "$BRANCH_NAME" |
35 | 41 | - name: Check PR title |
36 | 42 | run: | |
37 | 43 | node "$GITHUB_WORKSPACE/.github/workflows/lintcommit.js" |
|
55 | 61 | - run: npm run testCompile |
56 | 62 | - run: npm run lint |
57 | 63 |
|
| 64 | + jscpd: |
| 65 | + needs: lint-commits |
| 66 | + if: ${{ github.event_name == 'pull_request'}} |
| 67 | + runs-on: ubuntu-latest |
| 68 | + strategy: |
| 69 | + matrix: |
| 70 | + node-version: [18.x] |
| 71 | + env: |
| 72 | + NODE_OPTIONS: '--max-old-space-size=8192' |
| 73 | + |
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v4 |
| 76 | + with: |
| 77 | + fetch-depth: 0 |
| 78 | + |
| 79 | + - name: Use Node.js ${{ matrix.node-version }} |
| 80 | + uses: actions/setup-node@v4 |
| 81 | + with: |
| 82 | + node-version: ${{ matrix.node-version }} |
| 83 | + |
| 84 | + - name: Fetch fork upstream |
| 85 | + env: |
| 86 | + REPO_NAME: ${{ github.event.pull_request.head.repo.full_name }} |
| 87 | + run: | |
| 88 | + git remote add forkUpstream https://github.com/$REPO_NAME # URL of the fork |
| 89 | + git fetch forkUpstream # Fetch fork |
| 90 | +
|
| 91 | + - name: Compute git diff |
| 92 | + env: |
| 93 | + CURRENT_BRANCH: ${{ github.head_ref }} |
| 94 | + TARGET_BRANCH: ${{ github.event.pull_request.base.ref }} |
| 95 | + run: git diff --name-only origin/$TARGET_BRANCH forkUpstream/$CURRENT_BRANCH > diff_output.txt |
| 96 | + |
| 97 | + - run: npm install -g jscpd |
| 98 | + |
| 99 | + - run: jscpd --config "$GITHUB_WORKSPACE/.github/workflows/jscpd.json" |
| 100 | + |
| 101 | + - if: always() |
| 102 | + uses: actions/upload-artifact@v4 |
| 103 | + with: |
| 104 | + name: unfiltered-jscpd-report |
| 105 | + path: ./jscpd-report.json |
| 106 | + |
| 107 | + - name: Filter jscpd report for changed files |
| 108 | + run: | |
| 109 | + if [ ! -f ./jscpd-report.json ]; then |
| 110 | + echo "jscpd-report.json not found" |
| 111 | + exit 1 |
| 112 | + fi |
| 113 | + echo "Filtering jscpd report for changed files..." |
| 114 | + CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' diff_output.txt) |
| 115 | + echo "Changed files: $CHANGED_FILES" |
| 116 | + jq --argjson changed_files "$CHANGED_FILES" ' |
| 117 | + .duplicates | map(select( |
| 118 | + (.firstFile?.name as $fname | $changed_files | any(. == $fname)) or |
| 119 | + (.secondFile?.name as $sname | $changed_files | any(. == $sname)) |
| 120 | + )) |
| 121 | + ' ./jscpd-report.json > filtered-jscpd-report.json |
| 122 | + cat filtered-jscpd-report.json |
| 123 | +
|
| 124 | + - name: Check for duplicates |
| 125 | + run: | |
| 126 | + if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then |
| 127 | + echo "filtered_report_exists=true" >> $GITHUB_ENV |
| 128 | + else |
| 129 | + echo "filtered_report_exists=false" >> $GITHUB_ENV |
| 130 | + fi |
| 131 | + - name: upload filtered report (if applicable) |
| 132 | + if: env.filtered_report_exists == 'true' |
| 133 | + uses: actions/upload-artifact@v4 |
| 134 | + with: |
| 135 | + name: filtered-jscpd-report |
| 136 | + path: ./filtered-jscpd-report.json |
| 137 | + |
| 138 | + - name: Fail and log found duplicates. |
| 139 | + if: env.filtered_report_exists == 'true' |
| 140 | + run: | |
| 141 | + cat ./filtered-jscpd-report.json |
| 142 | + echo "Duplications found, failing the check." |
| 143 | + exit 1 |
| 144 | +
|
58 | 145 | macos: |
59 | 146 | needs: lint-commits |
60 | 147 | name: test macOS |
|
84 | 171 | env: |
85 | 172 | # Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475 |
86 | 173 | NODE_OPTIONS: '' |
87 | | - if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }} |
| 174 | + if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.event_name == 'pull_request' && github.base_ref == 'master' }} |
88 | 175 | uses: codecov/codecov-action@v5 |
89 | 176 | with: |
90 | 177 | flags: macos-toolkit-unittests |
|
95 | 182 | env: |
96 | 183 | # Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475 |
97 | 184 | NODE_OPTIONS: '' |
98 | | - if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }} |
| 185 | + if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.event_name == 'pull_request' && github.base_ref == 'master' }} |
99 | 186 | uses: codecov/codecov-action@v5 |
100 | 187 | with: |
101 | 188 | flags: macos-amazonq-unittests |
@@ -154,7 +241,7 @@ jobs: |
154 | 241 | env: |
155 | 242 | # Unset NODE_OPTIONS because of https://github.com/codecov/uploader/issues/475 |
156 | 243 | NODE_OPTIONS: '' |
157 | | - if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.ref == 'master' }} |
| 244 | + if: ${{ github.repository == 'aws/aws-toolkit-vscode' && github.event_name == 'pull_request' && github.base_ref == 'master' }} |
158 | 245 | uses: codecov/codecov-action@v5 |
159 | 246 | with: |
160 | 247 | flags: windows-unittests |
|
0 commit comments