-
Notifications
You must be signed in to change notification settings - Fork 5
102 lines (86 loc) · 3.88 KB
/
apollo-studio-checks.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Apollo Schema Check
# Generally running a pull_request_target with secrets from the fork is risky, however we are only using the schema.graphql
# file and not executing any code from the branch so it's safe here.
on:
pull_request_target:
branches:
- main
jobs:
check:
name: check
runs-on: ubuntu-latest
permissions:
pull-requests: write
env:
APOLLO_KEY: ${{ secrets.APOLLO_KEY }}
APOLLO_VCS_COMMIT: ${{ github.event.pull_request.head.sha }}
APOLLO_VCS_REMOTE_URL: ${{ github.event.pull_request.head.repo.clone_url }}
APOLLO_VCS_BRANCH: ${{ github.event.pull_request.head.label }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Rover
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Run check against infratographer supergraph
run: |
rover subgraph check --name metadata-api --schema schema.graphql infratographer@main --format json --output subgraph-check.json
- name: Generate report comment
run: |
RESULTS_FILE=subgraph-check.json
echo -e "#### GraphQL Schema Check\n" > comment.txt
print_details () {
TARGET_URL=$(jq '.data.target_url' $RESULTS_FILE | tr -d \")
echo -e "🔗 [View full schema check details]($TARGET_URL)\n" >> comment.txt
}
print_changes_for () {
SEV=$(echo $1 | tr -d \")
COUNT=$(jq -c ".data.changes[] | select(.severity == \"$SEV\")" $RESULTS_FILE | wc -l)
echo -e "<details>\n\n<summary>$COUNT $SEV Changes</summary>\n" >> comment.txt
echo -e "| Change Type | Description |\n| --- | --- |" >> comment.txt
jq -j ".data.changes[] | select(.severity == \"$SEV\") | (\"| \", .code, \" | \", .description, \" |\"),\"\n\"" $RESULTS_FILE | sort >> comment.txt
echo -e "\n</details>\n" >> comment.txt
}
print_errors () {
SUMMARY=$(jq -j '.error.message' $RESULTS_FILE)
echo -e "<details>\n\n<summary>$SUMMARY</summary>\n" >> comment.txt
echo -e "| Error Type | Code | Message |\n| --- | --- | --- |" >> comment.txt
jq -j '.error.details.build_errors[] | ("| ", .type, " | ", .code, " | ", .message, " |"),"\n"' $RESULTS_FILE >> comment.txt
echo -e "\n</details>\n" >> comment.txt
}
ERROR=$(jq '.error' $RESULTS_FILE)
if [ "$ERROR" != "null" ]; then
echo -e "❌ Schema composition failed\n" >> comment.txt
print_errors
print_details
exit 0
fi
FAILURE_COUNT=$(jq '.data.failure_count' $RESULTS_FILE)
CHANGE_COUNT=$(jq '.data.changes | length' $RESULTS_FILE)
OP_CHECK_COUNT=$(jq '.data.operation_check_count' $RESULTS_FILE)
echo -e "Compared $CHANGE_COUNT schema changes against $OP_CHECK_COUNT operations\n" >> comment.txt
if [ $CHANGE_COUNT -eq 0 ]; then
echo -e "✅ Found **no changes**\n\n" >> comment.txt
print_details
exit 0
fi
if [ $FAILURE_COUNT -eq 0 ]
then
echo -e "✅ Found **no breaking changes**\n" >> comment.txt
else
echo -e "❌ Found **$FAILURE_COUNT breaking changes**\n" >> comment.txt
fi
sev_array=()
IFS=$'\n' read -r -d '' -a sev_array < <( jq '.data.changes[].severity' $RESULTS_FILE | sort| uniq && printf '\0' )
for i in "${sev_array[@]}"
do
print_changes_for $i
done
print_details
- name: Comment PR with execution number
uses: thollander/actions-comment-pull-request@v2
with:
filePath: comment.txt
comment_tag: infratographer-apollo-graph-check