Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

CI: the git-sources check parses .cargo/config and .cargo/config.toml

aiongg7d9abd95afa9
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index f8ca27d16..6ca1e7e50 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -55,10 +55,21 @@ jobs:
run: |
set -euo pipefail
test -f Cargo.lock || { echo "Cargo.lock is missing"; exit 1; }
- # Source replacement and patches in cargo config never show up in Cargo.lock.
- if grep -qE '^[[:space:]]*(replace-with|\[patch)' .cargo/config.toml 2>/dev/null; then
- echo ".cargo/config.toml replaces or patches a source"; exit 1
- fi
+ # Source replacement, patches and path overrides in cargo config never show up
+ # in Cargo.lock. Parsed rather than grepped: TOML has many spellings of one key.
+ # Cargo still reads the legacy .cargo/config.
+ python3 - <<'PY'
+ import os, sys, tomllib
+ for path in (".cargo/config", ".cargo/config.toml"):
+ if not os.path.exists(path):
+ continue
+ config = tomllib.load(open(path, "rb"))
+ replaced = [name for name, source in config.get("source", {}).items()
+ if isinstance(source, dict) and "replace-with" in source]
+ if replaced or "patch" in config or "paths" in config:
+ print(f"{path} replaces, patches or overrides a source")
+ sys.exit(1)
+ PY
# Fails when Cargo.lock is out of date with the manifests.
cargo metadata --locked --format-version 1 > /dev/null
python3 - <<'PY'
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 99028d8a3..72b046107 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -29,10 +29,21 @@ jobs:
run: |
set -euo pipefail
test -f Cargo.lock || { echo "Cargo.lock is missing"; exit 1; }
- # Source replacement and patches in cargo config never show up in Cargo.lock.
- if grep -qE '^[[:space:]]*(replace-with|\[patch)' .cargo/config.toml 2>/dev/null; then
- echo ".cargo/config.toml replaces or patches a source"; exit 1
- fi
+ # Source replacement, patches and path overrides in cargo config never show up
+ # in Cargo.lock. Parsed rather than grepped: TOML has many spellings of one key.
+ # Cargo still reads the legacy .cargo/config.
+ python3 - <<'PY'
+ import os, sys, tomllib
+ for path in (".cargo/config", ".cargo/config.toml"):
+ if not os.path.exists(path):
+ continue
+ config = tomllib.load(open(path, "rb"))
+ replaced = [name for name, source in config.get("source", {}).items()
+ if isinstance(source, dict) and "replace-with" in source]
+ if replaced or "patch" in config or "paths" in config:
+ print(f"{path} replaces, patches or overrides a source")
+ sys.exit(1)
+ PY
# Fails when Cargo.lock is out of date with the manifests.
cargo metadata --locked --format-version 1 > /dev/null
python3 - <<'PY'