Unverified Commit 1a0c1e9f authored by s3krit's avatar s3krit Committed by GitHub
Browse files

[CI] Refactor publish_draft_release.sh (#1289)

* Refactor publish_draft_release.sh

* Switch to using arrays for storing labelled changes
* Combine changes for Polkadot and Substrate
* Change sanitised_git_logs in `lib.sh` to drop `*`s at the start
* Only look for priorities of medium or above (presence of one or more
  C1 label is enforeced by check-labels anyway, saves us some API calls)

* Ensure priorities >C1-low aren't labelled B0-silent
parent f6576194
Pipeline #97911 canceled with stages
in 5 minutes and 19 seconds
...@@ -3,9 +3,11 @@ ...@@ -3,9 +3,11 @@
#shellcheck source=lib.sh #shellcheck source=lib.sh
source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh" source "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/lib.sh"
repo='paritytech/polkadot'
ensure_labels() { ensure_labels() {
for label in "$@"; do for label in "$@"; do
if has_label 'paritytech/polkadot' "$CI_COMMIT_BRANCH" "$label"; then if has_label "$repo" "$CI_COMMIT_BRANCH" "$label"; then
return 0 return 0
fi fi
done done
...@@ -19,7 +21,7 @@ releasenotes_labels=( ...@@ -19,7 +21,7 @@ releasenotes_labels=(
'B2-runtimenoteworthy' 'B2-runtimenoteworthy'
) )
criticality_labels=( priority_labels=(
'C1-low' 'C1-low'
'C3-medium' 'C3-medium'
'C7-high' 'C7-high'
...@@ -34,11 +36,19 @@ else ...@@ -34,11 +36,19 @@ else
exit 1 exit 1
fi fi
echo "[+] Checking release criticality (C) labels for $CI_COMMIT_BRANCH" echo "[+] Checking release priority (C) labels for $CI_COMMIT_BRANCH"
if ensure_labels "${criticality_labels[@]}"; then if ensure_labels "${priority_labels[@]}"; then
echo "[+] Release criticality label detected. All is well." echo "[+] Release priority label detected. All is well."
else else
echo "[!] Release criticality label not detected. Please add one of: ${criticality_labels[*]}" echo "[!] Release priority label not detected. Please add one of: ${priority_labels[*]}"
exit 1
fi
# If the priority is anything other than C1-low, we *must not* have a B0-silent
# label
if has_label "$repo" "$CI_COMMIT_BRANCH" 'B0-silent' &&
! has_label "$repo" "$CI_COMMIT_BRANCH" 'C1-low' ; then
echo "[!] Changes with a priority higher than C1-low *MUST* have a B- label that is not B0-Silent"
exit 1 exit 1
fi fi
......
...@@ -9,9 +9,7 @@ sanitised_git_logs(){ ...@@ -9,9 +9,7 @@ sanitised_git_logs(){
# Only find messages referencing a PR # Only find messages referencing a PR
grep -E '\(#[0-9]+\)' | grep -E '\(#[0-9]+\)' |
# Strip any asterisks # Strip any asterisks
sed 's/^* //g' | sed 's/^* //g'
# And add them all back
sed 's/^/* /g'
} }
# Checks whether a tag on github has been verified # Checks whether a tag on github has been verified
......
...@@ -50,7 +50,9 @@ This release was built with the following versions of \`rustc\`. Other versions ...@@ -50,7 +50,9 @@ This release was built with the following versions of \`rustc\`. Other versions
- $nightly_rustc - $nightly_rustc
" "
runtime_changes="" declare -a misc_changes
declare -a runtime_changes
declare -a client_changes
# Following variables are for tracking the priority of the release (i.e., # Following variables are for tracking the priority of the release (i.e.,
# how important it is for the user to upgrade). # how important it is for the user to upgrade).
...@@ -72,7 +74,9 @@ declare -A priority_descriptions=( ...@@ -72,7 +74,9 @@ declare -A priority_descriptions=(
['C9-critical']="Upgrade priority: ❗❗ **URGENT** ❗❗ PLEASE UPGRADE IMMEDIATELY" ['C9-critical']="Upgrade priority: ❗❗ **URGENT** ❗❗ PLEASE UPGRADE IMMEDIATELY"
) )
max_label=-1 # We don't actually take any action on C1-low, so we can start at medium
# But set C1-low as the default
max_label=1
priority="${priority_descriptions['C1-low']}" priority="${priority_descriptions['C1-low']}"
declare -a priority_changes declare -a priority_changes
...@@ -93,6 +97,7 @@ while IFS= read -r line; do ...@@ -93,6 +97,7 @@ while IFS= read -r line; do
prev_label="$max_label" prev_label="$max_label"
max_label="$index" max_label="$index"
priority="${priority_descriptions[$cur_label]}" priority="${priority_descriptions[$cur_label]}"
# If it's not an increase in priority, we just append the PR to the list # If it's not an increase in priority, we just append the PR to the list
if [ "$prev_label" == "$max_label" ]; then if [ "$prev_label" == "$max_label" ]; then
priority_changes+=("${line/\* /}") priority_changes+=("${line/\* /}")
...@@ -101,6 +106,12 @@ while IFS= read -r line; do ...@@ -101,6 +106,12 @@ while IFS= read -r line; do
if [ "$prev_label" != "$max_label" ]; then if [ "$prev_label" != "$max_label" ]; then
priority_changes=("${line/\* /}") priority_changes=("${line/\* /}")
fi fi
# Append priority to change
# Skip first 3 chars
note=${cur_label:3}
# And capitalise
line=" \`${note^}\` $line"
fi fi
done done
...@@ -111,26 +122,16 @@ while IFS= read -r line; do ...@@ -111,26 +122,16 @@ while IFS= read -r line; do
# If the PR has a runtimenoteworthy label, add to the runtime_changes section # If the PR has a runtimenoteworthy label, add to the runtime_changes section
if has_label 'paritytech/polkadot' "$pr_id" 'B2-runtimenoteworthy'; then if has_label 'paritytech/polkadot' "$pr_id" 'B2-runtimenoteworthy'; then
runtime_changes="$runtime_changes runtime_changes+=("$line")
$line"
fi fi
# If the PR has a releasenotes label, add to the release section # If the PR has a releasenotes label, add to the release section
if has_label 'paritytech/polkadot' "$pr_id" 'B1-releasenotes'; then if has_label 'paritytech/polkadot' "$pr_id" 'B1-releasenotes'; then
release_text="$release_text misc_changes+=("$line")
$line"
fi fi
done <<< "$(sanitised_git_logs "$last_version" "$version" | \ done <<< "$(sanitised_git_logs "$last_version" "$version" | \
sed '/^\[contracts\].*/d' | \ sed '/^\[contracts\].*/d' | \
sed '/^contracts:.*/d' )" sed '/^contracts:.*/d' )"
if [ -n "$runtime_changes" ]; then
release_text="$release_text
## Runtime
$runtime_changes"
fi
echo "$release_text"
# Get substrate changes between last polkadot version and current # Get substrate changes between last polkadot version and current
# By grepping the Cargo.lock for a substrate crate, and grepping out the commit hash # 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}') cur_substrate_commit=$(grep -A 2 'name = "sc-cli"' Cargo.lock | grep -E -o '[a-f0-9]{40}')
...@@ -140,10 +141,6 @@ pushd $substrate_dir || exit ...@@ -140,10 +141,6 @@ pushd $substrate_dir || exit
git checkout master > /dev/null git checkout master > /dev/null
git pull > /dev/null git pull > /dev/null
all_substrate_changes="$(sanitised_git_logs "$old_substrate_commit" "$cur_substrate_commit" | sed 's/(#/(paritytech\/substrate#/')" all_substrate_changes="$(sanitised_git_logs "$old_substrate_commit" "$cur_substrate_commit" | sed 's/(#/(paritytech\/substrate#/')"
substrate_runtime_changes=""
substrate_api_changes=""
substrate_client_changes=""
substrate_changes=""
echo "[+] Iterating through substrate changes to find labelled PRs" echo "[+] Iterating through substrate changes to find labelled PRs"
while IFS= read -r line; do while IFS= read -r line; do
...@@ -159,6 +156,7 @@ pushd $substrate_dir || exit ...@@ -159,6 +156,7 @@ pushd $substrate_dir || exit
prev_label="$max_label" prev_label="$max_label"
max_label="$index" max_label="$index"
priority="${priority_descriptions[$cur_label]}" priority="${priority_descriptions[$cur_label]}"
# If it's not an increase in priority, we just append # If it's not an increase in priority, we just append
if [ "$prev_label" == "$max_label" ]; then if [ "$prev_label" == "$max_label" ]; then
priority_changes+=("${line/\* /}") priority_changes+=("${line/\* /}")
...@@ -167,6 +165,12 @@ pushd $substrate_dir || exit ...@@ -167,6 +165,12 @@ pushd $substrate_dir || exit
if [ "$prev_label" != "$max_label" ]; then if [ "$prev_label" != "$max_label" ]; then
priority_changes=("${line/\* /}") priority_changes=("${line/\* /}")
fi fi
# Append priority to change
# Skip first 3 chars
note=${cur_label:3}
# And capitalise
line=" \`${note^}\` $line"
fi fi
done done
...@@ -174,55 +178,17 @@ pushd $substrate_dir || exit ...@@ -174,55 +178,17 @@ pushd $substrate_dir || exit
if has_label 'paritytech/substrate' "$pr_id" 'B0-silent'; then if has_label 'paritytech/substrate' "$pr_id" 'B0-silent'; then
continue continue
fi fi
if has_label 'paritytech/substrate' "$pr_id" 'B3-apinoteworthy' ; then
substrate_api_changes="$substrate_api_changes
$line"
continue
fi
if has_label 'paritytech/substrate' "$pr_id" 'B5-clientnoteworthy'; then if has_label 'paritytech/substrate' "$pr_id" 'B5-clientnoteworthy'; then
substrate_client_changes="$substrate_client_changes client_changes+=("$line")
$line"
fi fi
if has_label 'paritytech/substrate' "$pr_id" 'B7-runtimenoteworthy'; then if has_label 'paritytech/substrate' "$pr_id" 'B7-runtimenoteworthy'; then
substrate_runtime_changes="$substrate_runtime_changes runtime_changes+=("$line")
$line"
fi fi
done <<< "$all_substrate_changes" done <<< "$all_substrate_changes"
popd || exit popd || exit
# Make the substrate section if there are any substrate changes
if [ -n "$substrate_runtime_changes" ] ||
[ -n "$substrate_api_changes" ] ||
[ -n "$substrate_client_changes" ]; then
substrate_changes=$(cat << EOF
# Substrate changes
EOF
)
if [ -n "$substrate_runtime_changes" ]; then
substrate_changes="$substrate_changes
## Runtime
$substrate_runtime_changes"
fi
if [ -n "$substrate_client_changes" ]; then
substrate_changes="$substrate_changes
## Client
$substrate_client_changes"
fi
if [ -n "$substrate_api_changes" ]; then
substrate_changes="$substrate_changes
## API
$substrate_api_changes"
fi
release_text="$release_text
$substrate_changes"
fi
# Finally, add the priorities to the *start* of the release notes # Add the priorities to the *start* of the release notes
# If polkadot and substrate priority = low, no need for list of changes # If polkadot and substrate priority = low, no need for list of changes
if [ "$priority" == "${priority_descriptions['C1-low']}" ]; then if [ "$priority" == "${priority_descriptions['C1-low']}" ]; then
release_text="$priority release_text="$priority
...@@ -234,6 +200,29 @@ else ...@@ -234,6 +200,29 @@ else
$release_text" $release_text"
fi fi
# Append all notable changes to the release notes
if [ "${#misc_changes[*]}" -gt 0 ] ; then
release_text="$release_text
## Changes
$(printf '* %s\n' "${misc_changes[@]}")"
fi
if [ "${#client_changes[*]}" -gt 0 ] ; then
release_text="$release_text
## Client
$(printf '* %s\n' "${client_changes[@]}")"
fi
if [ "${#runtime_changes[*]}" -gt 0 ] ; then
release_text="$release_text
## Runtime
$(printf '* %s\n' "${runtime_changes[@]}")"
fi
echo "[+] Release text generated: " echo "[+] Release text generated: "
echo "$release_text" echo "$release_text"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment