-
Notifications
You must be signed in to change notification settings - Fork 6
171 lines (150 loc) · 6.25 KB
/
Copy pathvalidate-graphql.yml
File metadata and controls
171 lines (150 loc) · 6.25 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Validate GraphQL Queries
on:
# PR checks — validate doc changes against committed schema snapshots
pull_request:
branches: [main]
paths:
- 'docs/_data/graphql-api/**'
- 'docs/_data/tutorials/queries/**'
- 'src/components/GraphQLPlayground.tsx'
- 'scripts/validate-graphql-queries.js'
- 'scripts/graphql-schema-*.json'
# Nightly drift detection — fetch fresh schemas, open PR if changed
schedule:
- cron: '0 8 * * *'
# Cross-repo dispatch from intuition-rs (Phase 4)
repository_dispatch:
types: [schema-changed]
# Manual trigger
workflow_dispatch:
# Read-only by default; the schema-drift job elevates itself to push its branch and manage its PR.
permissions:
contents: read
jobs:
# -----------------------------------------------------------------------
# Job 1: PR check — validate queries against committed snapshots
# -----------------------------------------------------------------------
validate-queries:
name: Validate GraphQL queries
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Validate queries against committed schemas
run: node scripts/validate-graphql-queries.js
# -----------------------------------------------------------------------
# Job 2: Schema drift detection — fetch fresh, validate, auto-PR
# -----------------------------------------------------------------------
schema-drift:
name: Detect schema drift
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Log trigger source
run: |
echo "Trigger: ${{ github.event_name }}"
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "Dispatch payload ref: ${{ github.event.client_payload.ref }}"
fi
- name: Fetch fresh schema snapshots
env:
INTUITION_PIN_API_KEY: ${{ secrets.INTUITION_PIN_API_KEY }}
run: node scripts/validate-graphql-queries.js --update-schema
- name: Check for schema changes
id: check-schema
run: |
if git diff --quiet scripts/graphql-schema-*.json; then
echo "changed=false" >> $GITHUB_OUTPUT
echo "No schema changes detected."
else
echo "changed=true" >> $GITHUB_OUTPUT
echo "Schema changes detected:"
git diff --stat scripts/graphql-schema-*.json
fi
- name: Validate queries against fresh schemas
if: steps.check-schema.outputs.changed == 'true'
id: validate
continue-on-error: true
run: node scripts/validate-graphql-queries.js 2>&1 | tee validation-output.txt
- name: Build PR body
if: steps.check-schema.outputs.changed == 'true'
run: |
{
echo "## Schema Drift Detected"
echo ""
if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
echo "Triggered by \`intuition-rs\` merge: \`${{ github.event.client_payload.ref }}\`"
elif [ "${{ github.event_name }}" = "schedule" ]; then
echo "Triggered by nightly schedule"
else
echo "Triggered manually"
fi
echo ""
echo "### Schema Changes"
echo ""
echo '```'
git diff --stat scripts/graphql-schema-*.json
echo '```'
echo ""
if [ -f validation-output.txt ] && grep -q "❌" validation-output.txt; then
echo "⚠️ **Validation found errors** — some documented queries may be broken by this schema change."
echo ""
echo "<details>"
echo "<summary>Full validation output</summary>"
echo ""
echo '```'
cat validation-output.txt
echo '```'
echo ""
echo "</details>"
else
echo "✅ All documented queries still valid against the new schema."
fi
echo ""
echo "---"
echo "🤖 Generated by [validate-graphql workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})"
} > pr-body.md
- name: Create or update PR
if: steps.check-schema.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="auto/schema-update"
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Check if an open schema drift PR already exists
EXISTING_PR=$(gh pr list --state open --head "$BRANCH" --json number --jq '.[0].number // empty')
if [ -n "$EXISTING_PR" ]; then
# Update existing PR — force-push new schema to same branch
git checkout -b "$BRANCH" "origin/$BRANCH" 2>/dev/null || git checkout -b "$BRANCH"
git add scripts/graphql-schema-*.json
git commit -m "chore: update GraphQL schema snapshots
Schema drift detected from live endpoints.
Trigger: ${{ github.event_name }}
Co-authored-by: GitHub Actions <action@github.com>"
git push origin "$BRANCH" --force
gh pr edit "$EXISTING_PR" --body-file pr-body.md
echo "Updated existing PR #$EXISTING_PR"
else
# Create new branch and PR
git checkout -b "$BRANCH"
git add scripts/graphql-schema-*.json
git commit -m "chore: update GraphQL schema snapshots
Schema drift detected from live endpoints.
Trigger: ${{ github.event_name }}
Co-authored-by: GitHub Actions <action@github.com>"
git push origin "$BRANCH" --force
gh pr create \
--title "Schema drift: GraphQL schema updated from live endpoints" \
--body-file pr-body.md \
--base main \
--head "$BRANCH" \
--draft
fi