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

Companion: move check-polkadot-companion-build to polkadot #1426

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ indent_style=space
indent_size=2
tab_width=8
end_of_line=lf

[*.sh]
indent_style=space
indent_size=2
tab_width=2
end_of_line=lf
4 changes: 3 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ test-linux-stable: &test
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
TARGET: native
script:
- time cargo test --all --release --verbose --locked --features runtime-benchmarks
- ./scripts/gitlab/test_linux_stable.sh
- sccache -s
after_script:
- cd substrate && git rev-parse --abbrev-ref HEAD

check-web-wasm: &test
stage: test
Expand Down
2 changes: 1 addition & 1 deletion runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("kusama"),
impl_name: create_runtime_str!("parity-kusama"),
authoring_version: 2,
spec_version: 2018,
spec_version: 2019,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down
2 changes: 1 addition & 1 deletion runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("polkadot"),
impl_name: create_runtime_str!("parity-polkadot"),
authoring_version: 0,
spec_version: 18,
spec_version: 19,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down
2 changes: 1 addition & 1 deletion runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("westend"),
impl_name: create_runtime_str!("parity-westend"),
authoring_version: 2,
spec_version: 38,
spec_version: 39,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
Expand Down
292 changes: 147 additions & 145 deletions scripts/gitlab/check_runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ boldprint "make sure the master branch is available in shallow clones"
git fetch --depth="${GIT_DEPTH:-100}" origin master

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

common_dirs=(
"common"
"common"
)

# Helper function to join elements in an array with a multi-char delimiter
Expand All @@ -52,176 +52,178 @@ runtime_regex="^runtime/$(join_by '|^runtime/' "${runtimes[@]}" "${common_dirs[@

boldprint "check if the wasm sources changed since ${LATEST_TAG}"
if ! git diff --name-only "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" \
| grep -E -q -e "$runtime_regex"
| grep -E -q -e "$runtime_regex"
then
boldprint "no changes to any runtime source code detected"
# continue checking if Cargo.lock was updated with a new substrate reference
# and if that change includes a {spec|impl}_version update.

SUBSTRATE_REFS_CHANGED="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^[\+\-]source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | wc -l
)"

# check Cargo.lock for substrate ref change
case "${SUBSTRATE_REFS_CHANGED}" in
(0)
boldprint "substrate refs not changed in Cargo.lock"
exit 0
;;
(2)
boldprint "substrate refs updated since ${LATEST_TAG}"
;;
(*)
boldprint "check unsupported: more than one commit targeted in repo ${SUBSTRATE_REPO_CARGO}"
exit 1
esac


SUBSTRATE_PREV_REF="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^\-source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | head -n 1
)"

SUBSTRATE_NEW_REF="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^\+source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | head -n 1
)"


boldcat <<-EOT
previous substrate commit id ${SUBSTRATE_PREV_REF}
new substrate commit id ${SUBSTRATE_NEW_REF}
EOT

# okay so now need to fetch the substrate repository and check whether spec_version or impl_version has changed there
SUBSTRATE_CLONE_DIR="$(mktemp -t -d substrate-XXXXXX)"
trap 'rm -rf "${SUBSTRATE_CLONE_DIR}"' INT QUIT TERM ABRT EXIT

git clone --depth="${GIT_DEPTH:-100}" --no-tags \
"${SUBSTRATE_REPO}" "${SUBSTRATE_CLONE_DIR}"

# check if there are changes to the spec|impl versions
git -C "${SUBSTRATE_CLONE_DIR}" diff \
"${SUBSTRATE_PREV_REF}..${SUBSTRATE_NEW_REF}" "${SUBSTRATE_VERSIONS_FILE}" \
| grep -E '^[\+\-][[:space:]]+(spec|impl)_version: +([0-9]+),$' || exit 0

boldcat <<-EOT
spec_version or or impl_version have changed in substrate after updating Cargo.lock
please make sure versions are bumped in polkadot accordingly
EOT

