Skip to content

Commit 2f86d46

Browse files
Add workflow to test OpenZeppelin contracts (#1595)
### What Add GitHub Actions workflow to test OpenZeppelin Stellar contracts against the SDK. The workflow checks out both repositories, patches Cargo.toml files to use local SDK versions, builds contracts for wasm32v1-none target, and runs the contract test suite. ### Why This acts as an early canary-like test to alert us to changes to the SDK that break contracts out there that people are building on the SDK. This is similar to the test with soroban-examples that was added in #1591. For #1544
1 parent a288232 commit 2f86d46

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Test with OpenZeppelin Contracts
2+
3+
on:
4+
push:
5+
branches: [main, release/**]
6+
pull_request:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
10+
cancel-in-progress: true
11+
12+
# No permissions. This workflow downloads code from outside this repository and
13+
# compiles it. No permissions ensures that any exploit in an external
14+
# repository does not gain access to anything in this repo.
15+
permissions: {}
16+
17+
jobs:
18+
collect-crates:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v5
22+
with:
23+
repository: OpenZeppelin/stellar-contracts
24+
ref: main
25+
- name: Find workspace member Cargo.toml files.
26+
id: dirs
27+
run: |
28+
dirs=$(cargo metadata --no-deps --format-version 1 | jq -r --arg pwd "$(pwd)" '.workspace_members[] as $id | .packages[] | select(.id == $id) | .manifest_path | sub("^\($pwd)/"; "") | sub("/Cargo.toml$"; "")' | jq -Rnc '[inputs | "\(.)"]')
29+
echo "dirs=$dirs" | tee -a $GITHUB_OUTPUT
30+
outputs:
31+
dirs: ${{ steps.dirs.outputs.dirs }}
32+
33+
test-crate:
34+
needs: collect-crates
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
working-directory: ${{ fromJSON(needs.collect-crates.outputs.dirs) }}
39+
defaults:
40+
run:
41+
working-directory: stellar-contracts/${{ matrix.working-directory }}
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Checkout rs-soroban-sdk
45+
uses: actions/checkout@v5
46+
with:
47+
path: rs-soroban-sdk
48+
49+
- name: Checkout OpenZeppelin stellar-contracts
50+
uses: actions/checkout@v5
51+
with:
52+
repository: OpenZeppelin/stellar-contracts
53+
ref: main
54+
path: stellar-contracts
55+
56+
- name: Install Rust
57+
run: |
58+
rustup update
59+
rustup target add wasm32v1-none
60+
61+
- uses: stellar/actions/rust-cache@main
62+
63+
- name: Check if should be built as a contract
64+
id: check-if-contract
65+
run: |
66+
is_a_contract=$(cargo metadata --no-deps --format-version 1 | jq -r --arg pwd "$(pwd)" '.packages[] | select(.manifest_path == "\($pwd)/Cargo.toml") | (any(.dependencies[]; .name == "soroban-sdk") and any(.targets[]; any(.crate_types[]; . == "cdylib")))')
67+
echo "is-a-contract=$is_a_contract" | tee -a $GITHUB_OUTPUT
68+
69+
- name: Patch workspace dependencies
70+
working-directory: stellar-contracts
71+
run: |
72+
crates=$(cd ../rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
73+
for crate in $crates; do
74+
rel_path=$(realpath --relative-to="." ../rs-soroban-sdk/$crate)
75+
sed -i 's|'"$crate"' = "\([^"]*\)"|'"$crate"' = { path = "'"$rel_path"'" }|g' Cargo.toml
76+
sed -i 's|'"$crate"' = { \(.*\)version = "[^"]*"\(.*\)|'"$crate"' = { \1path = "'"$rel_path"'" \2|g' Cargo.toml
77+
done
78+
79+
- name: Diff
80+
run: (! git diff --exit-code) || (echo 'A diff is expected'; exit 1)
81+
82+
- name: Build contract
83+
if: steps.check-if-contract.outputs.is-a-contract == 'true'
84+
env:
85+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
86+
run: cargo build --target wasm32v1-none --release
87+
88+
- name: Set artifact name
89+
if: steps.check-if-contract.outputs.is-a-contract == 'true'
90+
id: artifact-name
91+
run: echo "name=wasm-$(echo ${{ matrix.working-directory }} | sed 's/\//-/g')" | tee -a $GITHUB_OUTPUT
92+
93+
- name: Upload WASM artifacts
94+
if: steps.check-if-contract.outputs.is-a-contract == 'true'
95+
uses: actions/upload-artifact@v4
96+
with:
97+
name: ${{ steps.artifact-name.outputs.name }}
98+
path: 'stellar-contracts/target/wasm32v1-none/release/*.wasm'
99+
retention-days: 3
100+
101+
- env:
102+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
103+
run: cargo test
104+
105+
- name: Diff
106+
run: git add -N . && git diff HEAD

0 commit comments

Comments
 (0)