2021-12-16 00:07:11 +08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-01-20 17:20:32 +08:00
|
|
|
# Find package directories
|
|
|
|
PACKAGES=$(ls -d ./packages/*/)
|
2021-12-16 00:07:11 +08:00
|
|
|
EXIT_CODE=0
|
|
|
|
GITHUB_MESSAGE=""
|
2024-01-26 19:30:35 +08:00
|
|
|
SKIP_PACKAGES=("grafana-eslint-rules" "grafana-plugin-configs" "grafana-o11y-ds-frontend" "grafana-sql")
|
2021-12-16 00:07:11 +08:00
|
|
|
|
2022-01-03 19:48:12 +08:00
|
|
|
# Loop through the packages
|
2022-01-20 17:20:32 +08:00
|
|
|
while IFS=" " read -r -a package; do
|
2021-12-16 00:07:11 +08:00
|
|
|
|
2023-12-20 17:09:58 +08:00
|
|
|
# shellcheck disable=SC2128
|
|
|
|
PACKAGE_PATH=$(basename "$package")
|
|
|
|
|
|
|
|
# Calculate current and previous package paths / names
|
|
|
|
PREV="./base/$PACKAGE_PATH"
|
|
|
|
CURRENT="./pr/$PACKAGE_PATH"
|
|
|
|
|
|
|
|
# Temporarily skipping these packages as they don't have any exposed static typing
|
2024-02-27 00:59:55 +08:00
|
|
|
SKIP_PACKAGE_FOUND=0
|
|
|
|
for skip_pkg in "${SKIP_PACKAGES[@]}"; do
|
|
|
|
if [[ "$PACKAGE_PATH" == "$skip_pkg" ]]; then
|
|
|
|
SKIP_PACKAGE_FOUND=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $SKIP_PACKAGE_FOUND -eq 1 ]]; then
|
2023-12-20 17:09:58 +08:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2024-02-02 22:25:32 +08:00
|
|
|
# Skip packages that are marked as private in their package.json (private: true)
|
|
|
|
if [[ $(jq -r '.private' "./packages/$PACKAGE_PATH/package.json") == "true" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2025-09-11 15:44:17 +08:00
|
|
|
# Skip packages that don't exist in the base (packages introduced in PR)
|
|
|
|
if [[ ! -f "./base/@$PACKAGE_PATH.tgz" ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2023-12-20 17:09:58 +08:00
|
|
|
# Extract the npm package tarballs into separate directories e.g. ./base/@grafana-data.tgz -> ./base/grafana-data/
|
|
|
|
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"
|
|
|
|
|
|
|
|
# Run the comparison and record the exit code
|
|
|
|
echo ""
|
|
|
|
echo ""
|
2024-02-02 16:19:30 +08:00
|
|
|
echo "$PACKAGE_PATH"
|
2023-12-20 17:09:58 +08:00
|
|
|
echo "================================================="
|
2024-02-02 16:19:30 +08:00
|
|
|
npm exec -- @grafana/levitate@latest compare --prev "$PREV" --current "$CURRENT" --json >data.json
|
2023-12-20 17:09:58 +08:00
|
|
|
|
|
|
|
# Check if the comparison returned with a non-zero exit code
|
|
|
|
# Record the output, maybe with some additional information
|
|
|
|
STATUS=$?
|
|
|
|
CURRENT_REPORT=$(node ./scripts/levitate-parse-json-report.js)
|
|
|
|
# Final exit code
|
|
|
|
# (non-zero if any of the packages failed the checks)
|
2024-02-02 16:19:30 +08:00
|
|
|
if [ "$STATUS" -gt 0 ]; then
|
2023-12-20 17:09:58 +08:00
|
|
|
EXIT_CODE=1
|
2025-05-05 19:05:03 +08:00
|
|
|
GITHUB_MESSAGE="${GITHUB_MESSAGE}**<code>${PACKAGE_PATH}</code>** has possible breaking changes<br />"
|
2023-12-20 20:40:47 +08:00
|
|
|
GITHUB_LEVITATE_MARKDOWN+="<h3>${PACKAGE_PATH}</h3>${CURRENT_REPORT}<br>"
|
2023-12-20 17:09:58 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
done <<<"$PACKAGES"
|
2021-12-16 00:07:11 +08:00
|
|
|
|
|
|
|
# "Export" the message to an environment variable that can be used across Github Actions steps
|
2023-12-20 17:09:58 +08:00
|
|
|
echo "is_breaking=$EXIT_CODE" >>"$GITHUB_OUTPUT"
|
|
|
|
echo "message=$GITHUB_MESSAGE" >>"$GITHUB_OUTPUT"
|
|
|
|
mkdir -p ./levitate
|
2024-02-02 16:19:30 +08:00
|
|
|
echo "$GITHUB_LEVITATE_MARKDOWN" >./levitate/levitate.md
|
2021-12-16 00:07:11 +08:00
|
|
|
|
2025-07-08 20:52:02 +08:00
|
|
|
if [[ "$IS_FORK" == "true" ]]; then
|
2025-07-10 18:12:12 +08:00
|
|
|
cat ./levitate/levitate.md >> "$GITHUB_STEP_SUMMARY"
|
|
|
|
exit $EXIT_CODE
|
2025-07-08 20:52:02 +08:00
|
|
|
fi
|
|
|
|
|
2021-12-16 00:07:11 +08:00
|
|
|
# We will exit the workflow accordingly at another step
|
2022-08-11 23:13:41 +08:00
|
|
|
exit 0
|