grafana/scripts/check-breaking-changes.sh
Levente Balogh 3f554f58bd
Detecting breaking changes (#42934)
* chore: add a script for detecting breaking changes

* chore: add a temporary binary for POC3

* chore: add a Github Action workflow for detecting breaking changes

* chore: remove unused variables from the script

* chore: rename the POC3 executable script

* chore: add a label if there is a breaking change

* chore: remove "breaking change" label if all is passing

* chore: rename steps

* fix: only remove the label if there were no breaking changes

* chore: jump to the correct step

* chore: skip `@grafana/toolkit`

* chore: add a message for opening links in a new tab

* chore: update comment message

* chore: use Node 16 for the breaking changes workflow

* chore: install Yarn separately

* chore: use @grafana/levitate

* refactor: remove the unused levitate.js bundle

* fix: handle error when trying to remove a label that does not exist

* chore: delete the comment if there are no breaking changes

* chore: add reviewers automatically

* fix: use double-quote in shell script

* TEMPORARY: introduce a breaking change in `@grafana/data`

* fix: use correct line number for the breaking changes

* Revert "TEMPORARY: introduce a breaking change in `@grafana/data`"

This reverts commit 986ac9ab82.

* chore: remove unnecessary line from .eslintignore
2021-12-15 17:07:11 +01:00

52 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
PACKAGES=$(lerna list -p -l)
EXIT_CODE=0
GITHUB_MESSAGE=""
# Loop through packages
while IFS= read -r line; do
# Read package info
IFS=':' read -ra ADDR <<< "$line"
PACKAGE_PATH="${ADDR[0]}"
PACKAGE_NAME="${ADDR[1]}"
# Calculate current and previous package paths / names
PREV="$PACKAGE_NAME@canary"
CURRENT="$PACKAGE_PATH/dist/"
# Temporarily skipping @grafana/toolkit, as it doesn't have any exposed static typing
if [[ "$PACKAGE_NAME" == '@grafana/toolkit' ]]; then
continue
fi
# Run the comparison and record the exit code
echo ""
echo ""
echo "${PACKAGE_NAME}"
echo "================================================="
npm exec -- @grafana/levitate compare --prev "$PREV" --current "$CURRENT"
# Check if the comparison returned with a non-zero exit code
# Record the output, maybe with some additional information
STATUS=$?
# Final exit code
# (non-zero if any of the packages failed the checks)
if [ $STATUS -gt 0 ]
then
EXIT_CODE=1
GITHUB_MESSAGE="${GITHUB_MESSAGE}**\`${PACKAGE_NAME}\`** has possible breaking changes ([more info](${GITHUB_JOB_LINK}#step:11:1))<br />"
fi
done <<< "$PACKAGES"
# "Export" the message to an environment variable that can be used across Github Actions steps
echo "::set-output name=is_breaking::$EXIT_CODE"
echo "::set-output name=message::$GITHUB_MESSAGE"
# We will exit the workflow accordingly at another step
exit 0