Skip to content

Add a script to check for breaking C ABI changes #3

Add a script to check for breaking C ABI changes

Add a script to check for breaking C ABI changes #3

Workflow file for this run

name: C ABI Compatibility Check (PR)
on:
workflow_call:
pull_request:
paths:
- 'c/include/**'
- 'ci/check_c_abi/**'
- '.github/workflows/check-c-abi-pr.yaml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
check-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install ci/check_c_abi
- name: Get dlpack dependency
run: |
git clone https://github.com/dmlc/dlpack
- name: Find merge base commit
id: merge-base
run: |
git fetch origin main
MERGE_BASE=$(git merge-base HEAD origin/main)
echo "merge_base_sha=${MERGE_BASE}" >> $GITHUB_OUTPUT
echo "Merge base commit: ${MERGE_BASE}"
- name: Checkout baselines branch
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
ref: baselines
path: baselines-repo
continue-on-error: true # Branch may not exist yet in new repos
- name: Get baseline from baselines branch
id: get-baseline
continue-on-error: true
run: |
mkdir -p baseline
MERGE_BASE="${{ steps.merge-base.outputs.merge_base_sha }}"
if [ ! -d baselines-repo/c-abi-baselines ]; then
exit 1
fi
if [ -f "baselines-repo/c-abi-baselines/c_abi_${MERGE_BASE}.json.gz" ]; then
cp "baselines-repo/c-abi-baselines/c_abi_${MERGE_BASE}.json.gz" baseline/c_abi.json.gz
echo "source=merge-base" >> $GITHUB_OUTPUT
elif [ -f baselines-repo/c-abi-baselines/c_abi_main.json.gz ]; then
cp baselines-repo/c-abi-baselines/c_abi_main.json.gz baseline/c_abi.json.gz
echo "source=main" >> $GITHUB_OUTPUT
else
exit 1
fi
- name: Extract baseline ABI from main branch (fallback)
if: steps.get-baseline.outcome == 'failure'
run: |
echo "⚠️ No baseline on baselines branch, extracting from main..."
git worktree add ../cuvs-main main
mkdir -p baseline
check-c-abi extract \
--header-path ../cuvs-main/c/include \
--include-file cuvs/core/all.h \
--output-file baseline/c_abi.json.gz \
--dlpack-include-path dlpack/include
echo "✓ Baseline ABI extracted from main branch"
- name: Report baseline source
run: |
if [ "${{ steps.get-baseline.outputs.source }}" == "merge-base" ]; then
echo "✓ Using baseline from merge-base commit: ${{ steps.merge-base.outputs.merge_base_sha }}"
elif [ "${{ steps.get-baseline.outputs.source }}" == "main" ]; then
echo "✓ Using latest main baseline from baselines branch"
else
echo "✓ Using freshly extracted baseline from main branch"
fi
- name: Analyze current branch for ABI breaking changes
run: |
check-c-abi analyze \
--abi-file baseline/c_abi.json.gz \
--header-path c/include \
--include-file cuvs/core/all.h \
--dlpack-include-path dlpack/include
- name: Comment on PR with results
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ⚠️ C ABI Breaking Changes Detected
This PR introduces breaking changes to the C ABI. Please review the changes carefully.
Breaking ABI changes are only allowed in major releases. If this is intentional for a major release,
the baseline ABI will need to be updated after merge.
See the job logs for details on what specific changes were detected.
### What are breaking ABI changes?
Breaking ABI changes include:
- Removing functions from the public API
- Changing function signatures (parameters or return types)
- Removing struct members or changing their types
- Removing or changing enum values
### Next steps
1. Review the changes flagged in the CI logs
2. If these changes are unintentional, update your PR to maintain ABI compatibility
3. If these changes are required, ensure:
- This is part of a major version release
- The changes are documented in the changelog
- Migration guide is provided for users
For more information, see the [C ABI documentation](../docs/source/c_developer_guide.md).`
});