forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update and rename release.sh to release_lib.sh
- Loading branch information
1 parent
8e6e10a
commit 78d4de1
Showing
2 changed files
with
102 additions
and
26 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Set the new version by replacing the value of the constant given as patetrn | ||
# in the file. | ||
# | ||
# input: pattern, version, file | ||
#output: none | ||
set_version() { | ||
pattern=$1 | ||
version=$2 | ||
file=$3 | ||
|
||
sed -i "s/$pattern/\1\"${version}\"/g" $file | ||
return 0 | ||
} | ||
|
||
# Commit changes to git with specific message. | ||
# "|| true" does not let script to fail with exit code 1, | ||
# in case there is nothing to commit. | ||
# | ||
# input: MESSAGE (any message which should be used for the commit) | ||
# output: none | ||
commit_with_message() { | ||
MESSAGE=$1 | ||
git commit -a -m "$MESSAGE" || true | ||
} | ||
|
||
# Retun list of the runtimes filterd based on the repo (i.e. cumulus or polkadot) | ||
# input: repo (cumulus, polkadot) | ||
# output: list of filtered runtimes | ||
get_filtered_runtimes_list_for_repo() { | ||
repo=$1 | ||
grep_filters=("runtime.*" "test|template|starters|substrate") | ||
|
||
git grep spec_version: | grep .rs: | grep -e "${grep_filters[0]}" | grep "lib.rs" | grep -vE "${grep_filters[1]}" | cut -d: -f1 | ||
} | ||
|
||
# Sets provided spec version | ||
# input: version | ||
set_spec_versions() { | ||
NEW_VERSION=$1 | ||
runtimes_list=(${@:2}) | ||
|
||
printf "Setting spec_version to $NEW_VERSION, please prepare your Yubikey and be ready to tap it" | ||
|
||
for f in ${runtimes_list[@]}; do | ||
printf " processing $f" | ||
sed -ri "s/spec_version: [0-9]+_[0-9]+_[0-9]+,/spec_version: $NEW_VERSION,/" $f | ||
done | ||
|
||
commit_with_message "Bump spec_version to $NEW_VERSION" | ||
|
||
git_show_log 'spec_version' | ||
} | ||
|
||
# Displays formated results of the git log command | ||
# for the given pattern which needs to be found in logs | ||
# input: pattern, count (optional, default is 10) | ||
git_show_log() { | ||
PATTERN="$1" | ||
COUNT=${2:-10} | ||
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=iso-strict | \ | ||
head -n $COUNT | grep -iE "$PATTERN" --color=always -z | ||
} | ||
|
||
# Get a spec_version number from the crate version | ||
# | ||
# ## inputs | ||
# - v1.12.0 or 1.12.0 | ||
# | ||
# ## output: | ||
# 1_012_000 or 1_012_001 if SUFFIX is set | ||
function get_spec_version() { | ||
INPUT=$1 | ||
SUFFIX=${SUFFIX:-000} #this variable makes it possible to set a specific ruuntime version like 93826 it can be intialised as sestem variable | ||
[[ $INPUT =~ .*([0-9]+\.[0-9]+\.[0-9]{1,2}).* ]] | ||
VERSION="${BASH_REMATCH[1]}" | ||
MATCH="${BASH_REMATCH[0]}" | ||
if [ -z $MATCH ]; then | ||
return 1 | ||
else | ||
SPEC_VERSION="$(sed -e "s/\./_0/g" -e "s/_[^_]*\$/_$SUFFIX/" <<< $VERSION)" | ||
echo "$SPEC_VERSION" | ||
return 0 | ||
fi | ||
} | ||
|
||
# Reorganize the prdoc files for the release | ||
# | ||
# input: VERSION (e.g. v1.0.0) | ||
# output: none | ||
reorder_prdocs() { | ||
VERSION="$1" | ||
|
||
printf "[+] ℹ️ Reordering prdocs:" | ||
|
||
VERSION=$(sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+).*$/\1/' <<< "$VERSION") #getting reed of the 'v' prefix | ||
mkdir -p "prdoc/$VERSION" | ||
mv prdoc/pr_*.prdoc prdoc/$VERSION | ||
git add -A | ||
commit_with_message "Reordering prdocs for the release $VERSION" | ||
} |