# Now check if any of the substrate changes have been tagged D2-breaksapi
(
cd "${SUBSTRATE_CLONE_DIR}"
substrate_changes="$(sanitised_git_logs "${SUBSTRATE_PREV_REF}" "${SUBSTRATE_NEW_REF}")"
echo "$substrate_changes" | while read -r line; do
pr_id=$(echo "$line" | sed -E 's/.*#([0-9]+)\)$/\1/')

if has_label 'paritytech/substrate' "$pr_id" 'D2-breaksapi'; then
boldprint "Substrate change labelled with D2-breaksapi. Labelling..."
github_label "D2-breaksapi"
exit 1
fi
done
)
boldprint "no changes to any runtime source code detected"
# continue checking if Cargo.lock was updated with a new substrate reference
# and if that change includes a {spec|impl}_version update.

SUBSTRATE_REFS_CHANGED="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^[\+\-]source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | wc -l
)"

# check Cargo.lock for substrate ref change
case "${SUBSTRATE_REFS_CHANGED}" in
(0)
boldprint "substrate refs not changed in Cargo.lock"
exit 0
;;
(2)
boldprint "substrate refs updated since ${LATEST_TAG}"
;;
(*)
boldprint "check unsupported: more than one commit targeted in repo ${SUBSTRATE_REPO_CARGO}"
exit 1
esac


SUBSTRATE_PREV_REF="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^\-source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | head -n 1
)"

SUBSTRATE_NEW_REF="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" Cargo.lock \
| sed -n -r "s~^\+source = \"${SUBSTRATE_REPO_CARGO}#([a-f0-9]+)\".*$~\1~p" | sort -u | head -n 1
)"


boldcat <<EOT
previous substrate commit id ${SUBSTRATE_PREV_REF}
new substrate commit id ${SUBSTRATE_NEW_REF}
EOT

# okay so now need to fetch the substrate repository and check whether spec_version or impl_version has changed there
SUBSTRATE_CLONE_DIR="$(mktemp -t -d substrate-XXXXXX)"
trap 'rm -rf "${SUBSTRATE_CLONE_DIR}"' INT QUIT TERM ABRT EXIT

git clone --depth="${GIT_DEPTH:-100}" --no-tags \
"${SUBSTRATE_REPO}" "${SUBSTRATE_CLONE_DIR}"

# check if there are changes to the spec|impl versions
git -C "${SUBSTRATE_CLONE_DIR}" diff \
"${SUBSTRATE_PREV_REF}..${SUBSTRATE_NEW_REF}" "${SUBSTRATE_VERSIONS_FILE}" \
| grep -E '^[\+\-][[:space:]]+(spec|impl)_version: +([0-9]+),$' || exit 0

boldcat <<EOT
spec_version or or impl_version have changed in substrate after updating Cargo.lock
please make sure versions are bumped in polkadot accordingly
EOT

# Now check if any of the substrate changes have been tagged D2-breaksapi
(
cd "${SUBSTRATE_CLONE_DIR}"
substrate_changes="$(sanitised_git_logs "${SUBSTRATE_PREV_REF}" "${SUBSTRATE_NEW_REF}")"
echo "$substrate_changes" | while read -r line; do
pr_id=$(echo "$line" | sed -E 's/.*#([0-9]+)\)$/\1/')

if has_label 'paritytech/substrate' "$pr_id" 'D2-breaksapi'; then
boldprint "Substrate change labelled with D2-breaksapi. Labelling..."
github_label "D2-breaksapi"
exit 1
fi
done
)

fi

failed_runtime_checks=()

# Iterate over each runtime defined at the start of the script
for RUNTIME in "${runtimes[@]}"
do

# Check if there were changes to this specific runtime or common directories.
# If not, we can skip to the next runtime
regex="^runtime/$(join_by '|^runtime/' "$RUNTIME" "${common_dirs[@]}")"
if ! git diff --name-only "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" \
| grep -E -q -e "$regex"; then
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.
# Check if there were changes to this specific runtime or common directories.
# If not, we can skip to the next runtime
regex="^runtime/$(join_by '|^runtime/' "$RUNTIME" "${common_dirs[@]}")"
if ! git diff --name-only "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" \
| grep -E -q -e "$regex"; then
continue
fi

