mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 10:24:54 -06:00
Chore: Improve levitate CI PR messaage (#79679)
* Chore: Improve levitate CI PR messaage * Temporary disable the skip * Remove ignore * Add an artificial breaking change * Restore * Restore * Trigger breaking change (maybe?) * --wip-- [skip ci] * Empty commit * Keep trying * Breaking change maybe? * Add levitate markdown to persistent output * Move markdown output * no skipping * Force run * remove skip * Try * Fix workflow * tryu * fix typo * remove duplicated id * Test * Invert commands * Fix script * Do not output the markdown directly * Try 2 * Try with base64 * Update message * Update message * Fix base64 encoding * Update report * Fix * test file * Try without base64 * Fix report to not use base64 * restore skip file * revert breaking changes * Empty commit
This commit is contained in:
parent
b312f48c10
commit
5fd5a8e385
3
.github/CODEOWNERS
vendored
3
.github/CODEOWNERS
vendored
@ -522,7 +522,8 @@ cypress.config.js @grafana/grafana-frontend-platform
|
||||
/scripts/trigger_windows_build.sh @grafana/grafana-release-guild
|
||||
/scripts/cleanup-husky.sh @grafana/frontend-ops
|
||||
/scripts/verify-repo-update/ @grafana/grafana-release-guild
|
||||
scripts/generate-icon-bundle.js @grafana/plugins-platform-frontend @grafana/grafana-frontend-platform
|
||||
/scripts/generate-icon-bundle.js @grafana/plugins-platform-frontend @grafana/grafana-frontend-platform
|
||||
/scripts/levitate-parse-json-report.js @grafana/plugins-platform-frontend
|
||||
|
||||
/scripts/docs/generate-transformations.ts @grafana/grafana-bi-squad
|
||||
/scripts/webpack/ @grafana/frontend-ops
|
||||
|
@ -96,6 +96,22 @@ jobs:
|
||||
|
||||
return doesExist ? 1 : 0;
|
||||
|
||||
# put the markdown into a variable
|
||||
- name: Levitate Markdown
|
||||
id: levitate-markdown
|
||||
if: steps.levitate-run.outputs.shouldSkip != 'true'
|
||||
run: |
|
||||
if [ -f "${ARTIFACT_FOLDER}/levitate.md" ]; then
|
||||
{
|
||||
echo 'levitate_markdown<<EOF'
|
||||
cat ${ARTIFACT_FOLDER}/levitate.md
|
||||
echo EOF
|
||||
} >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "levitate_markdown=No breaking changes detected" >> $GITHUB_OUTPUT
|
||||
fi
|
||||
|
||||
|
||||
# Comment on the PR
|
||||
- name: Comment on PR
|
||||
if: steps.levitate-run.outputs.exit_code == 1 && steps.levitate-run.outputs.shouldSkip != 'true'
|
||||
@ -103,11 +119,9 @@ jobs:
|
||||
with:
|
||||
number: ${{ steps.levitate-run.outputs.pr_number }}
|
||||
message: |
|
||||
⚠️ **Possible breaking changes**
|
||||
⚠️ **Possible breaking changes (md version)**
|
||||
|
||||
_(Open the links below in a new tab to go to the correct steps)_
|
||||
|
||||
${{ steps.levitate-run.outputs.message }}
|
||||
${{ steps.levitate-markdown.outputs.levitate_markdown }}
|
||||
|
||||
[Console output](${{ steps.levitate-run.outputs.job_link }})
|
||||
[Read our guideline](https://github.com/grafana/grafana/blob/main/contribute/breaking-changes-guide/breaking-changes-guide.md)
|
||||
|
@ -9,48 +9,53 @@ SKIP_PACKAGES=("grafana-eslint-rules" "grafana-plugin-configs")
|
||||
# Loop through the packages
|
||||
while IFS=" " read -r -a package; do
|
||||
|
||||
# shellcheck disable=SC2128
|
||||
PACKAGE_PATH=$(basename "$package")
|
||||
# shellcheck disable=SC2128
|
||||
PACKAGE_PATH=$(basename "$package")
|
||||
|
||||
# Calculate current and previous package paths / names
|
||||
PREV="./base/$PACKAGE_PATH"
|
||||
CURRENT="./pr/$PACKAGE_PATH"
|
||||
# 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
|
||||
if [[ ${SKIP_PACKAGES[@]} =~ "$PACKAGE_PATH" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Temporarily skipping these packages as they don't have any exposed static typing
|
||||
if [[ ${SKIP_PACKAGES[@]} =~ "$PACKAGE_PATH" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# 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"
|
||||
# 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 ""
|
||||
echo "${PACKAGE_PATH}"
|
||||
echo "================================================="
|
||||
npm exec -- @grafana/levitate compare --prev "$PREV" --current "$CURRENT"
|
||||
# Run the comparison and record the exit code
|
||||
echo ""
|
||||
echo ""
|
||||
echo "${PACKAGE_PATH}"
|
||||
echo "================================================="
|
||||
npm exec -- @grafana/levitate compare --prev "$PREV" --current "$CURRENT" --json >data.json
|
||||
|
||||
# Check if the comparison returned with a non-zero exit code
|
||||
# Record the output, maybe with some additional information
|
||||
STATUS=$?
|
||||
# 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_PATH}\\\`** has possible breaking changes ([more info](${GITHUB_JOB_LINK}#step:${GITHUB_STEP_NUMBER}:1))<br />"
|
||||
fi
|
||||
CURRENT_REPORT=$(node ./scripts/levitate-parse-json-report.js)
|
||||
echo $CURRENT_REPORT
|
||||
|
||||
done <<< "$PACKAGES"
|
||||
# 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_PATH}\\\`** has possible breaking changes ([more info](${GITHUB_JOB_LINK}#step:${GITHUB_STEP_NUMBER}:1))<br />"
|
||||
GITHUB_LEVITATE_MARKDOWN+="##${PACKAGE_PATH}\n${CURRENT_REPORT}\n"
|
||||
fi
|
||||
|
||||
done <<<"$PACKAGES"
|
||||
|
||||
# "Export" the message to an environment variable that can be used across Github Actions steps
|
||||
echo "is_breaking=$EXIT_CODE" >> "$GITHUB_OUTPUT"
|
||||
echo "message=$GITHUB_MESSAGE" >> "$GITHUB_OUTPUT"
|
||||
echo "is_breaking=$EXIT_CODE" >>"$GITHUB_OUTPUT"
|
||||
echo "message=$GITHUB_MESSAGE" >>"$GITHUB_OUTPUT"
|
||||
mkdir -p ./levitate
|
||||
echo $GITHUB_LEVITATE_MARKDOWN >./levitate/levitate.md
|
||||
|
||||
# We will exit the workflow accordingly at another step
|
||||
exit 0
|
||||
|
28
scripts/levitate-parse-json-report.js
Normal file
28
scripts/levitate-parse-json-report.js
Normal file
@ -0,0 +1,28 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const data = JSON.parse(fs.readFileSync('data.json', 'utf8'));
|
||||
|
||||
const stripAnsi = (string) => string.replace(/\u001b\[.*?m/g, '');
|
||||
|
||||
const printSection = (title, items) => {
|
||||
let output = `### ${title}\n\n`;
|
||||
items.forEach((item) => {
|
||||
output += `**${item.name}**\n`;
|
||||
output += `<sub>${item.location}</sub>\n\n`;
|
||||
output += '```' + (item.declaration ? 'typescript' : 'diff typescript') + '\n';
|
||||
output += item.declaration ? item.declaration : stripAnsi(item.diff);
|
||||
output += '\n```\n\n';
|
||||
});
|
||||
return output;
|
||||
};
|
||||
|
||||
let markdown = '';
|
||||
|
||||
if (data.removals.length > 0) {
|
||||
markdown += printSection('Removals', data.removals);
|
||||
}
|
||||
if (data.changes.length > 0) {
|
||||
markdown += printSection('Changes', data.changes);
|
||||
}
|
||||
|
||||
console.log(markdown);
|
Loading…
Reference in New Issue
Block a user