Skip to content

Commit 7b630ee

Browse files
authored
Add check for crates.io patches to CI (#1407)
1 parent 0c1499c commit 7b630ee

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ jobs:
9898
- name: Check Cargo.toml formatting
9999
run: taplo format --check
100100

101+
check-crates-patch:
102+
if: inputs.build_mode == 'release'
103+
runs-on: ubuntu-latest
104+
steps:
105+
- uses: actions/checkout@v6
106+
107+
- name: Ensure [patch.crates-io] is empty
108+
run: python3 dev/check_crates_patch.py
109+
101110
generate-license:
102111
runs-on: ubuntu-latest
103112
steps:

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,8 @@ crate-type = ["cdylib", "rlib"]
9191
[profile.release]
9292
lto = true
9393
codegen-units = 1
94+
95+
# We cannot publish to crates.io with any patches in the below section. Developers
96+
# must remove any entries in this section before creating a release candidate.
97+
[patch.crates-io]
98+
# datafusion = { git = "https://github.com/apache/datafusion.git", rev = "6713439497561fa74a94177e5b8632322fb7cea5" }

dev/check_crates_patch.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
19+
"""Check that no Cargo.toml files contain [patch.crates-io] entries.
20+
21+
Release builds must not depend on patched crates. During development it is
22+
common to temporarily patch crates-io dependencies, but those patches must
23+
be removed before creating a release.
24+
25+
An empty [patch.crates-io] section is allowed.
26+
"""
27+
28+
import sys
29+
from pathlib import Path
30+
31+
import tomllib
32+
33+
34+
def main() -> int:
35+
errors: list[str] = []
36+
for cargo_toml in sorted(Path().rglob("Cargo.toml")):
37+
if "target" in cargo_toml.parts:
38+
continue
39+
with Path.open(cargo_toml, "rb") as f:
40+
data = tomllib.load(f)
41+
patch = data.get("patch", {}).get("crates-io", {})
42+
if patch:
43+
errors.append(str(cargo_toml))
44+
for name, spec in patch.items():
45+
errors.append(f" {name} = {spec}")
46+
47+
if errors:
48+
print("ERROR: Release builds must not contain [patch.crates-io] entries.")
49+
print()
50+
for line in errors:
51+
print(line)
52+
print()
53+
print("Remove all [patch.crates-io] entries before creating a release.")
54+
return 1
55+
56+
print("OK: No [patch.crates-io] entries found.")
57+
return 0
58+
59+
60+
if __name__ == "__main__":
61+
sys.exit(main())

0 commit comments

Comments
 (0)