forked from stellar/rs-soroban-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (101 loc) · 4.05 KB
/
test-with-soroban-examples.yml
File metadata and controls
120 lines (101 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
name: Test with soroban-examples
on:
push:
branches: [main, release/**]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true
# No permissions. This workflow downloads code from outside this repository and
# compiles it. No permissions ensures that any exploit in an external
# repository does not gain access to anything in this repo.
permissions: {}
jobs:
collect-examples:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
repository: stellar/soroban-examples
ref: main
- id: dirs
run: |
dirs=$(
for dir in $(find . -type f -name 'Makefile' -mindepth 2 | xargs dirname | sed 's|^\./||'); do
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
echo "$dir"
fi
done | jq -Rnc '[inputs | "\(.)"]'
)
echo "dirs=$dirs" >> $GITHUB_OUTPUT
outputs:
dirs: ${{ steps.dirs.outputs.dirs }}
test-example:
needs: collect-examples
strategy:
fail-fast: false
matrix:
working-directory: ${{ fromJSON(needs.collect-examples.outputs.dirs) }}
defaults:
run:
working-directory: soroban-examples/${{ matrix.working-directory }}
runs-on: ubuntu-latest
steps:
- name: Checkout rs-soroban-sdk
uses: actions/checkout@v5
with:
path: rs-soroban-sdk
- name: Checkout soroban-examples
uses: actions/checkout@v5
with:
repository: stellar/soroban-examples
ref: main
path: soroban-examples
- name: Install Rust
run: |
rustup update
rustup target add wasm32v1-none
- uses: denoland/setup-deno@909cc5acb0fdd60627fb858598759246509fa755 # v2.0.2
with:
deno-version: v2.x
- uses: stellar/stellar-cli@v23.1.4
- uses: stellar/actions/rust-cache@main
- name: Patch SDK versions
run: |
# TODO: Update this patch logic to use `cargo add` once this issue is resolved: https://github.com/rust-lang/cargo/issues/16101
crates=$(cd ${{ github.workspace }}/rs-soroban-sdk && cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.publish != []) | .name')
# Find Cargo.toml files to patch
local_files=$(find . -name Cargo.toml)
workspace_root=$(cargo metadata --format-version 1 --no-deps | jq -r '.workspace_root')
files=$(echo "$local_files"; echo "$workspace_root/Cargo.toml")
# Patch local files and workspace root (sort -u to deduplicate)
echo "$files" | sort -u | while read -r file; do
echo Patching "$file" ...
dir=$(dirname "$file")
for crate in $crates; do
rel_path=$(realpath --relative-to="$dir" ${{ github.workspace }}/rs-soroban-sdk/$crate)
sed -i 's|'"$crate"' = "\([^"]*\)"|'"$crate"' = { path = "'"$rel_path"'" }|g' "$file"
sed -i 's|'"$crate"' = {.*version = "[^"]*"\(.*\)|'"$crate"' = { path = "'"$rel_path"'" \1|g' "$file"
done
done
- name: Diff
run: (! git diff --exit-code) || (echo 'A diff is expected'; exit 1)
- name: Build soroban-examples
env:
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
run: make build
- name: Set artifact name
id: artifact-name
run: echo "name=wasm-$(echo ${{ matrix.working-directory }} | sed 's/\//-/g')" | tee -a $GITHUB_OUTPUT
- name: Upload WASM artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ steps.artifact-name.outputs.name }}
path: 'soroban-examples/${{ matrix.working-directory }}/**/*.wasm'
retention-days: 3
- name: Test soroban-examples
env:
CARGO_BUILD_RUSTFLAGS: "-A deprecated"
run: make test
- name: Diff
run: git add -N . && git diff HEAD