Repository navigation
131 lines (115 loc) · 4.63 KB
/
Copy pathpython-api-compatibility.yml
File metadata and controls
131 lines (115 loc) · 4.63 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: Python - API Compatibility
on:
pull_request_target:
branches: ["main"]
types: [opened, synchronize, reopened, labeled, unlabeled]
paths:
- "python/**"
- ".github/scripts/check_python_api_compatibility.py"
- ".github/workflows/python-api-compatibility.yml"
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
api-compatibility:
name: Public API Compatibility
runs-on: ubuntu-latest
continue-on-error: true
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ github.event.pull_request.base.sha }}
fetch-depth: 1
persist-credentials: false
- name: Set up uv
uses: astral-sh/setup-uv@bec219d24cd3e171d82865faccec33120bb574f4 # v10.1.0
with:
enable-cache: false
version: "0.12.9"
- name: Compare public API with the PR base
working-directory: ${{ runner.temp }}
env:
BREAKING_CHANGE_ACKNOWLEDGED: ${{ contains(github.event.pull_request.labels.*.name, 'breaking change') }}
EXPECTED_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
UV_NO_CONFIG: "1"
shell: bash
run: |
skip_comparison() {
local reason="$1"
echo "::notice title=Python public API compatibility::$reason"
{
echo "## Python public API compatibility"
echo
echo "Comparison skipped: $reason"
} >> "$GITHUB_STEP_SUMMARY"
exit 0
}
set +e
git ls-remote \
--exit-code \
--refs \
"https://github.com/$GITHUB_REPOSITORY.git" \
"refs/pull/$PR_NUMBER/merge" > /dev/null
ref_status=$?
set -e
if (( ref_status == 2 )); then
skip_comparison "GitHub has not produced a synthetic merge ref for the current pull request head."
fi
if (( ref_status != 0 )); then
echo "Failed to query the pull request merge ref (exit $ref_status)." >&2
exit "$ref_status"
fi
git -C "$GITHUB_WORKSPACE" fetch \
--no-tags \
--no-recurse-submodules \
--depth=2 \
"https://github.com/$GITHUB_REPOSITORY.git" \
"refs/pull/$PR_NUMBER/merge"
MERGE_SHA="$(git -C "$GITHUB_WORKSPACE" rev-parse --verify 'FETCH_HEAD^{commit}')"
BASE_SHA="$(git -C "$GITHUB_WORKSPACE" rev-parse "$MERGE_SHA^1")"
HEAD_SHA="$(git -C "$GITHUB_WORKSPACE" rev-parse "$MERGE_SHA^2")"
if [[ "$HEAD_SHA" != "$EXPECTED_HEAD_SHA" ]]; then
skip_comparison "GitHub's synthetic merge ref is not current for pull request head $EXPECTED_HEAD_SHA."
fi
PR_SOURCE="$RUNNER_TEMP/pr-source"
mkdir "$PR_SOURCE"
git -C "$GITHUB_WORKSPACE" archive "$MERGE_SHA" python |
tar -x -C "$PR_SOURCE"
if [[ -n "$(find "$PR_SOURCE/python" -type l -print -quit)" ]]; then
echo "Refusing to analyze pull request source containing symbolic links." >&2
exit 1
fi
git -C "$GITHUB_WORKSPACE" show "$BASE_SHA:.github/scripts/check_python_api_compatibility.py" \
> "$RUNNER_TEMP/check_python_api_compatibility.py"
git -C "$GITHUB_WORKSPACE" show "$BASE_SHA:python/pyproject.toml" \
> "$RUNNER_TEMP/python-pyproject.toml"
griffe_requirement="$(
python3 - "$RUNNER_TEMP/python-pyproject.toml" <<'PY'
import sys
import tomllib
with open(sys.argv[1], "rb") as pyproject_file:
dev_dependencies = tomllib.load(pyproject_file)["dependency-groups"]["dev"]
requirements = [
dependency for dependency in dev_dependencies if dependency.startswith("griffe")
]
if len(requirements) != 1:
raise SystemExit("Expected exactly one Griffe development dependency")
print(requirements[0])
PY
)"
args=(
--base-sha "$BASE_SHA"
--current-source "$PR_SOURCE"
--repo "$GITHUB_WORKSPACE"
)
if [[ "$BREAKING_CHANGE_ACKNOWLEDGED" == "true" ]]; then
args+=(--acknowledge-breaking-changes)
fi
uv --no-config run \
--no-project \
--with "$griffe_requirement" \
python "$RUNNER_TEMP/check_python_api_compatibility.py" "${args[@]}"