Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 1a6491b

Browse files
authored
Add extrincic ordering check to CI (#629)
* Add extrincic ordering check to CI * Add missing script * Fix default chain * Ignore issues with pkill * Continue on error while trying to stop the node * Set embedded relay chain node * Fix formatting
1 parent 0b921dd commit 1a6491b

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# This workflow performs the Extrinsic Ordering Check on demand using a binary
2+
3+
name: Extrinsic Ordering Check from Binary
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
reference_url:
8+
description: The WebSocket url of the reference node
9+
default: wss://kusama-statemine-rpc.paritytech.net
10+
required: true
11+
binary_url:
12+
description: A url to a Linux binary for the node containing the runtime to test
13+
default: https://github.com/paritytech/cumulus/releases/download/statemine_v3/polkadot-collator
14+
required: true
15+
chain:
16+
description: The name of the chain under test. Usually, you would pass a local chain
17+
default: statemine-local
18+
required: true
19+
20+
jobs:
21+
check:
22+
name: Run check
23+
runs-on: ubuntu-latest
24+
env:
25+
CHAIN: ${{github.event.inputs.chain}}
26+
BIN_URL: ${{github.event.inputs.binary_url}}
27+
REF_URL: ${{github.event.inputs.reference_url}}
28+
29+
steps:
30+
- uses: actions/checkout@v2
31+
32+
- name: Fetch binary
33+
run: |
34+
echo Fetching $BIN_URL
35+
wget $BIN_URL
36+
chmod a+x polkadot-collator
37+
./polkadot-collator --version
38+
39+
- name: Start local node
40+
run: |
41+
echo Running on $CHAIN
42+
./polkadot-collator --chain=$CHAIN -- --chain polkadot-local &
43+
44+
- name: Prepare output
45+
run: |
46+
VERSION=$(./polkadot-collator --version)
47+
echo "Metadata comparison:" >> output.txt
48+
echo "Date: $(date)" >> output.txt
49+
echo "Reference: $REF_URL" >> output.txt
50+
echo "Target version: $VERSION" >> output.txt
51+
echo "Chain: $CHAIN" >> output.txt
52+
echo "----------------------------------------------------------------------" >> output.txt
53+
54+
- name: Pull polkadot-js-tools image
55+
run: docker pull jacogr/polkadot-js-tools
56+
57+
- name: Compare the metadata
58+
run: |
59+
CMD="docker run --pull always --network host jacogr/polkadot-js-tools metadata $REF_URL ws://localhost:9944"
60+
echo -e "Running:\n$CMD"
61+
$CMD >> output.txt
62+
sed -z -i 's/\n\n/\n/g' output.txt
63+
cat output.txt | egrep -n -i ''
64+
SUMMARY=$(./scripts/extrinsic-ordering-filter.sh output.txt)
65+
echo -e $SUMMARY
66+
echo -e $SUMMARY >> output.txt
67+
68+
- name: Show result
69+
run: |
70+
cat output.txt
71+
72+
- name: Stop our local node
73+
run: |
74+
pkill polkadot-collator
75+
continue-on-error: true
76+
77+
- name: Save output as artifact
78+
uses: actions/upload-artifact@v2
79+
with:
80+
name: ${{ env.CHAIN }}
81+
path: |
82+
output.txt

scripts/extrinsic-ordering-filter.sh

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env bash
2+
# This script is used in a Github Workflow. It helps filtering out what is interesting
3+
# when comparing metadata and spot what would require a tx version bump.
4+
5+
# shellcheck disable=SC2002,SC2086
6+
7+
FILE=$1
8+
9+
# Higlight indexes that were deleted
10+
function find_deletions() {
11+
echo "\n## Deletions\n"
12+
RES=$(cat "$FILE" | grep -n '\[\-\]' | tr -s " ")
13+
if [ "$RES" ]; then
14+
echo "$RES" | awk '{ printf "%s\\n", $0 }'
15+
else
16+
echo "n/a"
17+
fi
18+
}
19+
20+
# Highlight indexes that have been deleted
21+
function find_index_changes() {
22+
echo "\n## Index changes\n"
23+
RES=$(cat "$FILE" | grep -E -n -i 'idx:\s*([0-9]+)\s*(->)\s*([0-9]+)' | tr -s " ")
24+
if [ "$RES" ]; then
25+
echo "$RES" | awk '{ printf "%s\\n", $0 }'
26+
else
27+
echo "n/a"
28+
fi
29+
}
30+
31+
# Highlight values that decreased
32+
function find_decreases() {
33+
echo "\n## Decreases\n"
34+
OUT=$(cat "$FILE" | grep -E -i -o '([0-9]+)\s*(->)\s*([0-9]+)' | awk '$1 > $3 { printf "%s;", $0 }')
35+
IFS=$';' LIST=("$OUT")
36+
unset RES
37+
for line in "${LIST[@]}"; do
38+
RES="$RES\n$(cat "$FILE" | grep -E -i -n \"$line\" | tr -s " ")"
39+
done
40+
41+
if [ "$RES" ]; then
42+
echo "$RES" | awk '{ printf "%s\\n", $0 }' | sort -u -g | uniq
43+
else
44+
echo "n/a"
45+
fi
46+
}
47+
48+
echo "\n------------------------------ SUMMARY -------------------------------"
49+
echo "\n⚠️ This filter is here to help spotting changes that should be reviewed carefully."
50+
echo "\n⚠️ It catches only index changes, deletions and value decreases".
51+
52+
find_deletions "$FILE"
53+
find_index_changes "$FILE"
54+
find_decreases "$FILE"
55+
echo "\n----------------------------------------------------------------------\n"

0 commit comments

Comments
 (0)