Skip to content

Commit 72c9593

Browse files
add workflow to test OpenZeppelin contracts with sdk
1 parent 6aa930b commit 72c9593

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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+
permissions: {} # No permissions
13+
14+
jobs:
15+
collect-contracts:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v5
19+
with:
20+
repository: OpenZeppelin/stellar-contracts
21+
ref: main
22+
- id: dirs
23+
run: |
24+
dirs=$(find . -name 'Cargo.toml' -mindepth 2 -maxdepth 2 | xargs dirname | sed 's|^\./||' | jq -Rnc '[inputs | "\(.)"]')
25+
echo "dirs=$dirs" >> $GITHUB_OUTPUT
26+
outputs:
27+
dirs: ${{ steps.dirs.outputs.dirs }}
28+
29+
test-contract:
30+
needs: collect-contracts
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
working-directory: ${{ fromJSON(needs.collect-contracts.outputs.dirs) }}
35+
defaults:
36+
run:
37+
working-directory: stellar-contracts/${{ matrix.working-directory }}
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: Checkout rs-soroban-sdk
41+
uses: actions/checkout@v5
42+
with:
43+
path: rs-soroban-sdk
44+
45+
- name: Checkout OpenZeppelin stellar-contracts
46+
uses: actions/checkout@v5
47+
with:
48+
repository: OpenZeppelin/stellar-contracts
49+
ref: main
50+
path: stellar-contracts
51+
52+
- name: Install Rust
53+
run: |
54+
rustup update
55+
rustup target add wasm32v1-none
56+
57+
- uses: denoland/setup-deno@909cc5acb0fdd60627fb858598759246509fa755 # v2.0.2
58+
with:
59+
deno-version: v2.x
60+
61+
- uses: stellar/stellar-cli@v23.1.4
62+
63+
- uses: stellar/actions/rust-cache@main
64+
65+
- name: Patch SDK versions
66+
run: |
67+
# TODO: Update this patch logic to use `cargo add` once this issue is resolved: https://github.com/rust-lang/cargo/issues/16101
68+
crates=$(cd ${{ github.workspace }}/rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
69+
find . -name Cargo.toml | while read file; do
70+
echo Patching "$file" ...
71+
dir=$(dirname "$file")
72+
for crate in $crates; do
73+
rel_path=$(realpath --relative-to="$dir" ${{ github.workspace }}/rs-soroban-sdk/$crate)
74+
sed -i 's|'"$crate"' = "\([^"]*\)"|'"$crate"' = { path = "'"$rel_path"'" }|g' "$file"
75+
sed -i 's|'"$crate"' = {.*version = "[^"]*"\(.*\)|'"$crate"' = { path = "'"$rel_path"'" \1|g' "$file"
76+
done
77+
done
78+
79+
- name: Diff
80+
run: git diff
81+
82+
- name: Build contract
83+
env:
84+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
85+
run: cargo build --target wasm32v1-none --release
86+
87+
- name: Set artifact name
88+
id: artifact-name
89+
run: echo "name=wasm-$(echo ${{ matrix.working-directory }} | sed 's/\//-/g')" | tee -a $GITHUB_OUTPUT
90+
91+
- name: Upload WASM artifacts
92+
uses: actions/upload-artifact@v4
93+
with:
94+
name: ${{ steps.artifact-name.outputs.name }}
95+
path: 'stellar-contracts/target/wasm32v1-none/release/*.wasm'
96+
retention-days: 3
97+
98+
- name: Test OpenZeppelin stellar-contracts
99+
env:
100+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
101+
run: cargo test
102+
103+
- name: Diff
104+
run: git add -N . && git diff HEAD

0 commit comments

Comments
 (0)