From 7edb96d57baa53605f2655d0b8b7caad996afed5 Mon Sep 17 00:00:00 2001 From: Damien LACHAUME / PALO-IT Date: Thu, 25 Jan 2024 19:40:29 +0100 Subject: [PATCH] feat: [WIP] add `test-mithril-client-wasm` job --- .github/workflows/test-client.yml | 79 +++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/.github/workflows/test-client.yml b/.github/workflows/test-client.yml index 6373bc8801a..77f2cf3c433 100644 --- a/.github/workflows/test-client.yml +++ b/.github/workflows/test-client.yml @@ -159,3 +159,82 @@ jobs: - name: Mithril Stake Distribution / download & restore latest shell: bash run: ${{ steps.command.outputs.mithril_client }} ${{ steps.prepare.outputs.debug_level }} mithril-stake-distribution download $MITHRIL_STAKE_DISTRIBUTION_HASH --download-dir /app + + test-mithril-client-wasm: + strategy: + fail-fast: false + matrix: + os: [ ubuntu-22.04 ] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout sources + uses: actions/checkout@v3 + + - name: Download built artifacts + uses: dawidd6/action-download-artifact@v2 + with: + name: mithril-distribution-wasm + path: ./mithril-client-wasm + commit: ${{ steps.prepare.outputs.sha }} + branch: ${{ steps.prepare.outputs.branch }} + workflow: ci.yml + workflow_conclusion: success + + - name: Unpack 'mithril-client-wasm' package + working-directory: mithril-client-wasm + run: tar -xvzf pkg/*.tgz -C pkg/ && mv pkg/package/* pkg/ + + - name: Install dependencies + working-directory: mithril-client-wasm + run: make www-test-install + + - name: Create .env file + working-directory: mithril-client-wasm + run: | + echo "AGGREGATOR_ENDPOINT=${{ inputs.aggregator_endpoint }}" > ./www-test/.env + echo "GENESIS_VERIFICATION_KEY=$(curl -s ${{ inputs.genesis_verification_key }})" >> ./www-test/.env + + - name: Start the server + working-directory: mithril-client-wasm + shell: bash + run: make www-test-serve & + + - name: Wait for the server to be ready + shell: bash + run: | + MAX_ATTEMPTS=30 + CURRENT_ATTEMPT=0 + while true + do + sleep 1 + CURRENT_ATTEMPT=$(( ${CURRENT_ATTEMPT} + 1 )) + echo "Before command nc..." + if nc -z localhost 8080; then + echo "Server is ready." + break + fi + if [ "$CURRENT_ATTEMPT" -ge "$MAX_ATTEMPTS" ]; then + echo "Error: Server not ready after $MAX_ATTEMPTS attempts." + exit 1 + fi + done + + - name: Run Chrome headless + working-directory: mithril-client-wasm + shell: bash + run: | + /usr/bin/google-chrome --headless --virtual-time-budget=60000 --dump-dom http://localhost:8080 > www-test-results.html + + # Handle tests results + if grep -q 'title="FAILED"' www-test-results.html; then + failed_info=$(grep -oE '
([^<]+)' www-test-results.html | awk 'NR==1 {print substr($0, index($0,$4))}') + echo $failed_info + exit 1 + elif grep -q 'title="OK"' www-test-results.html; then + grep -oE '
([^<]+)' www-test-results.html | awk '{print substr($0, index($0,$4))}' + echo "Success: all tests passed." + else + cat www-test-results.html + echo "No test results found. Check www-test-results.html output." + exit 1 + fi