Move scripts used in CI to the new location (#11008)

Move scripts used in CI to the new location - **./scripts/ci/**

* Move github scripts

* Move more files

* Move ci scripts and fix dependencies

* Update docs/node-template-release.md

Co-authored-by: João Paulo Silva de Souza <77391175+joao-paulo-parity@users.noreply.github.com>

* Remove Cargo.lock

* Apply suggestions from code review

Co-authored-by: Denis Pisarev <denis.pisarev@parity.io>

* Make more paths uniform

Co-authored-by: João Paulo Silva de Souza <77391175+joao-paulo-parity@users.noreply.github.com>
Co-authored-by: Denis Pisarev <denis.pisarev@parity.io>
This commit is contained in:
Sergejs Kostjucenko
2022-03-14 10:42:34 +02:00
committed by GitHub
parent 42484508d7
commit 46891e849f
25 changed files with 35 additions and 35 deletions
+121
View File
@@ -0,0 +1,121 @@
#!/bin/sh
#
#
# check for any changes in the node/src/runtime, frame/ and primitives/sr_* trees. if
# there are any changes found, it should mark the PR breaksconsensus and
# "auto-fail" the PR if there isn't a change in the runtime/src/lib.rs file
# that alters the version.
set -e # fail on any error
#shellcheck source=../common/lib.sh
. "$(dirname "${0}")/../common/lib.sh"
VERSIONS_FILE="bin/node/runtime/src/lib.rs"
boldprint () { printf "|\n| \033[1m%s\033[0m\n|\n" "${@}"; }
boldcat () { printf "|\n"; while read -r l; do printf "| \033[1m%s\033[0m\n" "${l}"; done; printf "|\n" ; }
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}" \
"${GITLAB_API}/projects/${GITHUB_API_PROJECT}/trigger/pipeline"
}
boldprint "latest 10 commits of ${CI_COMMIT_REF_NAME}"
git log --graph --oneline --decorate=short -n 10
boldprint "make sure the master branch and release tag are available in shallow clones"
git fetch --depth="${GIT_DEPTH:-100}" origin master
git fetch --depth="${GIT_DEPTH:-100}" origin release
git tag -f release FETCH_HEAD
git log -n1 release
boldprint "check if the wasm sources changed"
if ! has_runtime_changes origin/master "${CI_COMMIT_SHA}"
then
boldcat <<-EOT
no changes to the runtime source code detected
EOT
exit 0
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 tags/release ${CI_COMMIT_SHA} -- "${VERSIONS_FILE}" \
| sed -n -r "s/^\+[[:space:]]+spec_version: +([0-9]+),$/\1/p")"
sub_spec_version="$(git diff tags/release ${CI_COMMIT_SHA} -- "${VERSIONS_FILE}" \
| sed -n -r "s/^\-[[:space:]]+spec_version: +([0-9]+),$/\1/p")"
if [ "${add_spec_version}" != "${sub_spec_version}" ]
then
boldcat <<-EOT
changes to the runtime sources and changes in the spec version.
spec_version: ${sub_spec_version} -> ${add_spec_version}
EOT
exit 0
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 tags/release ${CI_COMMIT_SHA} -- "${VERSIONS_FILE}" \
| sed -n -r 's/^\+[[:space:]]+impl_version: +([0-9]+),$/\1/p')"
sub_impl_version="$(git diff tags/release ${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
boldcat <<-EOT
changes to the runtime sources and changes in the impl version.
impl_version: ${sub_impl_version} -> ${add_impl_version}
EOT
exit 0
fi
boldcat <<-EOT
wasm source files changed 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'.
source file directories:
- bin/node/src/runtime
- frame
- primitives/sr-*
versions file: ${VERSIONS_FILE}
EOT
fi
# dropped through. there's something wrong; exit 1.
exit 1
# vim: noexpandtab
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
# shellcheck source=../common/lib.sh
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh"
version="$CI_COMMIT_TAG"
echo '[+] Checking tag has been signed'
check_tag "paritytech/substrate" "$version"
case $? in
0) echo '[+] Tag found and has been signed'; exit 0
;;
1) echo '[!] Tag found but has not been signed. Aborting release.'; exit 1
;;
2) echo '[!] Tag not found. Aborting release.'; exit 1
esac
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env bash
# The script is meant to check if the rules regarding packages
# dependencies are satisfied.
# The general format is:
# [top-lvl-dir] MESSAGE/[other-top-dir]
# For instance no crate within `./client` directory
# is allowed to import any crate with a directory path containing `frame`.
# Such rule is just: `client crates must not depend on anything in /frame`.
# The script should be run from the main repo directory!
set -u
# HARD FAILING
MUST_NOT=(
"client crates must not depend on anything in /frame"
"client crates must not depend on anything in /node"
"frame crates must not depend on anything in /node"
"frame crates must not depend on anything in /client"
"primitives crates must not depend on anything in /frame"
)
# ONLY DISPLAYED, script still succeeds
PLEASE_DONT=(
"primitives crates should not depend on anything in /client"
)
VIOLATIONS=()
PACKAGES=()
function check_rule() {
rule=$1
from=$(echo $rule | cut -f1 -d\ )
to=$(echo $rule | cut -f2 -d\/)
cd $from
echo "Checking rule '$rule'"
packages=$(find -name Cargo.toml | xargs grep -wn "path.*\.\.\/$to")
has_references=$(echo -n $packages | wc -c)
if [ "$has_references" != "0" ]; then
VIOLATIONS+=("$rule")
# Find packages that violate:
PACKAGES+=("$packages")
fi
cd - > /dev/null
}
for rule in "${MUST_NOT[@]}"
do
check_rule "$rule";
done
# Only the MUST NOT will be counted towards failure
HARD_VIOLATIONS=${#VIOLATIONS[@]}
for rule in "${PLEASE_DONT[@]}"
do
check_rule "$rule";
done
# Display violations and fail
I=0
for v in "${VIOLATIONS[@]}"
do
cat << EOF
===========================================
======= Violation of rule: $v
===========================================
${PACKAGES[$I]}
EOF
I=$I+1
done
exit $HARD_VIOLATIONS
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
# shellcheck source=../common/lib.sh
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../common/lib.sh"
version="$CI_COMMIT_TAG"
# Note that this is not the last *tagged* version, but the last *published* version
last_version=$(last_github_release 'paritytech/substrate')
release_text="$(./generate_release_text.sh "$last_version" "$version")"
echo "[+] Pushing release to github"
# Create release on github
release_name="Substrate $version"
data=$(jq -Rs --arg version "$version" \
--arg release_name "$release_name" \
--arg release_text "$release_text" \
'{
"tag_name": $version,
"target_commitish": "master",
"name": $release_name,
"body": $release_text,
"draft": true,
"prerelease": false
}' < /dev/null)
out=$(curl -s -X POST --data "$data" -H "Authorization: token $GITHUB_RELEASE_TOKEN" "$api_base/paritytech/substrate/releases")
html_url=$(echo "$out" | jq -r .html_url)
if [ "$html_url" == "null" ]
then
echo "[!] Something went wrong posting:"
echo "$out"
else
echo "[+] Release draft created: $html_url"
fi
echo '[+] Sending draft release URL to Matrix'
msg_body=$(cat <<EOF
**Release pipeline for Substrate $version complete.**
Draft release created: $html_url
EOF
)
formatted_msg_body=$(cat <<EOF
<strong>Release pipeline for Substrate $version complete.</strong><br />
Draft release created: $html_url
EOF
)
send_message "$(structure_message "$msg_body" "$formatted_msg_body")" "$MATRIX_ROOM_ID" "$MATRIX_ACCESS_TOKEN"
echo "[+] Done! Maybe the release worked..."
+14
View File
@@ -0,0 +1,14 @@
#!/bin/sh
url="https://api.github.com/repos/paritytech/substrate/pulls/${CI_COMMIT_REF_NAME}"
echo "[+] API URL: $url"
draft_state=$(curl -H "Authorization: token ${GITHUB_PR_TOKEN}" "$url" | jq -r .draft)
echo "[+] Draft state: $draft_state"
if [ "$draft_state" = 'true' ]; then
echo "[!] PR is currently a draft, stopping pipeline"
exit 1
else
echo "[+] PR is not a draft. Proceeding with CI pipeline"
exit 0
fi