Skip to content

ci: add sem semantic diff to pre-commit and PR review #1

ci: add sem semantic diff to pre-commit and PR review

ci: add sem semantic diff to pre-commit and PR review #1

Workflow file for this run

name: Semantic Diff Review
on:
pull_request:
branches: [main]
permissions:
contents: read
pull-requests: write
env:
CARGO_TERM_COLOR: always
CARGO_NET_RETRY: 10
CARGO_INCREMENTAL: 0
jobs:
sem-diff:
name: Semantic Diff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
fetch-depth: 0
persist-credentials: false
- uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable
- uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
with:
prefix-key: sem
- name: Install system dependencies
run: sudo apt-get update && sudo apt-get install -y libgit2-dev
- name: Install sem
run: |
git clone --depth 1 https://github.com/Ataraxy-Labs/sem /tmp/sem
cargo install --path /tmp/sem/crates/sem-cli
- name: Run semantic diff
id: sem
run: |
BASE_SHA="${{ github.event.pull_request.base.sha }}"
HEAD_SHA="${{ github.event.pull_request.head.sha }}"
DIFF_OUTPUT=$(sem diff --from "$BASE_SHA" --to "$HEAD_SHA" --file-exts .rs 2>&1 || true)
JSON_OUTPUT=$(sem diff --from "$BASE_SHA" --to "$HEAD_SHA" --file-exts .rs --format json 2>&1 || true)
# Check for deleted entities
DELETED=""
if echo "$JSON_OUTPUT" | jq -e '.changes[]? | select(.kind == "deleted")' > /dev/null 2>&1; then
DELETED=$(echo "$JSON_OUTPUT" | jq -r '[.changes[] | select(.kind == "deleted") | "- ⊖ \(.entity_type) `\(.name)`"] | join("\n")' 2>/dev/null || true)
fi
{
echo "diff<<SEMEOF"
echo "$DIFF_OUTPUT"
echo "SEMEOF"
echo "deleted<<DEOF"
echo "$DELETED"
echo "DEOF"
} >> "$GITHUB_OUTPUT"
- name: Post PR comment
if: steps.sem.outputs.diff != ''
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4
with:
header: sem-diff
message: |
## Semantic Diff
Entity-level changes detected by [`sem`](https://github.com/Ataraxy-Labs/sem):
```
${{ steps.sem.outputs.diff }}
```
${{ steps.sem.outputs.deleted != '' && format('### ⚠️ Deleted Entities\n\n{0}', steps.sem.outputs.deleted) || '' }}