|
| 1 | +name: Semantic Diff Review |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + pull-requests: write |
| 10 | + |
| 11 | +env: |
| 12 | + CARGO_TERM_COLOR: always |
| 13 | + CARGO_NET_RETRY: 10 |
| 14 | + CARGO_INCREMENTAL: 0 |
| 15 | + |
| 16 | +jobs: |
| 17 | + sem-diff: |
| 18 | + name: Semantic Diff |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + persist-credentials: false |
| 25 | + |
| 26 | + - uses: dtolnay/rust-toolchain@631a55b12751854ce901bb631d5902ceb48146f7 # stable |
| 27 | + |
| 28 | + - uses: Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2 |
| 29 | + with: |
| 30 | + prefix-key: sem |
| 31 | + |
| 32 | + - name: Install system dependencies |
| 33 | + run: sudo apt-get update && sudo apt-get install -y libgit2-dev |
| 34 | + |
| 35 | + - name: Install sem |
| 36 | + run: | |
| 37 | + git clone --depth 1 https://github.com/Ataraxy-Labs/sem /tmp/sem |
| 38 | + cargo install --path /tmp/sem/crates/sem-cli |
| 39 | +
|
| 40 | + - name: Run semantic diff |
| 41 | + id: sem |
| 42 | + run: | |
| 43 | + BASE_SHA="${{ github.event.pull_request.base.sha }}" |
| 44 | + HEAD_SHA="${{ github.event.pull_request.head.sha }}" |
| 45 | +
|
| 46 | + DIFF_OUTPUT=$(sem diff --from "$BASE_SHA" --to "$HEAD_SHA" --file-exts .rs 2>&1 || true) |
| 47 | + JSON_OUTPUT=$(sem diff --from "$BASE_SHA" --to "$HEAD_SHA" --file-exts .rs --format json 2>&1 || true) |
| 48 | +
|
| 49 | + # Check for deleted entities |
| 50 | + DELETED="" |
| 51 | + if echo "$JSON_OUTPUT" | jq -e '.changes[]? | select(.kind == "deleted")' > /dev/null 2>&1; then |
| 52 | + DELETED=$(echo "$JSON_OUTPUT" | jq -r '[.changes[] | select(.kind == "deleted") | "- ⊖ \(.entity_type) `\(.name)`"] | join("\n")' 2>/dev/null || true) |
| 53 | + fi |
| 54 | +
|
| 55 | + { |
| 56 | + echo "diff<<SEMEOF" |
| 57 | + echo "$DIFF_OUTPUT" |
| 58 | + echo "SEMEOF" |
| 59 | + echo "deleted<<DEOF" |
| 60 | + echo "$DELETED" |
| 61 | + echo "DEOF" |
| 62 | + } >> "$GITHUB_OUTPUT" |
| 63 | +
|
| 64 | + - name: Post PR comment |
| 65 | + if: steps.sem.outputs.diff != '' |
| 66 | + uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2.9.4 |
| 67 | + with: |
| 68 | + header: sem-diff |
| 69 | + message: | |
| 70 | + ## Semantic Diff |
| 71 | +
|
| 72 | + Entity-level changes detected by [`sem`](https://github.com/Ataraxy-Labs/sem): |
| 73 | +
|
| 74 | + ``` |
| 75 | + ${{ steps.sem.outputs.diff }} |
| 76 | + ``` |
| 77 | +
|
| 78 | + ${{ steps.sem.outputs.deleted != '' && format('### ⚠️ Deleted Entities\n\n{0}', steps.sem.outputs.deleted) || '' }} |
0 commit comments