2021-12-15 10:07:11 -06:00
#!/usr/bin/env bash
2022-01-20 03:20:32 -06:00
# Find package directories
PACKAGES = $( ls -d ./packages/*/)
2021-12-15 10:07:11 -06:00
EXIT_CODE = 0
GITHUB_MESSAGE = ""
2023-10-16 10:31:43 -05:00
SKIP_PACKAGES = ( "grafana-eslint-rules" "grafana-plugin-configs" )
2021-12-15 10:07:11 -06:00
2022-01-03 05:48:12 -06:00
# Loop through the packages
2022-01-20 03:20:32 -06:00
while IFS = " " read -r -a package; do
2021-12-15 10:07:11 -06:00
2022-01-20 03:20:32 -06:00
# shellcheck disable=SC2128
PACKAGE_PATH = $( basename " $package " )
2021-12-15 10:07:11 -06:00
# Calculate current and previous package paths / names
2022-08-11 08:17:51 -05:00
PREV = " ./base/ $PACKAGE_PATH "
CURRENT = " ./pr/ $PACKAGE_PATH "
2021-12-15 10:07:11 -06:00
2022-01-20 03:20:32 -06:00
# Temporarily skipping these packages as they don't have any exposed static typing
2023-10-16 10:31:43 -05:00
if [ [ ${ SKIP_PACKAGES [@] } = ~ " $PACKAGE_PATH " ] ] ; then
2021-12-15 10:07:11 -06:00
continue
fi
2022-08-11 08:17:51 -05:00
# Extract the npm package tarballs into separate directories e.g. ./base/@grafana-data.tgz -> ./base/grafana-data/
2022-08-11 10:13:41 -05:00
mkdir " $PREV "
tar -xf " ./base/@ $PACKAGE_PATH .tgz " --strip-components= 1 -C " $PREV "
mkdir " $CURRENT "
tar -xf " ./pr/@ $PACKAGE_PATH .tgz " --strip-components= 1 -C " $CURRENT "
2022-08-11 08:17:51 -05:00
2021-12-15 10:07:11 -06:00
# Run the comparison and record the exit code
echo ""
echo ""
2022-01-20 03:20:32 -06:00
echo " ${ PACKAGE_PATH } "
2021-12-15 10:07:11 -06:00
echo "================================================="
2022-02-01 02:18:21 -06:00
npm exec -- @grafana/levitate compare --prev " $PREV " --current " $CURRENT "
2021-12-15 10:07:11 -06:00
# Check if the comparison returned with a non-zero exit code
# Record the output, maybe with some additional information
STATUS = $?
# Final exit code
2023-01-27 08:13:17 -06:00
# (non-zero if any of the packages failed the checks)
2021-12-15 10:07:11 -06:00
if [ $STATUS -gt 0 ]
then
EXIT_CODE = 1
2023-01-27 08:13:17 -06:00
GITHUB_MESSAGE = " ${ GITHUB_MESSAGE } **\\\` ${ PACKAGE_PATH } \\\`** has possible breaking changes ([more info]( ${ GITHUB_JOB_LINK } #step: ${ GITHUB_STEP_NUMBER } :1))<br /> "
2022-01-20 03:20:32 -06:00
fi
2021-12-15 10:07:11 -06:00
done <<< " $PACKAGES "
# "Export" the message to an environment variable that can be used across Github Actions steps
2022-11-10 05:02:04 -06:00
echo " is_breaking= $EXIT_CODE " >> " $GITHUB_OUTPUT "
echo " message= $GITHUB_MESSAGE " >> " $GITHUB_OUTPUT "
2021-12-15 10:07:11 -06:00
# We will exit the workflow accordingly at another step
2022-08-11 10:13:41 -05:00
exit 0