add_spec_version="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r "s/^\+[[:space:]]+spec_version: +([0-9]+),$/\1/p"
)"
sub_spec_version="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r "s/^\-[[:space:]]+spec_version: +([0-9]+),$/\1/p"
)"
# 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 "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r "s/^\+[[:space:]]+spec_version: +([0-9]+),$/\1/p"
)"
sub_spec_version="$(
git diff "refs/tags/${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| 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}" ]
then

if git diff --name-only "origin/master...${CI_COMMIT_SHA}" \
| grep -E -q -e "$regex"
then
# add label breaksapi only if this pr altered the runtime sources
github_label "D2-breaksapi"
fi
# see if the version and the binary blob changed
if [ "${add_spec_version}" != "${sub_spec_version}" ]
then

boldcat <<-EOT
## RUNTIME: ${RUNTIME} ##
if git diff --name-only "origin/master...${CI_COMMIT_SHA}" \
| grep -E -q -e "$regex"
then
# add label breaksapi only if this pr altered the runtime sources
github_label "D2-breaksapi"
fi

changes to the ${RUNTIME} runtime sources and changes in the spec version.
boldcat <<EOT
## RUNTIME: ${RUNTIME} ##

spec_version: ${sub_spec_version} -> ${add_spec_version}
changes to the ${RUNTIME} runtime sources and changes in the spec version.

EOT
continue
spec_version: ${sub_spec_version} -> ${add_spec_version}

else
# check for impl_version updates: if only the impl versions changed, we assume
# there is no consensus-critical logic that has changed.
EOT
continue

add_impl_version="$(
git diff refs/tags/"${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r 's/^\+[[:space:]]+impl_version: +([0-9]+),$/\1/p'
)"
sub_impl_version="$(
git diff refs/tags/"${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r 's/^\-[[:space:]]+impl_version: +([0-9]+),$/\1/p'
)"
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 refs/tags/"${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| sed -n -r 's/^\+[[:space:]]+impl_version: +([0-9]+),$/\1/p'
)"
sub_impl_version="$(
git diff refs/tags/"${LATEST_TAG}...${CI_COMMIT_SHA}" "runtime/${RUNTIME}/src/lib.rs" \
| 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
boldcat <<-EOT

## RUNTIME: ${RUNTIME} ##
# see if the impl version changed
if [ "${add_impl_version}" != "${sub_impl_version}" ]
then
boldcat <<EOT

changes to the ${RUNTIME} runtime sources and changes in the impl version.
## RUNTIME: ${RUNTIME} ##

impl_version: ${sub_impl_version} -> ${add_impl_version}
changes to the ${RUNTIME} runtime sources and changes in the impl version.

EOT
continue
fi
impl_version: ${sub_impl_version} -> ${add_impl_version}

EOT
continue
fi

boldcat <<-EOT
wasm source files changed or the spec version in the substrate reference in
the Cargo.lock but not the spec/impl version. If changes made do not alter
logic, just bump 'impl_version'. If they do change logic, bump
'spec_version'.
failed_runtime_checks+=($RUNTIME)
cecton marked this conversation as resolved.
Show resolved Hide resolved
fi
done

source file directories:
- runtime
if [ ${#failed_runtime_checks} -gt 0 ]; then
boldcat <<EOT
wasm source files changed or the spec version in the substrate reference in
the Cargo.lock but not the spec/impl version. If changes made do not alter
logic, just bump 'impl_version'. If they do change logic, bump
'spec_version'.

versions file: ${VERSIONS_FILE}
source file directories:
- runtime

EOT
version files: ${failed_runtime_checks[@]}
EOT

exit 1
fi
done
exit 1
fi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this change to this PR. It's not really related, I just wanted to fix it.

Instead of failing at the first runtime check, it now collects all the runtime check that fails and print them in a single build.

I also converted the file from tabs to spaces because all other bash scripts in this repo are using spaces.


exit 0

# vim: noexpandtab
Loading