Skip to content

Commit

Permalink
[CI] Fix check-tx-version Gitlab job (paritytech#2449)
Browse files Browse the repository at this point in the history
* set -e for tx job

* dont set -e while we investigate

* fetch latest release polkadot

* add jq to node:15 image

* Add logic for timing out if nodes never start listening

* remove trap
  • Loading branch information
s3krit authored Feb 17, 2021
1 parent d3cb594 commit ecaac11
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ check-transaction-versions:
<<: *docker-env
needs:
- job: test-linux-stable
artifacts: false
artifacts: true
before_script:
- apt-get -y update; apt-get -y install jq lsof
- npm install --ignore-scripts -g @polkadot/metadata-cmp
- git fetch origin release
script:
Expand Down
7 changes: 7 additions & 0 deletions scripts/common/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,10 @@ skip_if_companion_pr() {
echo "[+] PR is not a companion PR. Proceeding test"
fi
}

# Fetches the tag name of the latest release from a repository
# repo: 'organisation/repo'
# Usage: latest_release 'paritytech/polkadot'
latest_release() {
curl -s "$api_base/$1/releases/latest" | jq -r '.tag_name'
}
57 changes: 40 additions & 17 deletions scripts/gitlab/check_extrinsics_ordering.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
#!/bin/bash
BIN=./target/release/polkadot
LIVE_WS=wss://rpc.polkadot.io
LOCAL_WS=ws://localhost:9944
#!/usr/bin/env bash
set -e

# Kill the polkadot client before exiting
trap 'kill "$(jobs -p)"' EXIT
# Include the common functions library
#shellcheck source=../common/lib.sh
. "$(dirname "${0}")/../common/lib.sh"

HEAD_BIN=./target/release/polkadot
HEAD_WS=ws://localhost:9944
RELEASE_WS=ws://localhost:9945

runtimes=(
"westend"
"kusama"
"polkadot"
)

# First we fetch the latest released binary
latest_release=$(latest_release 'paritytech/polkadot')
RELEASE_BIN="./polkadot-$latest_release"
echo "[+] Fetching binary for Polkadot version $latest_release"
curl -L "https://github.com/paritytech/polkadot/releases/download/$latest_release/polkadot" > "$RELEASE_BIN" || exit 1
chmod +x "$RELEASE_BIN"


for RUNTIME in "${runtimes[@]}"; do
echo "[+] Checking runtime: ${RUNTIME}"

Expand All @@ -32,19 +43,29 @@ for RUNTIME in "${runtimes[@]}"; do
exit 0
fi

if [ "$RUNTIME" = 'polkadot' ]; then
LIVE_WS="wss://rpc.polkadot.io"
else
LIVE_WS="wss://${RUNTIME}-rpc.polkadot.io"
fi

# Start running the local polkadot node in the background
$BIN --chain="$RUNTIME-local" &
# Start running the nodes in the background
$HEAD_BIN --chain="$RUNTIME-local" --tmp &
$RELEASE_BIN --chain="$RUNTIME-local" --ws-port 9945 --tmp &
jobs

# Sleep a little to allow the nodes to spin up and start listening
TIMEOUT=5
for i in $(seq $TIMEOUT); do
sleep 1
if [ "$(lsof -nP -iTCP -sTCP:LISTEN | grep -c '994[45]')" == 2 ]; then
echo "[+] Both nodes listening"
break
fi
if [ "$i" == $TIMEOUT ]; then
echo "[!] Both nodes not listening after $i seconds. Exiting"
exit 1
fi
done
sleep 5

changed_extrinsics=$(
polkadot-js-metadata-cmp "$LIVE_WS" "$LOCAL_WS" \
| sed 's/^ \+//g' | grep -e 'idx: [0-9]\+ -> [0-9]\+'
polkadot-js-metadata-cmp "$RELEASE_WS" "$HEAD_WS" \
| sed 's/^ \+//g' | grep -e 'idx: [0-9]\+ -> [0-9]\+' || true
)

if [ -n "$changed_extrinsics" ]; then
Expand All @@ -54,6 +75,8 @@ for RUNTIME in "${runtimes[@]}"; do
fi

echo "[+] No change in extrinsics ordering for the ${RUNTIME} runtime"
kill "$(jobs -p)"; sleep 5
jobs -p | xargs kill; sleep 5
done

# Sleep a little to let the jobs die properly
sleep 5

0 comments on commit ecaac11

Please sign in to comment.