|
| 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 }} |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | + |
| 18 | +jobs: |
| 19 | + build-cli: |
| 20 | + runs-on: ubuntu-latest-8-cores |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v6 |
| 23 | + - uses: stellar/actions/rust-cache@main |
| 24 | + - run: rustup update |
| 25 | + - run: sudo apt update && sudo apt install -y libudev-dev libdbus-1-dev |
| 26 | + - run: make install |
| 27 | + - uses: actions/upload-artifact@v7 |
| 28 | + with: |
| 29 | + name: stellar-cli |
| 30 | + path: ~/.cargo/bin/stellar |
| 31 | + |
| 32 | + collect-crates: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + outputs: |
| 35 | + dirs: ${{ steps.dirs.outputs.dirs }} |
| 36 | + steps: |
| 37 | + - uses: actions/checkout@v6 |
| 38 | + with: |
| 39 | + repository: OpenZeppelin/stellar-contracts |
| 40 | + - id: dirs |
| 41 | + run: | |
| 42 | + dirs=$(cargo metadata --no-deps --format-version 1 \ |
| 43 | + | jq -r --arg pwd "$(pwd)" \ |
| 44 | + '[.workspace_members[] as $id | .packages[] | select(.id == $id) | select(any(.dependencies[]; .name == "soroban-sdk") and any(.targets[]; any(.crate_types[]; . == "cdylib"))) | .manifest_path | sub("^\($pwd)/"; "") | sub("/Cargo.toml$"; "")] | tojson' \ |
| 45 | + ) |
| 46 | + echo "dirs=$dirs" | tee -a $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + build-crate: |
| 49 | + needs: [build-cli, collect-crates] |
| 50 | + if: ${{ needs.collect-crates.outputs.dirs != '[]' }} |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + dir: ${{ fromJSON(needs.collect-crates.outputs.dirs) }} |
| 55 | + experimental_spec_shaking_v2: [true, false] |
| 56 | + runs-on: ubuntu-latest |
| 57 | + steps: |
| 58 | + - uses: actions/checkout@v6 |
| 59 | + with: |
| 60 | + repository: OpenZeppelin/stellar-contracts |
| 61 | + - uses: actions/download-artifact@v8 |
| 62 | + with: |
| 63 | + name: stellar-cli |
| 64 | + path: stellar-cli |
| 65 | + - run: chmod +x stellar-cli/stellar |
| 66 | + - run: echo "${{ github.workspace }}/stellar-cli" >> $GITHUB_PATH |
| 67 | + - run: rustup update |
| 68 | + - run: rustup target add wasm32v1-none |
| 69 | + - name: Enable experimental_spec_shaking_v2 feature |
| 70 | + if: matrix.experimental_spec_shaking_v2 |
| 71 | + run: | |
| 72 | + find . -name Cargo.toml | while read -r file; do |
| 73 | + # Add feature to entries with existing features |
| 74 | + sed -i '/soroban-sdk = {/s|features = \[|features = ["experimental_spec_shaking_v2", |' "$file" |
| 75 | + # Add features field to entries without features |
| 76 | + sed -i '/soroban-sdk = {/{/features/!s| }|, features = ["experimental_spec_shaking_v2"] }|}' "$file" |
| 77 | + done |
| 78 | + cargo update -p soroban-sdk |
| 79 | + - name: Diff |
| 80 | + run: git diff |
| 81 | + - name: Build ${{ matrix.dir }} |
| 82 | + run: stellar contract build --manifest-path ${{ matrix.dir }}/Cargo.toml |
| 83 | + - name: Find wasm |
| 84 | + id: find-wasm |
| 85 | + run: | |
| 86 | + wasm=$(find . -name '*.wasm' -path '*/wasm32v1-none/release/*' -not -path '*/deps/*' | head -1) |
| 87 | + echo "wasm=$wasm" | tee -a $GITHUB_OUTPUT |
| 88 | + - name: Set artifact name |
| 89 | + id: artifact-name |
| 90 | + run: echo "name=wasm-$(echo ${{ matrix.dir }} | sed 's/\//-/g')${{ matrix.experimental_spec_shaking_v2 && '-spec-shaking-v2' || '' }}" | tee -a $GITHUB_OUTPUT |
| 91 | + - name: Upload WASM artifacts |
| 92 | + uses: actions/upload-artifact@v4 |
| 93 | + with: |
| 94 | + name: ${{ steps.artifact-name.outputs.name }} |
| 95 | + path: ${{ steps.find-wasm.outputs.wasm }} |
| 96 | + retention-days: 3 |
| 97 | + - name: Verify interface |
| 98 | + if: ${{ startsWith(matrix.dir, 'examples/') }} |
| 99 | + run: | |
| 100 | + output=$(stellar contract info interface --wasm ${{ steps.find-wasm.outputs.wasm }} --output json) |
| 101 | + echo "$output" |
| 102 | + count=$(echo "$output" | jq 'length') |
| 103 | + if [ "$count" -lt 1 ]; then |
| 104 | + echo "ERROR: interface is empty" |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | + - name: Verify env-meta |
| 108 | + if: ${{ startsWith(matrix.dir, 'examples/') }} |
| 109 | + run: | |
| 110 | + output=$(stellar contract info env-meta --wasm ${{ steps.find-wasm.outputs.wasm }} --output json) |
| 111 | + echo "$output" |
| 112 | + if [ "$(echo "$output" | jq 'length')" -lt 1 ]; then |
| 113 | + echo "ERROR: env-meta is empty" |
| 114 | + exit 1 |
| 115 | + fi |
| 116 | + - name: Verify meta |
| 117 | + if: ${{ startsWith(matrix.dir, 'examples/') }} |
| 118 | + run: | |
| 119 | + output=$(stellar contract info meta --wasm ${{ steps.find-wasm.outputs.wasm }} --output json) |
| 120 | + echo "$output" |
| 121 | + if [ "$(echo "$output" | jq 'length')" -lt 1 ]; then |
| 122 | + echo "ERROR: meta is empty" |
| 123 | + exit 1 |
| 124 | + fi |
| 125 | + - name: Verify spec |
| 126 | + if: ${{ startsWith(matrix.dir, 'examples/') }} |
| 127 | + run: stellar contract spec-verify --wasm ${{ steps.find-wasm.outputs.wasm }} |
| 128 | + - name: Diff |
| 129 | + run: git add -N . && git diff HEAD |
0 commit comments