1+ name : relayer-test
2+
3+ # NOTE: could be parametrized with which package to test when we have a specific transaction manager different from the relayer itself.
4+
5+ on :
6+ pull_request :
7+
8+ permissions : {}
9+
10+ concurrency :
11+ group : ${{ github.workflow }}-${{ github.head_ref }}
12+ cancel-in-progress : ${{ github.ref != 'refs/heads/main' }}
13+
14+ jobs :
15+ check-changes :
16+ name : relayer-test/check-changes
17+ permissions :
18+ actions : ' read' # Required to read workflow run information
19+ contents : ' read' # Required to checkout repository code
20+ pull-requests : ' read' # Required to read pull request information
21+ runs-on : ubuntu-latest
22+ outputs :
23+ changes-rust-files : ${{ steps.filter.outputs.rust-files }}
24+ steps :
25+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
26+ with :
27+ persist-credentials : ' false'
28+ - uses : dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
29+ id : filter
30+ with :
31+ filters : |
32+ rust-files:
33+ - .github/workflows/relayer-tests.yaml
34+ - relayer/**
35+
36+ unit-test :
37+ name : relayer-test/unit-test (bpr)
38+ needs : check-changes
39+ if : ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
40+ permissions :
41+ contents : ' read' # Required to checkout repository code
42+ runs-on : ubuntu-latest
43+ steps :
44+ - name : Checkout Project
45+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
46+ with :
47+ persist-credentials : false
48+ token : ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
49+ submodules : recursive
50+
51+ - name : Setup Rust toolchain file
52+ run : cp relayer/rust-toolchain.toml .
53+
54+ - name : Rust setup
55+ uses : dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
56+
57+ - name : Cache Rust dependencies and build artifacts
58+ uses : Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
59+ with :
60+ workspaces : relayer
61+ key : rust-build-relayer
62+ cache-targets : true
63+ cache-all-crates : true
64+
65+ - name : Format
66+ working-directory : relayer
67+ run : cargo fmt --all -- --check
68+
69+ - name : Build for tests (no rpc mock)
70+ working-directory : relayer
71+ run : cargo test --no-run --lib
72+
73+ - name : Unit tests
74+ working-directory : relayer
75+ run : RUST_BACKTRACE=full make test-unit
76+
77+ clippy :
78+ name : relayer-test/clippy (bpr)
79+ needs : check-changes
80+ if : ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
81+ permissions :
82+ contents : ' read' # Required to checkout repository code
83+ runs-on : ubuntu-latest
84+ steps :
85+ - name : Checkout Project
86+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
87+ with :
88+ persist-credentials : false
89+ token : ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
90+ submodules : recursive
91+
92+ - name : Setup Rust toolchain file
93+ run : cp relayer/rust-toolchain.toml .
94+
95+ - name : Setup Rust
96+ uses : dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
97+
98+ - name : Cache Rust dependencies
99+ uses : Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
100+ with :
101+ workspaces : relayer
102+ key : rust-build-relayer
103+
104+ - name : Clippy
105+ working-directory : relayer
106+ run : cargo clippy -- -D warnings
107+
108+ integration-test :
109+ name : relayer-test/integration-test (bpr)
110+ needs : check-changes
111+ if : ${{ needs.check-changes.outputs.changes-rust-files == 'true' }}
112+ permissions :
113+ contents : ' read' # Required to checkout repository code
114+ runs-on : ubuntu-latest
115+ services :
116+ postgres :
117+ image : cgr.dev/zama.ai/postgres:17.9@sha256:d42847b7c5f9ece73655164588b2387dcd5fadd618ea64761c19d3484498cef0
118+ credentials :
119+ username : ${{ secrets.CGR_USERNAME }}
120+ password : ${{ secrets.CGR_PASSWORD }}
121+ env :
122+ POSTGRES_USER : postgres
123+ POSTGRES_PASSWORD : postgres
124+ POSTGRES_DB : relayer_db
125+ ports :
126+ - 5432
127+ options : >-
128+ --health-cmd "pg_isready -U postgres -d relayer_db"
129+ --health-interval 10s
130+ --health-timeout 5s
131+ --health-retries 5
132+
133+ env :
134+ SQLX_OFFLINE : true # Use cached queries for compilation (speeds up CI)
135+ APP_GLOBAL__MOCK_TEST : true
136+ DB_USER : postgres
137+ DB_PASSWORD : postgres
138+ DB_NAME : relayer_db
139+
140+ steps :
141+ - name : Checkout Project
142+ uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
143+ with :
144+ persist-credentials : false
145+ token : ${{ secrets.BLOCKCHAIN_ACTIONS_TOKEN }}
146+ submodules : recursive
147+
148+ - name : Set database URLs
149+ env :
150+ DB_PORT : ${{ job.services.postgres.ports['5432'] }}
151+ run : |
152+ {
153+ echo "DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
154+ echo "APP_STORAGE__SQL_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
155+ echo "TEST_DATABASE_URL=postgres://${DB_USER}:${DB_PASSWORD}@localhost:${DB_PORT}/${DB_NAME}"
156+ } >> "$GITHUB_ENV"
157+
158+ - name : Setup Rust toolchain file
159+ run : cp relayer/rust-toolchain.toml .
160+
161+ - name : Setup Rust
162+ uses : dsherret/rust-toolchain-file@3551321aa44dd44a0393eb3b6bdfbc5d25ecf621 # v1
163+
164+ - name : Cache Rust dependencies and build artifacts
165+ uses : Swatinem/rust-cache@779680da715d629ac1d338a641029a2f4372abb5 # v2.8.2
166+ with :
167+ workspaces : relayer
168+ key : rust-build-relayer
169+ cache-targets : true
170+ cache-all-crates : true
171+
172+ - name : Install SQLx CLI
173+ run : |
174+ if ! command -v sqlx &> /dev/null; then
175+ echo "Installing sqlx-cli..."
176+ cargo install sqlx-cli --no-default-features --features postgres
177+ else
178+ echo "sqlx-cli found in cache."
179+ fi
180+
181+ - name : Migrate Database
182+ working-directory : relayer/relayer-migrate
183+ run : sqlx migrate run
184+
185+ - name : Run tests
186+ working-directory : relayer
187+ run : RUST_BACKTRACE=full make test-run
0 commit comments