-
-
Save EverlastingBugstopper/d6aa0d9a49bcf39f2df53e1cfb9bb88a to your computer and use it in GitHub Desktop.
#! /bin/bash | |
# This script performs a subgraph check and generates a markdown file from Rover's JSON output | |
# Change the following line to refer to your graph ref, schema, and subgraph name | |
CHECK_OUTPUT=$(rover subgraph check my-graph --schema ./products.graphql --name products --output json) | |
CHECK_SUCCESS=$(echo $CHECK_OUTPUT | jq '.data.success') | |
if [ $CHECK_SUCCESS = "true" ]; then | |
echo "### Check Success" | |
echo "" | |
echo "#### Change Details" | |
echo "" | |
fi | |
CHANGES=$(echo "${CHECK_OUTPUT}" | jq '.data.changes') | |
if [ "$CHANGES" != "null" ]; then | |
CHANGE_SIZE=$(echo "${CHECK_OUTPUT}" | jq -r '.data.changes | length') | |
if [ "$CHANGE_SIZE" = "0" ]; then | |
echo "No changes" | |
fi | |
if [ "$CHANGE_SIZE" != "0" ]; then | |
echo "| Severity | Code | Description |" | |
echo "| -------- | ---- | ----------- |" | |
for CHANGE in $(echo "${CHECK_OUTPUT}" | jq -r '.data.changes[] | @base64'); do | |
_jq() { | |
echo ${CHANGE} | base64 -d | jq -r ${1} | |
} | |
CHANGE_SEVERITY=$(_jq '.severity') | |
CHANGE_CODE=$(_jq '.code') | |
CHANGE_DESCRIPTION=$(_jq '.description') | |
echo "| $CHANGE_SEVERITY | $CHANGE_CODE | $CHANGE_DESCRIPTION |" | |
done | |
fi | |
echo "" | |
fi | |
if [ $CHECK_SUCCESS = "false" ]; then | |
echo "### Check Failure" | |
echo "" | |
echo $CHECK_OUTPUT | jq -r '.error.message' | |
echo "" | |
echo "#### Error Details" | |
echo "" | |
for BUILD_ERROR in $(echo "${CHECK_OUTPUT}" | jq -r '.error.details.build_errors[] | @base64'); do | |
_jq() { | |
echo ${BUILD_ERROR} | base64 -d | jq -r ${1} | |
} | |
BUILD_ERROR_CODE=$(_jq '.code') | |
if [ $BUILD_ERROR_CODE != "null" ]; then | |
echo -n "$BUILD_ERROR_CODE: " | |
else | |
echo -n "UNKNOWN: " | |
fi | |
echo $(_jq '.message') | |
done | |
fi | |
CHECK_URL=$(echo $CHECK_OUTPUT | jq '.data.target_url') | |
if [ $CHECK_URL != null ]; then | |
echo "" | |
echo "See more details in [Apollo Studio]($CHECK_URL)" | |
fi | |
echo "" |
Thanks @busches - I've updated the gist w/your suggested changes :)
I tweaked a few more times to get display something when no changes are present, instead of an empty table. And apparently alpine doesn't support base64 --decode
only base64 -d
so I made that change too. https://gist.github.com/busches/811012cd1df8243efcbef71ae5c90410
Thanks for the script, much better than sending the plain output to GH :)
Glad it helped! We'll definitely want to get proper markdown support at some point but there's a bunch of other really neat stuff cooking as well - glad this stopgap will work for you
Hey! I also wanted to thank you for the inspiration/jumping off point π. I made a few minor tweaks as well. If you like them, feel free to add here else ignore them. You can view our script here and the changes are more or less the following things:
- Wrapped the Change Details Table into a
<details>
tag so it was collapsable and prevented the comment from being a wall of text - Moved the Error if block up above the change details because we found it was possible to have change details AND be an error status
- Strip out the
"
from the URL so the github link displays as a link instead of text - Used github emojis instead of text for the success/failure status β / β
Ends up looking like this an then if you open up the Change Details dropdown you see the table
Seems like the response body is now change, and most of the object is not available and the script seems broken
{
"json_version": "1",
"data": {
"target_url": "url?variant=env",
"operation_check_count": 259,
"changes": [
{
"code": "TYPE_REMOVED",
"description": "type `DeletedAlluser`: removed",
"severity": "FAIL"
}
{
"code": "FIELD_REMOVED",
"description": "type `ABC`: field `esMessagesDeleted` removed",
"severity": "FAIL"
},
{
"code": "FIELD_REMOVED",
"description": "type `Mutation`: field `XYZ` removed",
"severity": "FAIL"
}
],
"failure_count": 3,
"success": false
},
"error": {
"message": "This operation check has encountered 4 schema changes that would break operations from existing client traffic.",
"code": "E030"
}
}
come up with this
https://gist.github.com/adiii717/a5428c0f91cb56521d7d5f2f834c7309
### | Severity | Code | Description |
| -------- | ---- | ----------- |
| FAIL | TYPE_REMOVED | type `demo`: removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
| FAIL | FIELD_REMOVED | type `demo`: field `demo` removed |
### Check Failure
This operation check has encountered 4 schema changes that would break operations from existing client traffic.
### Status: β
StatusCode: E030
Error Message: This operation check has encountered 4 schema changes that would break operations from existing client traffic.
See more details in [Apollo Studio]
and I was on gitlab so this work for me
- export RESULT=$(curl -s https://gist.githubusercontent.com/adiii717/a5428c0f91cb56521d7d5f2f834c7309/raw/77ab4077617f252ba1a675e77fb67cd284655d93/rover_check_markdown.sh | bash -s -- "rover subgraph check demo@develop -s demo.gql --name demo --output json")
- echo "${RESULT}" > result.md && export MD_RESULT=$(awk 'ORS="\n\n"' result.md)
- curl --request POST --header "Content-Type:multipart/form-data" --header "PRIVATE-TOKEN:${GITLAB_TOKEN}" "https://gitlab.com/api/v4/projects/${CI_MERGE_REQUEST_PROJECT_ID}/merge_requests/${CI_MERGE_REQUEST_IID}/notes?body" -d "body=$MD_RESULT"
Note I had to make the following change to get this to work on OSX:
Likely could have used
[[
since this is bash, but I will ultimately have to send it tosh
on CI.