Skip to content

Commit a606ca9

Browse files
Merge branch 'main' into i1451
2 parents 9913497 + 7456be9 commit a606ca9

File tree

63 files changed

+5147
-770
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5147
-770
lines changed

.github/workflows/rust.yml

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,46 @@ jobs:
2727
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
2828
run: exit 1
2929

30+
setup:
31+
runs-on: ubuntu-latest
32+
outputs:
33+
sys: ${{ steps.sys.outputs.sys }}
34+
steps:
35+
- id: sys
36+
run: |
37+
if [ "${{ github.event_name }}" == "pull_request" ]; then
38+
sys='[
39+
{
40+
"os": "ubuntu-latest",
41+
"target": "x86_64-unknown-linux-gnu"
42+
}
43+
]'
44+
else
45+
sys='[
46+
{
47+
"os": "ubuntu-latest",
48+
"target": "x86_64-unknown-linux-gnu"
49+
},
50+
{
51+
"os": "ubuntu-24.04-arm",
52+
"target": "aarch64-unknown-linux-gnu"
53+
},
54+
{
55+
"os": "macos-15-intel",
56+
"target": "x86_64-apple-darwin"
57+
},
58+
{
59+
"os": "macos-latest",
60+
"target": "aarch64-apple-darwin"
61+
},
62+
{
63+
"os": "windows-latest",
64+
"target": "x86_64-pc-windows-msvc"
65+
}
66+
]'
67+
fi
68+
echo "sys=$(<<< $sys jq -c)" >> $GITHUB_OUTPUT
69+
3070
fmt:
3171
runs-on: ubuntu-latest
3272
steps:
@@ -71,21 +111,12 @@ jobs:
71111
--exclude stellar-asset-spec
72112
73113
build:
114+
needs: setup
74115
strategy:
75116
fail-fast: false
76117
matrix:
77118
rust: [msrv, latest]
78-
sys:
79-
- os: ubuntu-latest
80-
target: x86_64-unknown-linux-gnu
81-
- os: ubuntu-24.04-arm
82-
target: aarch64-unknown-linux-gnu
83-
- os: macos-15-intel
84-
target: x86_64-apple-darwin
85-
- os: macos-latest
86-
target: aarch64-apple-darwin
87-
- os: windows-latest
88-
target: x86_64-pc-windows-msvc
119+
sys: ${{ fromJSON(needs.setup.outputs.sys) }}
89120
runs-on: ${{ matrix.sys.os }}
90121
steps:
91122
- uses: actions/checkout@v3
@@ -129,22 +160,12 @@ jobs:
129160
retention-days: ${{ env.ARTIFACT_RETENTION_DAYS_FOR_TEST_WASMS }}
130161

131162
test:
132-
needs: build
163+
needs: [setup, build]
133164
strategy:
134165
fail-fast: false
135166
matrix:
136167
rust: [msrv, latest]
137-
sys:
138-
- os: ubuntu-latest
139-
target: x86_64-unknown-linux-gnu
140-
- os: ubuntu-24.04-arm
141-
target: aarch64-unknown-linux-gnu
142-
- os: macos-15-intel
143-
target: x86_64-apple-darwin
144-
- os: macos-latest
145-
target: aarch64-apple-darwin
146-
- os: windows-latest
147-
target: x86_64-pc-windows-msvc
168+
sys: ${{ fromJSON(needs.setup.outputs.sys) }}
148169
runs-on: ${{ matrix.sys.os }}
149170
steps:
150171
- uses: actions/checkout@v3
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
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Test with soroban-examples
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-examples:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v5
22+
with:
23+
repository: stellar/soroban-examples
24+
ref: main
25+
- id: dirs
26+
run: |
27+
dirs=$(
28+
for dir in $(find . -type f -name 'Makefile' -mindepth 2 | xargs dirname | sed 's|^\./||'); do
29+
if (cargo metadata --manifest-path "$dir/Cargo.toml" --no-deps --format-version 1 | jq -r --arg pwd "$(pwd)" '.packages[0] | (any(.dependencies[]; .name == "soroban-sdk") and any(.targets[]; any(.crate_types[]; . == "cdylib")))' | grep -q '^true$'); then
30+
echo "$dir"
31+
fi
32+
done | jq -Rnc '[inputs | "\(.)"]'
33+
)
34+
echo "dirs=$dirs" >> $GITHUB_OUTPUT
35+
outputs:
36+
dirs: ${{ steps.dirs.outputs.dirs }}
37+
38+
test-example:
39+
needs: collect-examples
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
working-directory: ${{ fromJSON(needs.collect-examples.outputs.dirs) }}
44+
defaults:
45+
run:
46+
working-directory: soroban-examples/${{ matrix.working-directory }}
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout rs-soroban-sdk
50+
uses: actions/checkout@v5
51+
with:
52+
path: rs-soroban-sdk
53+
54+
- name: Checkout soroban-examples
55+
uses: actions/checkout@v5
56+
with:
57+
repository: stellar/soroban-examples
58+
ref: main
59+
path: soroban-examples
60+
61+
- name: Install Rust
62+
run: |
63+
rustup update
64+
rustup target add wasm32v1-none
65+
66+
- uses: denoland/setup-deno@909cc5acb0fdd60627fb858598759246509fa755 # v2.0.2
67+
with:
68+
deno-version: v2.x
69+
70+
- uses: stellar/stellar-cli@v23.1.4
71+
72+
- uses: stellar/actions/rust-cache@main
73+
74+
- name: Patch SDK versions
75+
run: |
76+
# TODO: Update this patch logic to use `cargo add` once this issue is resolved: https://github.com/rust-lang/cargo/issues/16101
77+
crates=$(cd ${{ github.workspace }}/rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
78+
find . -name Cargo.toml | while read file; do
79+
echo Patching "$file" ...
80+
dir=$(dirname "$file")
81+
for crate in $crates; do
82+
rel_path=$(realpath --relative-to="$dir" ${{ github.workspace }}/rs-soroban-sdk/$crate)
83+
sed -i 's|'"$crate"' = "\([^"]*\)"|'"$crate"' = { path = "'"$rel_path"'" }|g' "$file"
84+
sed -i 's|'"$crate"' = {.*version = "[^"]*"\(.*\)|'"$crate"' = { path = "'"$rel_path"'" \1|g' "$file"
85+
done
86+
done
87+
88+
- name: Diff
89+
run: (! git diff --exit-code) || (echo 'A diff is expected'; exit 1)
90+
91+
- name: Build soroban-examples
92+
env:
93+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
94+
run: make build
95+
96+
- name: Set artifact name
97+
id: artifact-name
98+
run: echo "name=wasm-$(echo ${{ matrix.working-directory }} | sed 's/\//-/g')" | tee -a $GITHUB_OUTPUT
99+
100+
- name: Upload WASM artifacts
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: ${{ steps.artifact-name.outputs.name }}
104+
path: 'soroban-examples/${{ matrix.working-directory }}/**/*.wasm'
105+
retention-days: 3
106+
107+
- name: Test soroban-examples
108+
env:
109+
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
110+
run: make test
111+
112+
- name: Diff
113+
run: git add -N . && git diff HEAD

0 commit comments

Comments
 (0)