fix(e2e-tests): fix merod port issue, pass PR number to update PR com… #385
This file contains 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: End-to-end tests | ||
on: | ||
push: | ||
branches: | ||
- '**' | ||
paths: | ||
- Cargo.toml | ||
- Cargo.lock | ||
- 'contracts/**' | ||
- 'crates/**' | ||
- 'e2e-tests/**' | ||
- '.github/workflows/e2e_tests.yml' | ||
jobs: | ||
test: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup rust toolchain | ||
run: rustup toolchain install stable --profile minimal | ||
- name: Setup rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
cache-on-failure: true | ||
cache-all-crates: true # due to candid-extractor | ||
- name: Install dfx | ||
uses: dfinity/setup-dfx@main | ||
- name: Get PR number test | ||
if: success() || failure() | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
Check failure on line 40 in .github/workflows/e2e_tests.yml GitHub Actions / End-to-end testsInvalid workflow file
|
||
echo "PR_NUMBER=$(gh pr list \ | ||
--repo ${{ github.repository }} \ | ||
--state open \ | ||
--head ${{ github.ref#refs/head/ }} \ | ||
--base master \ | ||
--json number \ | ||
-q '.[0].number')" | ||
- name: Build apps | ||
run: | | ||
./apps/kv-store/build.sh | ||
- name: Build contracts | ||
run: | | ||
./contracts/near/context-config/build.sh | ||
./contracts/near/context-proxy/build.sh | ||
- name: Build binaries | ||
run: | | ||
cargo build -p meroctl -p merod -p e2e-tests | ||
- name: Prepare e2e-tests config | ||
id: prepare_e2e_tests_config | ||
run: | | ||
# Generate 4 unique random numbers | ||
random_numbers=() | ||
while [ ${#random_numbers[@]} -lt 3 ]; do | ||
num=$((RANDOM%37001 + 3000)) | ||
if [[ ! " ${random_numbers[@]} " =~ " ${num} " ]]; then | ||
random_numbers+=($num) | ||
fi | ||
done | ||
# Export random numbers to environment variables | ||
echo "SWARM_PORT=${random_numbers[0]}" | ||
echo "SERVER_PORT=${random_numbers[1]}" | ||
echo "ICP_PORT=${random_numbers[2]}" | ||
# Update JSON file with jq | ||
jq --arg swarmPort "${random_numbers[0]}" \ | ||
--arg serverPort "${random_numbers[1]}" \ | ||
--arg icpPort "${random_numbers[2]}" \ | ||
'.network.startSwarmPort = ($swarmPort | tonumber) | | ||
.network.startServerPort = ($serverPort | tonumber) | | ||
.protocolSandboxes[1].config.rpcUrl = "http://127.0.0.1:\($icpPort)" | ||
' e2e-tests/config/config.json > updated_config.json | ||
mv updated_config.json e2e-tests/config/config.json | ||
echo "ICP_PORT=$ICP_PORT" >> $GITHUB_OUTPUT | ||
- name: Deploy ICP local devnet | ||
env: | ||
ICP_PORT: ${{ steps.prepare_e2e_tests_config.outputs.ICP_PORT }} | ||
run: | | ||
cargo install candid-extractor | ||
cd ./contracts/icp/context-config | ||
./deploy_devnet.sh | ||
cd ../../.. | ||
- name: Run e2e tests | ||
env: | ||
NO_COLOR: '1' | ||
# RUST_LOG: calimero_node=debug,calimero_network=debug | ||
run: | | ||
export SWARM_HOST=$(ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}' | head -n 1) | ||
echo "Running e2e tests, check job summary for details" | ||
./target/debug/e2e-tests \ | ||
--input-dir ./e2e-tests/config \ | ||
--output-dir ./e2e-tests/corpus \ | ||
--merod-binary ./target/debug/merod \ | ||
--meroctl-binary ./target/debug/meroctl | ||
- name: Get PR number | ||
id: pr_number | ||
if: success() || failure() | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
GH_REF: ${{ github.ref }} | ||
run: | | ||
echo "PR_NUMBER=$(gh pr list \ | ||
--repo ${{ github.repository }} \ | ||
--state open \ | ||
--head ${GH_REF#refs/head/} \ | ||
--base master \ | ||
--json number \ | ||
-q '.[0].number')" >> $GITHUB_OUTPUT | ||
- name: Update pull request comment | ||
if: (success() || failure()) && steps.pr_number.outputs.PR_NUMBER != '' | ||
uses: thollander/actions-comment-pull-request@v3 | ||
with: | ||
file-path: ./e2e-tests/corpus/report.md | ||
pr-number: ${{ steps.pr_number.outputs.PR_NUMBER }} | ||
- name: Upload artifacts | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: e2e-tests-corpus | ||
path: e2e-tests/corpus/ | ||
retention-days: 2 |