check_runtime.sh 2.96 KB
Newer Older
1
2
3
#!/bin/sh
#
#
4
5
6
7
# check for any changes in the ^runtime/ tree. if there are any changes found, 
# it should mark the PR B2-breaksapi and "auto-fail" the PR if there 
# isn't a change in the runtime/{kusama,polkadot}/src/lib.rs file that alters 
# the version.
8
9
10
11
12
13
14

set -e # fail on any error


# give some context
git log --graph --oneline --decorate=short -n 10

15
16
17
# make sure the master branch is available in shallow clones
git fetch --depth=${GIT_DEPTH:-100} origin master

18
19
20
21
22
23
24
25
26
27
28
29
30
31

github_label () {
	echo
	echo "# run github-api job for labeling it ${1}"
	curl -sS -X POST \
		-F "token=${CI_JOB_TOKEN}" \
		-F "ref=master" \
		-F "variables[LABEL]=${1}" \
		-F "variables[PRNO]=${CI_COMMIT_REF_NAME}" \
		-F "variables[PROJECT]=paritytech/polkadot" \
		${GITLAB_API}/projects/${GITHUB_API_PROJECT}/trigger/pipeline
}


Gavin Wood's avatar
Gavin Wood committed
32
33
# Introduce runtime/polkadot/src/lib.rs once Polkadot mainnet is live.
for VERSIONS_FILE in runtime/kusama/src/lib.rs 
34
35
36
37
38
39
do
	# check if the wasm sources changed
	if ! git diff --name-only origin/master...${CI_COMMIT_SHA} \
		| grep -q -e '^runtime/'
	then
		cat <<-EOT
40
		
41
		no changes to the runtime source code detected
42
	
43
		EOT
44
	
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
		continue
	fi
	
	
	
	# check for spec_version updates: if the spec versions changed, then there is
	# consensus-critical logic that has changed. the runtime wasm blobs must be
	# rebuilt.
	
	add_spec_version="$(git diff origin/master...${CI_COMMIT_SHA} ${VERSIONS_FILE} \
		| sed -n -r "s/^\+[[:space:]]+spec_version: +([0-9]+),$/\1/p")"
	sub_spec_version="$(git diff origin/master...${CI_COMMIT_SHA} ${VERSIONS_FILE} \
		| sed -n -r "s/^\-[[:space:]]+spec_version: +([0-9]+),$/\1/p")"
	
	
	# see if the version and the binary blob changed
	if [ "${add_spec_version}" != "${sub_spec_version}" ]
62
	then
63
64
65
	
		github_label "B2-breaksapi"
	
66
		cat <<-EOT
67
68
69
70
			
			changes to the runtime sources and changes in the spec version.
		
			spec_version: ${sub_spec_version} -> ${add_spec_version}
71
72
		
		EOT
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
		continue
	
	else
		# check for impl_version updates: if only the impl versions changed, we assume
		# there is no consensus-critical logic that has changed.
	
		add_impl_version="$(git diff origin/master...${CI_COMMIT_SHA} ${VERSIONS_FILE} \
			| sed -n -r 's/^\+[[:space:]]+impl_version: +([0-9]+),$/\1/p')"
		sub_impl_version="$(git diff origin/master...${CI_COMMIT_SHA} ${VERSIONS_FILE} \
			| sed -n -r 's/^\-[[:space:]]+impl_version: +([0-9]+),$/\1/p')"
	
	
		# see if the impl version changed
		if [ "${add_impl_version}" != "${sub_impl_version}" ]
		then
			cat <<-EOT
			
			changes to the runtime sources and changes in the impl version.
	
			impl_version: ${sub_impl_version} -> ${add_impl_version}
	
			EOT
			continue
		fi
	
	
		cat <<-EOT
	
		wasm source files changed but not the spec/impl version and the runtime
		binary blob. If changes made do not alter logic, just bump 'impl_version'.
		If they do change logic, bump 'spec_version' and rebuild wasm.
	
		source file directories:
		- runtime
	
		versions file: ${VERSIONS_FILE}
	
		EOT
111

112
113
114
		exit 1
	fi
done
115
116


117
exit 0
118
119

# vim: noexpandtab