Repository navigation
86 lines (75 loc) · 3.45 KB
/
Copy pathapi-compat.yml
File metadata and controls
86 lines (75 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: API compatibility
# Blocks PRs to stable branches that change the public Python API in a way that breaks
# customer code (see scripts/api_compat.py). A PR is compared with its base branch, so it
# answers only for its own changes: an approved break already merged does not fail every
# later PR. When a break is intended (e.g. a bug fix that must change the API), apply the
# `api-break-approved` label: the check still runs and lists the breaks, but passes. The
# Publish workflow compares the code it is about to release with the last release.
on:
pull_request:
branches:
- 'stable/**'
# labeled/unlabeled: re-evaluate when api-break-approved is added or removed. edited:
# re-evaluate when the PR is retargeted to another stable branch. The job must run for
# every such event: a skipped run would replace a failed one and the required check
# would count as passing.
types: [opened, synchronize, reopened, labeled, unlabeled, edited]
permissions:
contents: read
concurrency:
group: api-compat-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
api-compat:
name: API compatibility
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v6
- name: Check out the base branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.pull_request.base.sha }}
path: .api-compat-base
persist-credentials: false
- name: Install uv
uses: astral-sh/setup-uv@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version-file: "pyproject.toml"
# Both the baseline wheel and generated/ are imported to read their API, so the
# SDK's runtime dependencies must be installed.
- name: Install dependencies
run: uv sync --all-extras --dev
# Regenerate both sides from their checked-in bundled specs, so a generator change is
# checked even when its regenerated output was not committed. Upstream spec drift is
# left to the release gate, which checks what Publish actually generates.
- name: Generate SDK
run: |
make generate-only
make -C .api-compat-base generate-only
- name: Check API compatibility
env:
# stable/<N> with no N.x release yet (just cut from main) has no published API
# to protect and passes.
MAJOR: ${{ github.base_ref }}
APPROVED: ${{ contains(github.event.pull_request.labels.*.name, 'api-break-approved') }}
run: |
set -uo pipefail
released=$(uv run python scripts/api_compat.py --print-baseline-major "${MAJOR#stable/}") || exit 2
if [ -z "$released" ]; then
echo "::notice::No ${MAJOR#stable/}.x release published yet; nothing to protect."
exit 0
fi
rc=0
uv run python scripts/api_compat.py --baseline-dir .api-compat-base/generated || rc=$?
if [ "$rc" -eq 1 ] && [ "$APPROVED" = "true" ]; then
echo "::warning::Breaking API changes approved with the api-break-approved label."
echo "Approved with the \`api-break-approved\` label." >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
if [ "$rc" -eq 1 ]; then
echo "::error::If this break is intended (e.g. a bug fix that must change the API), apply the api-break-approved label. Otherwise make the change backward compatible."
fi
exit "$rc"