Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import some scripts from other repositories #86

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
63 changes: 63 additions & 0 deletions check-each-crate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

## A script that runs "cargo check" for each workspace crate individually. It's
## relevant to check workspace crates individually because otherwise their
## compilation problems due to feature misconfigurations won't be caught, as
## exemplified by https://github.com/paritytech/substrate/issues/12705.
## Crates are partitioned into groups based on $target_group and $groups_total,
## where each group has ($crates_total / $groups_total) crates within it. Those
## groups can be used in parallel for speeding up the checks' overall time to
## completion while minimizing redundant work between runners.
## For example usage within GitLab CI, see:
## https://github.com/paritytech/substrate/blob/f80c370cdce7c996e8bf8710b6522dac639fbab0/scripts/ci/gitlab/pipeline/test.yml#L427

set -Eeu -o pipefail
shopt -s inherit_errexit

set -vx

# $target_group is the number of the group to be executed in this run, from
# 1..$groups_total (inclusive)
target_group="$1"
Copy link
Contributor

Choose a reason for hiding this comment

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

could you please describe how the target group look like? so it's a bit more clear how to test this e.g. the context you run it and examples of where you get these groups

# $groups_total is the total amount of groups
groups_total="$2"

readarray -t workspace_crates < <(\
cargo tree --workspace --depth 0 --prefix none |
awk '{ if (length($1) == 0 || substr($1, 1, 1) == "[") { skip } else { print $1 } }' |
sort |
uniq
)

crates_total=${#workspace_crates[*]}
if [ "$crates_total" -lt 1 ]; then
>&2 echo "No crates detected for $PWD"
exit 1
fi

if [ "$crates_total" -lt "$groups_total" ]; then
# `crates_total / groups_total` would result in 0, so round it up to 1
crates_per_group=1
else
# We add `crates_total % groups_total > 0` (which evaluates to 1 in case there's a remainder for
# `crates_total % groups_total`) to round UP `crates_total / groups_total` 's
# potentially-fractional result to the nearest integer. Doing that ensures that we'll not miss any
# crate in case `crates_total / groups_total` would normally result in a fractional number, since
# in those cases Bash would round DOWN the result to the nearest integer. For example, if
# `crates_total = 5` and `groups_total = 2`, then `crates_total / groups_total` would round down
# to 2; since the loop below would then step by 2, we'd miss the 5th crate.
crates_per_group=$(( (crates_total / groups_total) + (crates_total % groups_total > 0) ))
fi

group=1
for ((i=0; i < crates_total; i += crates_per_group)); do
if [ $group -eq "$target_group" ]; then
crates_in_group=("${workspace_crates[@]:$i:$crates_per_group}")
echo "crates in the group: ${crates_in_group[*]}" >/dev/null # >/dev/null due to "set -x"
for crate in "${crates_in_group[@]}"; do
cargo check --locked --release -p "$crate"
done
break
fi
group=$(( group + 1 ))
done
59 changes: 59 additions & 0 deletions create-benchmark-pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

## A script that generates a link to the weights comparison tool, then creates a
## PR with the generated link in its description.
Copy link
Contributor

Choose a reason for hiding this comment

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

would be cool to add info where is it used (integrated) and why. How people get the link to PR or how is it used overall

## Its usage started in Cumulus to create a PR for updating weights generated from CI jobs:
## https://github.com/paritytech/cumulus/blob/e4855e352f972f59a2d5941d7bce2d5174ab34ee/scripts/ci/gitlab/pipeline/benchmarks.yml#L31
## See https://github.com/paritytech/cumulus/pull/1789 for an example of using it.

set -Eeu -o pipefail
shopt -s inherit_errexit

PR_TITLE="$1"
HEAD_REF="$2"

ORG="{ORG:-paritytech}"
REPO="$CI_PROJECT_NAME"
BASE_REF="$CI_COMMIT_BRANCH"
# Change threshold in %. Bigger values excludes the small changes.
THRESHOLD=${THRESHOLD:-30}

WEIGHTS_COMPARISON_URL_PARTS=(
"https://weights.tasty.limo/compare?"
"repo=$REPO&"
"threshold=$THRESHOLD&"
"path_pattern=**%2Fweights%2F*.rs&"
"method=guess-worst&"
"ignore_errors=true&"
"unit=time&"
"old=$BASE_REF&"
"new=$HEAD_REF"
)
printf -v WEIGHTS_COMPARISON_URL %s "${WEIGHTS_COMPARISON_URL_PARTS[@]}"

PAYLOAD="$(jq -n \
--arg title "$PR_TITLE" \
--arg body "
This PR is generated automatically by CI.

Compare the weights with \`$BASE_REF\`: $WEIGHTS_COMPARISON_URL

- [ ] Backport to master and node release branch once merged
" \
--arg base "$BASE_REF" \
--arg head "$HEAD_REF" \
'{
title: $title,
body: $body,
head: $head,
base: $base
}'
)"

echo "PAYLOAD: $PAYLOAD"

curl \
-H "Authorization: token $GITHUB_TOKEN" \
-X POST \
-d "$PAYLOAD" \
"https://api.github.com/repos/$ORG/$REPO/pulls"