diff --git a/.github/workflows/zxc-code-style.yaml b/.github/workflows/zxc-code-style.yaml index cb8ea2b8c..a80b739a1 100644 --- a/.github/workflows/zxc-code-style.yaml +++ b/.github/workflows/zxc-code-style.yaml @@ -80,4 +80,36 @@ jobs: npm ci - name: Check Code Style - run: task check + run: | + task check + mv eslint.log eslint-branch.log || true + + - name: Compare warnings with target branch + if: ${{ github.event_name == 'pull_request' }} + run: | + get_warnings() { + file="$1" + if [ -f "$file" ]; then + # Use awk to find the line containing "problems" and print the token before "warnings" + awk -F'[(), ]+' '/problems/ { for(i=1;i<=NF;i++) if($i=="warnings") print $(i-1) }' "$file" | tail -n1 + else + echo 0 + fi + } + # Determine the PR target (base) branch + target_branch="${{ github.event.pull_request.base.ref }}" + echo "Target branch: $target_branch" + # Fetch and check out the target branch from origin + git fetch origin "$target_branch":"$target_branch" + git checkout "$target_branch" + task check + branch_warnings=$(get_warnings eslint-branch.log) + target_warnings=$(get_warnings eslint.log) + echo "Warnings on branch: $branch_warnings" + echo "Warnings on target ($target_branch): $target_warnings" + if [ "$branch_warnings" -gt "$target_warnings" ]; then + echo "✘ Warnings have increased from $target_warnings to $branch_warnings" + exit 1 + else + echo "✔ Warnings have not increased" + fi