Add CI for soroban-examples and OZ contracts #1
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test with OpenZeppelin contracts | |
| on: | |
| push: | |
| branches: [main, release/**] | |
| pull_request: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || | |
| github.ref }} | |
| cancel-in-progress: true | |
| permissions: {} | |
| defaults: | |
| run: | |
| shell: bash | |
| jobs: | |
| build-cli: | |
| runs-on: ubuntu-latest-8-cores | |
| steps: | |
| - uses: actions/checkout@v6 | |
| - uses: stellar/actions/rust-cache@main | |
| - run: rustup update | |
| - run: sudo apt update && sudo apt install -y libudev-dev libdbus-1-dev | |
| - run: cargo build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: stellar-cli | |
| path: target/debug/stellar | |
| collect-crates: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| dirs: ${{ steps.dirs.outputs.dirs }} | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: OpenZeppelin/stellar-contracts | |
| - id: dirs | |
| run: | | |
| dirs=$(cargo metadata --no-deps --format-version 1 \ | |
| | jq -r --arg pwd "$(pwd)" \ | |
| '[.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' \ | |
| ) | |
| echo "dirs=$dirs" | tee -a $GITHUB_OUTPUT | |
| build-crate: | |
| needs: [build-cli, collect-crates] | |
| if: ${{ needs.collect-crates.outputs.dirs != '[]' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| dir: ${{ fromJSON(needs.collect-crates.outputs.dirs) }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| repository: OpenZeppelin/stellar-contracts | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: stellar-cli | |
| path: stellar-cli | |
| - run: chmod +x stellar-cli/stellar | |
| - run: echo "${{ github.workspace }}/stellar-cli" >> $GITHUB_PATH | |
| - run: rustup update | |
| - run: rustup target add wasm32v1-none | |
| - name: Build ${{ matrix.dir }} | |
| run: stellar contract build --manifest-path ${{ matrix.dir }}/Cargo.toml | |
| - name: Find wasm | |
| id: find-wasm | |
| run: | | |
| wasm=$(find target -name '*.wasm' -path '*/wasm32v1-none/*' | head -1) | |
| echo "wasm=$wasm" | tee -a $GITHUB_OUTPUT | |
| artifact_name="wasm-$(echo '${{ matrix.dir }}' | tr '/' '-')" | |
| echo "artifact-name=$artifact_name" | tee -a $GITHUB_OUTPUT | |
| - name: Verify interface | |
| run: | | |
| output=$(stellar contract info interface --wasm ${{ steps.find-wasm.outputs.wasm }} --output json) | |
| echo "$output" | |
| count=$(echo "$output" | jq 'length') | |
| if [ "$count" -lt 1 ]; then | |
| echo "ERROR: interface is empty" | |
| exit 1 | |
| fi | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.find-wasm.outputs.artifact-name }} | |
| path: ${{ steps.find-wasm.outputs.wasm }} | |
| upload-crate: | |
| needs: [collect-crates, build-crate] | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| dir: ${{ fromJSON(needs.collect-crates.outputs.dirs) }} | |
| runs-on: ubuntu-latest-8-cores | |
| steps: | |
| - uses: stellar/quickstart@main | |
| with: | |
| tag: testing | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: stellar-cli | |
| path: stellar-cli | |
| - run: chmod +x stellar-cli/stellar | |
| - run: echo "${{ github.workspace }}/stellar-cli" >> $GITHUB_PATH | |
| - name: Download wasm | |
| run: | | |
| artifact_name="wasm-$(echo '${{ matrix.dir }}' | tr '/' '-')" | |
| echo "artifact-name=$artifact_name" >> $GITHUB_OUTPUT | |
| id: artifact | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ steps.artifact.outputs.artifact-name }} | |
| path: wasm | |
| - name: Upload ${{ matrix.dir }} | |
| run: | | |
| wasm=$(find wasm -name '*.wasm' | head -1) | |
| stellar contract upload --wasm "$wasm" --network local | |
| complete: | |
| if: always() | |
| needs: [build-cli, collect-crates, build-crate, upload-crate] | |
| runs-on: ubuntu-slim | |
| steps: | |
| - if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') | |
| run: exit 1 |