-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
111 lines (98 loc) · 3.37 KB
/
action.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
103
104
105
106
107
108
109
110
111
name: Grafbase Schema Check Action
author: Grafbase
description: Run the Grafbase Schema Checks
branding:
icon: activity
color: green
inputs:
grafbase-access-token:
description: A Grafbase API access token. It can be created from the Grafbase dashboard.
required: true
project-ref:
description: "The account, project and (optional) branch of the schema to check against, in the format expected by the grafbase CLI. Example: tomhoule/test-project@main."
required: true
schema-path:
description: The file path of the schema to check, as GraphQL SDL.
required: true
subgraph-name:
description: The name of the subgraph to check. Only required in federated projects.
slack-incoming-webhook-url:
description: An optional Slack webhook url to post errors to
runs:
using: composite
steps:
- id: validate-args
shell: bash
env:
SCHEMA_PATH: "${{ inputs.schema-path }}"
run: |
: Handle the inputs.
if [ -z "$SCHEMA_PATH" ]; then
echo "The schema-path input is missing."
exit 1
fi
if [ ! -s "$SCHEMA_PATH" ]; then
echo "The schema path at $SCHEMA_PATH is empty or missing."
exit 1
fi
if [ -z "${{ inputs.grafbase-access-token }}" ]; then
echo "The grafbase-access-token input is missing."
exit 1
fi
if [ -z "${{ inputs.project-ref }}" ]; then
echo "The project-ref input is missing."
exit 1
fi
- id: download-cli
shell: bash
run: |
: Install the Grafbase CLI
npm i --no-audit --no-fund grafbase
: Test that the CLI binary works
npx grafbase --help > /dev/null 2>&1
- id: check
shell: bash
env:
SCHEMA_PATH: ${{ inputs.schema-path }}
GRAFBASE_ACCESS_TOKEN: ${{ inputs.grafbase-access-token }}
run: |
: Perform the check
if [ -n "${{ inputs.subgraph-name }}" ]; then
SUBGRAPH="--subgraph ${{ inputs.subgraph-name }}"
else
SUBGRAPH=""
fi
set +e
echo 'check_errors<<STOPHERE' > "$GITHUB_OUTPUT"
npx grafbase check "${{ inputs.project-ref }}" --schema "$SCHEMA_PATH" $SUBGRAPH |& tee >(cat >&2) | jq --slurp --raw-input >> "$GITHUB_OUTPUT"
exit_code=${PIPESTATUS[0]}
echo 'STOPHERE' >> "$GITHUB_OUTPUT"
echo "Exiting with status $exit_code"
exit $exit_code
- name: Post check errors to slack
if: inputs.slack-incoming-webhook-url && failure()
uses: slackapi/[email protected]
with:
payload: |
{
"text": "Schema checks failed for ${{ github.event.pull_request.html_url || github.event.head_commit.url }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Schema checks failed at ${{ github.event.pull_request.html_url || github.event.head_commit.url }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{ steps.check.outputs.check_errors }}
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack-incoming-webhook-url }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK