Skip to content

Commit

Permalink
feat(nervous-system): Filter out boring commits when listing new NNS …
Browse files Browse the repository at this point in the history
…and SNS commits. (#1647)

Overall, tries to make list-new-commits.sh more ergonomic.


# Ergonomics

Boring is defined as having one of the following Conventional Commits
prefixes:

- chore
- refactor
- test

Colorizes.

When commit ID is not supplied, warns that one is chosen automatically.
(When I originally sent this out for review, commit ID was required, but
feedback said this is too inconvenient. So, I switched to printing a
warning.)


# Entrained Change(s)

Factored out common code from two loops (one for NNS, the other for
SNS).

Adds more print_* colors.


# Possible Future Work (no promises)

Instead of manually reviewing which canisters to upgrade, this could be
used to make that choice for us (using the same criterion for using
green to print the canister heading). This would help streamline our
releases, and in particular, reduce the release tsar's workload.
  • Loading branch information
daniel-wong-dfinity-org authored Sep 30, 2024
1 parent 0b217d3 commit 90e12e0
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 28 deletions.
20 changes: 15 additions & 5 deletions testnet/tools/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,37 @@ repo_root() {
}

RED_TEXT='\033[0;31m'
YELLOW_TEXT='\033[0;33m'
GREEN_TEXT='\033[0;32m'
YELLOW_TEXT='\033[0;33m'
BLUE_TEXT='\033[0;34m'
PURPLE_TEXT='\033[0;35m'
CYAN_TEXT='\033[0;36m'
NO_COLOR='\033[0m'

print_red() {
echo -e "${RED_TEXT}$*${NO_COLOR}" 1>&2
}

print_yellow() {
echo -e "${YELLOW_TEXT}$*${NO_COLOR}" 1>&2
}

print_green() {
echo -e "${GREEN_TEXT}$*${NO_COLOR}"
}

print_yellow() {
echo -e "${YELLOW_TEXT}$*${NO_COLOR}" 1>&2
}

print_blue() {
echo -e "${BLUE_TEXT}$*${NO_COLOR}"
}

print_purple() {
echo -e "${PURPLE_TEXT}$*${NO_COLOR}"
}

print_cyan() {
echo -e "${CYAN_TEXT}$*${NO_COLOR}"
}

info() {
print_green "***** $*"
}
Expand Down
105 changes: 82 additions & 23 deletions testnet/tools/nns-tools/list-new-commits.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ source "$NNS_TOOLS_DIR/lib/include.sh"

help() {
print_green "
Usage: $0 (<COMMIT_ID>)
Usage: $0 <COMMIT_ID>
COMMIT_ID: The commit ID to compare to
Prints unreleased canister git logs. This indicates which canisters should be
Expand All @@ -19,39 +19,98 @@ Usage: $0 (<COMMIT_ID>)
exit 1
}

if [ $# -gt 1 ]; then
help
RELEASE_CANDIDATE_COMMIT_ID="${1:-GARBAGE}"

AUTO_COMMIT_ID=false
if [[ "${RELEASE_CANDIDATE_COMMIT_ID}" == 'GARBAGE' ]]; then
RELEASE_CANDIDATE_COMMIT_ID=$(latest_commit_with_prebuilt_artifacts 2>/dev/null)
AUTO_COMMIT_ID=true

COMMIT_DESCRIPTION=$(git show -s --format="%h (%cd)" --date=relative "${RELEASE_CANDIDATE_COMMIT_ID}")
echo
print_yellow "⚠️ Using the latest commit with prebuilt artifacts: ${COMMIT_DESCRIPTION}"
fi

LATEST_ARTIFACTS_COMMIT=$(latest_commit_with_prebuilt_artifacts 2>/dev/null)
NETWORK=ic

list_new_canister_commits() {
CANISTER_NAME="${1}"
# Notice plural. Multiple values are separated by space. Because bash.
CODE_DIRECTORIES="${2}"
LATEST_RELEASED_COMMIT_ID="${3}"

RANGE="${LATEST_RELEASED_COMMIT_ID}..${RELEASE_CANDIDATE_COMMIT_ID}"
NEW_COMMITS=$(
git \
--no-pager \
log \
--format="%C(auto) %h %s" \
"${RANGE}" \
-- \
${CODE_DIRECTORIES} # No quote here is necessary, because plural.
)

RELEASE_CANDIDATE_COMMIT_ID=${1:-$LATEST_ARTIFACTS_COMMIT}
echo "Listing commits from:" "$RELEASE_CANDIDATE_COMMIT_ID"
INTERESTING_COMMITS=$(
grep -v -E ' .{10} (chore|refactor|test)\b' <<<"$NEW_COMMITS" \
|| true
)

echo NNS
echo =====
COMMIT_COUNT=$(grep . <<<"$NEW_COMMITS" | wc -l || true)
INTERESTING_COMMIT_COUNT=$(grep . <<<"$INTERESTING_COMMITS" | wc -l || true)

for canister_name in "${NNS_CANISTERS[@]}"; do
# Compose heading for canister.
HEADING=$(printf "%-14s" "${CANISTER_NAME}") # Add space padding on right of canister name.
HEADING="${HEADING} ${COMMIT_COUNT} new commits"
if [[ "${COMMIT_COUNT}" -gt 0 ]]; then
if [[ "${INTERESTING_COMMIT_COUNT}" -eq 0 ]]; then
INTERESTING=NONE
else
INTERESTING="${INTERESTING_COMMIT_COUNT}"
fi
HEADING="${HEADING}, ${INTERESTING} interesting"
fi

# Print heading.
echo
echo Canister: "$canister_name"
if [[ "${INTERESTING_COMMIT_COUNT}" -gt 0 || "${COMMIT_COUNT}" -ge 5 ]]; then
print_green "${HEADING}"
else
print_cyan "${HEADING}"
fi

# Print commits.
if [[ "${INTERESTING_COMMITS}" != "" ]]; then
echo "${INTERESTING_COMMITS}"
fi
}

# Begin main.

network=ic
released_commit_id=$(nns_canister_git_version "$network" "$canister_name" 2>/dev/null)
root=$(get_nns_canister_code_location "$canister_name")
git --no-pager log --format="%C(auto) %h %s" "$released_commit_id".."$RELEASE_CANDIDATE_COMMIT_ID" -- $root
echo
print_purple NNS
print_purple =====

for CANISTER_NAME in "${NNS_CANISTERS[@]}"; do
LATEST_RELEASED_COMMIT_ID=$(nns_canister_git_version "${NETWORK}" "${CANISTER_NAME}" 2>/dev/null)
CODE_DIRECTORIES=$(get_nns_canister_code_location "${CANISTER_NAME}")

list_new_canister_commits "${CANISTER_NAME}" "${CODE_DIRECTORIES}" "${LATEST_RELEASED_COMMIT_ID}"
done

echo
echo
echo SNS
echo =====
print_purple SNS
print_purple =====

for canister_name in "${SNS_CANISTERS[@]}"; do
echo
echo Canister: "$canister_name"
for CANISTER_NAME in "${SNS_CANISTERS[@]}"; do
LATEST_RELEASED_COMMIT_ID=$(sns_mainnet_git_commit_id "${CANISTER_NAME}")
CODE_DIRECTORIES=$(get_sns_canister_code_location "${CANISTER_NAME}")

network=ic
released_commit_id=$(sns_mainnet_git_commit_id "$canister_name")
root=$(get_sns_canister_code_location "$canister_name")
git --no-pager log --format="%C(auto) %h %s" "$released_commit_id".."$RELEASE_CANDIDATE_COMMIT_ID" -- $root
list_new_canister_commits "${CANISTER_NAME}" "${CODE_DIRECTORIES}" "${LATEST_RELEASED_COMMIT_ID}"
done

if [[ "${AUTO_COMMIT_ID}" == true ]]; then
echo
echo
print_yellow "⚠️ Used the latest commit with prebuilt artifacts: ${RELEASE_CANDIDATE_COMMIT_ID}"
fi

0 comments on commit 90e12e0

Please sign in to comment.