Skip to content

Commit f74b79a

Browse files
ci: harden transitive soroban-sdk patch for OpenZeppelin build
Address review feedback on the [patch.crates-io] step: - Guard the [patch.crates-io] header so it is not emitted twice if the OpenZeppelin workspace ever declares its own, which would be invalid TOML. - Only append the section when there are crates to patch. - Derive crate directories from manifest_path instead of assuming the package name matches the directory name, in both the workspace and transitive patch. - Collect the crate list once and reuse it, avoiding a second cargo metadata resolver pass per matrix job.
1 parent daffe58 commit f74b79a

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

.github/workflows/test-with-openzeppelin-stellar-contracts.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ jobs:
7070
- name: Patch workspace dependencies
7171
working-directory: stellar-contracts
7272
run: |
73-
crates=$(cd ../rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
74-
for crate in $crates; do
75-
rel_path=$(realpath --relative-to="." ../rs-soroban-sdk/$crate)
73+
# Collect the publishable rs-soroban-sdk crates and their directories once,
74+
# from the authoritative cargo metadata, deriving the path from manifest_path
75+
# rather than assuming the package name matches the directory name. The list is
76+
# reused by the "Patch transitive crates.io dependencies" step below.
77+
(cd ../rs-soroban-sdk && cargo metadata --format-version 1 --no-deps) \
78+
| jq -r '.packages[] | select(.publish != []) | "\(.name)\t\(.manifest_path | sub("/Cargo.toml$"; ""))"' \
79+
> "$RUNNER_TEMP/sdk-crates.tsv"
80+
while IFS=$'\t' read -r crate dir; do
81+
rel_path=$(realpath --relative-to="." "$dir")
7682
sed -i 's|'"$crate"' = "\([^"]*\)"|'"$crate"' = { path = "'"$rel_path"'" }|g' Cargo.toml
7783
sed -i 's|'"$crate"' = { \(.*\)version = "[^"]*"\(.*\)|'"$crate"' = { \1path = "'"$rel_path"'" \2|g' Cargo.toml
78-
done
84+
done < "$RUNNER_TEMP/sdk-crates.tsv"
7985
8086
- name: Enable experimental_spec_shaking_v2 feature
8187
if: matrix.experimental_spec_shaking_v2
@@ -95,13 +101,15 @@ jobs:
95101
# linked, producing duplicate `panic_impl` lang item errors (E0152, #1723).
96102
# A [patch.crates-io] table redirects transitive copies to the local checkout
97103
# (valid while the local version is semver-compatible with the required one).
98-
crates=$(cd ../rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
99-
echo "" >> Cargo.toml
100-
echo "[patch.crates-io]" >> Cargo.toml
101-
for crate in $crates; do
102-
rel_path=$(realpath --relative-to="." ../rs-soroban-sdk/$crate)
103-
echo "$crate = { path = \"$rel_path\" }" >> Cargo.toml
104-
done
104+
# Reuse the crate list collected in the "Patch workspace dependencies" step.
105+
if [ -s "$RUNNER_TEMP/sdk-crates.tsv" ]; then
106+
# Don't emit a second [patch.crates-io] header if one already exists upstream.
107+
grep -q '^\[patch.crates-io\]' Cargo.toml || printf '\n[patch.crates-io]\n' >> Cargo.toml
108+
while IFS=$'\t' read -r crate dir; do
109+
rel_path=$(realpath --relative-to="." "$dir")
110+
echo "$crate = { path = \"$rel_path\" }" >> Cargo.toml
111+
done < "$RUNNER_TEMP/sdk-crates.tsv"
112+
fi
105113
106114
- name: Diff
107115
run: (! git diff --exit-code) || (echo 'A diff is expected'; exit 1)

0 commit comments

Comments
 (0)