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

[CI] Add criticality of release to release notes #1259

Merged
merged 12 commits into from
Jun 17, 2020
4 changes: 1 addition & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ build-wasm-release:
<<: *compiler_info
# Note: We likely only want to do this for tagged releases, hence the 'only:'
only:
# FIXME remove when ready to merge
Copy link
Contributor

Choose a reason for hiding this comment

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

don't forget

- /^[0-9]+$/
# - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
- /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
script:
- time wasm-pack build --target web --out-dir wasm --release cli -- --no-default-features --features browser
- mkdir -p ./artifacts/wasm
Expand Down
42 changes: 32 additions & 10 deletions scripts/gitlab/check_labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,43 @@
#shellcheck source=lib.sh
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh"

ensure_labels() {
for label in "$@"; do
if has_label 'paritytech/polkadot' "$CI_COMMIT_BRANCH" "$label"; then
return 0
fi
done
return 1
}

# Must have one of the following labels
labels=(
releasenotes_labels=(
'B0-silent'
'B1-releasenotes'
'B2-runtimenoteworthy'
)

echo "[+] Checking labels for $CI_COMMIT_BRANCH"
criticality_labels=(
'C1-low'
'C3-medium'
'C7-high'
'C9-critical'
)

echo "[+] Checking release notes (B) labels for $CI_COMMIT_BRANCH"
if ensure_labels "${releasenotes_labels[@]}"; then
echo "[+] Release notes label detected. All is well."
else
echo "[!] Release notes label not detected. Please add one of: ${releasenotes_labels[*]}"
exit 1
fi

for label in "${labels[@]}"; do
if has_label 'paritytech/polkadot' "$CI_COMMIT_BRANCH" "$label"; then
echo "[+] Label $label detected, test passed"
exit 0
fi
done
echo "[+] Checking release criticality (C) labels for $CI_COMMIT_BRANCH"
if ensure_labels "${criticality_labels[@]}"; then
echo "[+] Release criticality label detected. All is well."
else
echo "[!] Release criticality label not detected. Please add one of: ${criticality_labels[*]}"
exit 1
fi

echo "[!] PR does not have one of the required labels! Please add one of: ${labels[*]}"
exit 1
exit 0
103 changes: 96 additions & 7 deletions scripts/gitlab/publish_draft_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,65 @@ This release was built with the following versions of \`rustc\`. Other versions

runtime_changes=""

# Following variables are for tracking the priority of the release (i.e.,
# how important it is for the user to upgrade).
# It's frustrating that we need to make an array of indexes (in this case the
# labels), but it's necessary to maintain the correct order. Labels and
# descriptions *must* be kept in lockstep

priority_labels=(
'C1-low'
'C3-medium'
'C7-high'
'C9-critical'
)

declare -A priority_descriptions=(
['C1-low']="Upgrade priority: Low (upgrade at your convenience)"
['C3-medium']="Upgrade priority: *Medium* (timely upgrade recommended)"
['C7-high']="Upgrade priority:❗ HIGH ❗ Please upgrade your node as soon as possible"
['C9-critical']="Upgrade priority: ❗❗ URGENT ❗❗ PLEASE UPGRADE IMMEDIATELY"
)

max_label=-1
priority="${priority_descriptions['C1-low']}"
declare -a priority_changes

# Iterate through every PR
while IFS= read -r line; do
pr_id=$(echo "$line" | sed -E 's/.*#([0-9]+)\)$/\1/')
if has_label 'paritytech/polkadot' "$pr_id" 'B1-silent'; then

# Release priority check:
# For each PR, we look for every label equal to or higher than the current highest
# I.e., if there has already been a PR marked as 'medium', we only need
# to look for priorities medium or above. If we find one, we set the
# priority to that level.
for ((index=max_label; index<${#priority_labels[@]}; index++)) ; do
cur_label="${priority_labels[$index]}"
echo "[+] Checking #$pr_id for presence of $cur_label label"
if has_label 'paritytech/polkadot' "$pr_id" "$cur_label" ; then
echo "[+] #$pr_id has label $cur_label. Setting max."
prev_label="$max_label"
max_label="$index"
priority="${priority_descriptions[$cur_label]}"
# If it's not an increase in priority, we just append the PR to the list
if [ "$prev_label" == "$max_label" ]; then
priority_changes+=("#$pr_id")
fi
# If the priority has increased, we override previous changes with new changes
if [ "$prev_label" != "$max_label" ]; then
priority_changes=("#$pr_id")
fi
fi
done

# If the PR is labelled silent, we can do an early continue to save a little work
if has_label 'paritytech/polkadot' "$pr_id" 'B0-silent'; then
continue
fi

# If the PR has a runtimenoteworthy label, add to the runtime_changes section
if has_label 'paritytech/polkadot' "$pr_id" 'B1-runtimenoteworthy'; then
if has_label 'paritytech/polkadot' "$pr_id" 'B2-runtimenoteworthy'; then
runtime_changes="$runtime_changes
$line"
else
Expand All @@ -81,10 +132,10 @@ fi
echo "$release_text"

# Get substrate changes between last polkadot version and current
# By grepping the Cargo.lock for a substrate crate, and grepping out the commit hash
cur_substrate_commit=$(grep -A 2 'name = "sc-cli"' Cargo.lock | grep -E -o '[a-f0-9]{40}')
git checkout "$last_version"
old_substrate_commit=$(grep -A 2 'name = "sc-cli"' Cargo.lock | grep -E -o '[a-f0-9]{40}')

old_substrate_commit=$(git diff "refs/tags/$last_version" Cargo.lock |\
grep -A 2 'name = "sc-cli"' | grep -E -o '[a-f0-9]{40}')
pushd $substrate_dir || exit
git checkout master > /dev/null
git pull > /dev/null
Expand All @@ -94,10 +145,37 @@ pushd $substrate_dir || exit
substrate_client_changes=""
substrate_changes=""

# Set initial upgrade priority variables
substrate_max_label=-1
substrate_priority="${priority_descriptions['C1-low']}"

declare -a substrate_priority_changes

echo "[+] Iterating through substrate changes to find labelled PRs"
while IFS= read -r line; do
pr_id=$(echo "$line" | sed -E 's/.*#([0-9]+)\)$/\1/')

# Basically same check as Polkadot priority
# We only need to check for any labels of the current priority or higher
for ((index=substrate_max_label; index<${#priority_labels[@]}; index++)) ; do
cur_label="${priority_labels[$index]}"
echo "[+] Checking substrate/#$pr_id for presence of $cur_label label"
if has_label 'paritytech/substrate' "$pr_id" "$cur_label" ; then
echo "[+] #$pr_id has label $cur_label. Setting max."
prev_label="$substrate_max_label"
substrate_max_label="$index"
substrate_priority="${priority_descriptions[$cur_label]}"
# If it's not an increase in priority, we just append
if [ "$prev_label" == "$max_label" ]; then
substrate_priority_changes+=("paritytech/substrate#$pr_id")
fi
# If the priority has increased, we override previous changes with new changes
if [ "$prev_label" != "$max_label" ]; then
substrate_priority_changes=("paritytech/substrate#$pr_id")
fi
fi
done

# Skip if the PR has the silent label - this allows us to skip a few requests
if has_label 'paritytech/substrate' "$pr_id" 'B0-silent'; then
continue
Expand All @@ -118,8 +196,6 @@ $line"
done <<< "$all_substrate_changes"
popd || exit

echo "[+] Changes generated. Removing temporary repos"

# Make the substrate section if there are any substrate changes
if [ -n "$substrate_runtime_changes" ] ||
[ -n "$substrate_api_changes" ] ||
Expand Down Expand Up @@ -152,6 +228,19 @@ $substrate_api_changes"
$substrate_changes"
fi

# Finally, add the priorities to the *start* of the release notes
# If polkadot and substrate priority = low, no need for list of changes
if [ "$priority" == "${priority_descriptions['C1-low']}" ] &&
[ "$substrate_priority" == "${priority_descriptions['C1-low']}" ]; then
release_text="$priority

$release_text"
else
release_text="$priority - due to change(s): ${priority_changes[*]} ${substrate_priority_changes[*]}

$release_text"
fi

echo "[+] Release text generated: "
echo "$release_text"

Expand Down