From 0c930117606afb4252ecf9cda58504659f698efe Mon Sep 17 00:00:00 2001 From: s3krit Date: Wed, 26 Feb 2020 14:56:18 +0100 Subject: [PATCH] CI: Label PRs with B2-breaksapi if substrate changes are labelled B2-breaksapi (#862) * CI: Split common functions into lib.sh and make... ... alert_pending_release.sh check the substrate changes for various labels. If labelled, will be included in the changelog, otherwise will silently be left out. * replace non-standard /bin/bash with /usr/bin/env bash * CI: make lib.sh /bin/sh-compatible * lib.sh: fix newline chars sometimes breaking has_label() * check_runtime.sh: tag change with 'B2-breaksapi'... ... if any substrate changes are also labelled 'B2-breaksapi' * Remove debug exits and uncomment labelling * exit early if we label with breaksapi * fix publish_draft_release.sh --- polkadot/scripts/gitlab/check_runtime.sh | 25 ++++++++++++++++--- polkadot/scripts/gitlab/lib.sh | 2 +- .../scripts/gitlab/publish_draft_release.sh | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/polkadot/scripts/gitlab/check_runtime.sh b/polkadot/scripts/gitlab/check_runtime.sh index 2169289b5c..51090c6404 100755 --- a/polkadot/scripts/gitlab/check_runtime.sh +++ b/polkadot/scripts/gitlab/check_runtime.sh @@ -16,13 +16,16 @@ set -e # fail on any error +#Include the common functions library +#shellcheck source=lib.sh +. "$(dirname "${0}")/lib.sh" SUBSTRATE_REPO="https://github.com/paritytech/substrate" SUBSTRATE_REPO_CARGO="git\+${SUBSTRATE_REPO}\?branch=polkadot-master" SUBSTRATE_VERSIONS_FILE="bin/node/runtime/src/lib.rs" -boldprint () { printf "|\n| \033[1m${@}\033[0m\n|\n" ; } -boldcat () { printf "|\n"; while read l; do printf "| \033[1m${l}\033[0m\n"; done; printf "|\n" ; } +boldprint () { printf "|\n| \033[1m%s\033[0m\n|\n" "${@}"; } +boldcat () { printf "|\n"; while read -r l; do printf "| \033[1m%s\033[0m\n" "${l}"; done; printf "|\n" ; } # figure out the latest release tag @@ -31,7 +34,7 @@ boldprint "latest release tag ${LATEST_TAG}" boldprint "latest 10 commits of ${CI_COMMIT_REF_NAME}" -git log --graph --oneline --decorate=short -n 10 +git --no-pager log --graph --oneline --decorate=short -n 10 boldprint "make sure the master branch is available in shallow clones" git fetch --depth=${GIT_DEPTH:-100} origin master @@ -106,6 +109,22 @@ then spec_version or or impl_version have changed in substrate after updating Cargo.lock please make sure versions are bumped in polkadot accordingly EOT + + # Now check if any of the substrate changes have been tagged B2-breaksapi + ( + cd "${SUBSTRATE_CLONE_DIR}" + substrate_changes="$(sanitised_git_logs "${SUBSTRATE_PREV_REF}" "${SUBSTRATE_NEW_REF}")" + echo "$substrate_changes" | while read -r line; do + pr_id=$(echo "$line" | sed -E 's/.*#([0-9]+)\)$/\1/') + + if has_label 'paritytech/substrate' "$pr_id" 'B2-breaksapi'; then + boldprint "Substrate change labelled with B2-breaksapi. Labelling..." + github_label "B2-breaksapi" + exit 1 + fi + done + ) + fi diff --git a/polkadot/scripts/gitlab/lib.sh b/polkadot/scripts/gitlab/lib.sh index bc0e06a6d4..7fae82f189 100755 --- a/polkadot/scripts/gitlab/lib.sh +++ b/polkadot/scripts/gitlab/lib.sh @@ -47,7 +47,7 @@ has_label(){ pr_id="$2" label="$3" out=$(curl -H "Authorization: token $GITHUB_RELEASE_TOKEN" -s "$api_base/$repo/pulls/$pr_id") - [ -n "$(echo "$out" | jq ".labels | .[] | select(.name==\"$label\")")" ] + [ -n "$(echo "$out" | tr -d '\r\n' | jq ".labels | .[] | select(.name==\"$label\")")" ] } # Formats a message into a JSON string for posting to Matrix diff --git a/polkadot/scripts/gitlab/publish_draft_release.sh b/polkadot/scripts/gitlab/publish_draft_release.sh index b8c4dedc4e..41c08da4c2 100755 --- a/polkadot/scripts/gitlab/publish_draft_release.sh +++ b/polkadot/scripts/gitlab/publish_draft_release.sh @@ -129,6 +129,6 @@ formatted_msg_body=$(cat <