@embrace-ai/infra-api-schema-sync 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- # .github/workflows/graphql-schema-validate.yml
2
1
  name: Validate GraphQL Schema Updates
3
2
 
4
3
  on:
@@ -7,24 +6,30 @@ on:
7
6
  workflow_dispatch:
8
7
  inputs:
9
8
  schema_url:
10
- description: "Schema URL to validate against"
11
- required: false
12
- default: ""
9
+ description: "GraphQL schema URL to validate/update"
10
+ required: true
11
+ type: string
12
+
13
+ permissions:
14
+ id-token: write
15
+ contents: write
16
+ pull-requests: write
13
17
 
14
18
  jobs:
15
19
  validate-schema:
20
+ if: ${{ !startsWith(github.repository, 'Embrace-AI/template-') }}
16
21
  runs-on: ubuntu-latest
17
22
 
18
23
  steps:
19
- - uses: actions/checkout@v4
24
+ - uses: actions/checkout@v5
20
25
 
21
26
  - name: Setup pnpm
22
27
  uses: pnpm/action-setup@v4
23
28
 
24
29
  - name: Setup node cache
25
- uses: actions/setup-node@v4
30
+ uses: actions/setup-node@v5
26
31
  with:
27
- node-version: 22.16.0
32
+ node-version: 22.19.0
28
33
  cache: "pnpm"
29
34
 
30
35
  - name: Setup NPM
@@ -33,100 +38,171 @@ jobs:
33
38
  run: pnpm config set //registry.npmjs.org/:_authToken "${NPM_TOKEN}"
34
39
 
35
40
  - name: Install GraphQL schema sync tool
36
- # Update line below to use the version you want
37
- run: pnpm install -w @embrace-ai/infra-api-schema-sync@latest
41
+ run: pnpm add -g @embrace-ai/infra-api-schema-sync@latest
38
42
 
39
43
  - name: Configure aws credentials
40
- uses: aws-actions/configure-aws-credentials@v4.2.1
44
+ uses: aws-actions/configure-aws-credentials@v5.0.0
41
45
  with:
42
46
  role-to-assume: ${{ secrets.AWS_DEPLOY_ROLE_DEV }}
43
47
  aws-region: ${{ vars.AWS_REGION }}
44
48
 
45
- - name: Determine schema URL
46
- id: schema-url
49
+ - name: Set schema URL and source repo
50
+ id: set-schema-url
47
51
  run: |
48
- if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
49
- # Use the schema URL from the dispatch event
50
- SCHEMA_URL="${{ github.event.client_payload.schemaUrl }}"
51
- echo "📡 Using schema URL from dispatch event: $SCHEMA_URL"
52
- elif [ -n "${{ github.event.inputs.schema_url }}" ]; then
53
- # Use the schema URL from workflow_dispatch input
54
- SCHEMA_URL="${{ github.event.inputs.schema_url }}"
55
- echo "🔧 Using schema URL from workflow input: $SCHEMA_URL"
56
- else
57
- echo "❌ Error: No schema URL provided"
58
- exit 1
52
+ SCHEMA_URL="${{ github.event.client_payload.schemaUrl || github.event.inputs.schema_url || '' }}"
53
+ if [ -z "$SCHEMA_URL" ]; then
54
+ echo " schemaUrl not provided via repository_dispatch payload or workflow input"; exit 1
59
55
  fi
60
- echo "url=$SCHEMA_URL" >> $GITHUB_OUTPUT
56
+ echo "schema_url=$SCHEMA_URL" >> "$GITHUB_OUTPUT"
61
57
 
62
58
  - name: Display schema update context
63
59
  run: |
64
- if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
65
- echo "Schema update received from: ${{ github.event.client_payload.sourceRepo }}"
66
- echo "Schema URL: ${{ github.event.client_payload.schemaUrl }}"
67
- echo "Source commit: ${{ github.event.client_payload.commit }}"
68
- echo "Source branch: ${{ github.event.client_payload.branch }}"
69
- echo "Timestamp: ${{ github.event.client_payload.timestamp }}"
70
- else
71
- echo "Event type: ${{ github.event_name }}"
72
- echo "Schema URL: ${{ steps.schema-url.outputs.url }}"
73
- fi
60
+ echo "Schema update received from: ${{ github.event.client_payload.sourceRepo }}"
61
+ echo "Schema URL: ${{ steps.set-schema-url.outputs.schema_url }}"
62
+ echo "Source commit: ${{ github.event.client_payload.commit }}"
63
+ echo "Source branch: ${{ github.event.client_payload.branch }}"
64
+ echo "Timestamp: ${{ github.event.client_payload.timestamp }}"
74
65
 
75
66
  - name: Fetch updated schema
76
- run: pnpm exec api-tool fetch --url ${{ steps.schema-url.outputs.url }} --output new-schema.graphql
67
+ run: api-tool fetch --url ${{ steps.set-schema-url.outputs.schema_url }} --output new-schema.graphql
77
68
 
69
+ - name: Update local schema files
70
+ id: update-schema
71
+ run: |
72
+ echo "🔍 Searching for local schema files to update..."
73
+ api-tool update-local-schema \
74
+ --schema-url "${{ steps.set-schema-url.outputs.schema_url }}" \
75
+ --schema-file new-schema.graphql \
76
+ --output schema-update-result.json
77
+
78
+ # Read the results
79
+ if [ -f schema-update-result.json ]; then
80
+ SERVICE_NAME=$(jq -r '.serviceName // "unknown"' schema-update-result.json)
81
+ UPDATED_COUNT=$(jq -r '.updatedFiles | length' schema-update-result.json)
82
+ HAS_CHANGES=$(jq -r '.hasChanges' schema-update-result.json)
83
+
84
+ echo "service_name=$SERVICE_NAME" >> $GITHUB_OUTPUT
85
+ echo "updated_count=$UPDATED_COUNT" >> $GITHUB_OUTPUT
86
+ echo "has_changes=$HAS_CHANGES" >> $GITHUB_OUTPUT
87
+
88
+ if [ "$HAS_CHANGES" = "true" ]; then
89
+ echo "✅ Updated $UPDATED_COUNT schema file(s) for service: $SERVICE_NAME"
90
+ jq -r '.updatedFiles[]' schema-update-result.json | while read file; do
91
+ echo " - $file"
92
+ done
93
+ else
94
+ echo "ℹ️ No changes detected in schema files"
95
+ fi
96
+ else
97
+ echo "has_changes=false" >> $GITHUB_OUTPUT
98
+ echo "⚠️ No schema files found to update"
99
+ fi
78
100
  - name: Validate queries against new schema
79
101
  id: validate
80
- run: pnpm exec api-tool validate --schema new-schema.graphql --queries 'src/**/*.graphql' --output report.json
102
+ run: api-tool validate --schema new-schema.graphql --queries 'src/**/*.graphql' --output report.json
81
103
 
82
104
  - name: Check for issues
83
105
  id: check-issues
84
106
  run: |
85
- if [ -s report.json ] && [ "$(jq 'length' report.json)" -gt 0 ]; then
107
+ if [ -s report.json ] && [ "$(jq '.issues | length' report.json)" -gt 0 ]; then
86
108
  echo "has_issues=true" >> $GITHUB_OUTPUT
87
- echo "issue_count=$(jq 'length' report.json)" >> $GITHUB_OUTPUT
109
+ echo "issue_count=$(jq '.issues | length' report.json)" >> $GITHUB_OUTPUT
88
110
  else
89
111
  echo "has_issues=false" >> $GITHUB_OUTPUT
90
112
  echo "issue_count=0" >> $GITHUB_OUTPUT
91
113
  fi
92
114
 
93
- - name: Generate summary
115
+ - name: Generate validation summary
94
116
  id: gen-summary
95
- if: steps.check-issues.outputs.has_issues == 'true'
96
- run: pnpm exec api-tool summarize --report report.json --output GRAPHQL_ISSUES.md && echo "summary=$(cat GRAPHQL_ISSUES.md)" >> $GITHUB_OUTPUT
117
+ run: |
118
+ # Always generate summary, even if no issues (for consistency)
119
+ if [ ! -f report.json ]; then
120
+ echo "[]" > report.json
121
+ fi
122
+ api-tool summarize --report report.json --output GRAPHQL_ISSUES.md
123
+
124
+ # Also generate a summary of updated files
125
+ if [ -f schema-update-result.json ]; then
126
+ echo "## 📝 Updated Schema Files" > SCHEMA_CHANGES.md
127
+ echo "" >> SCHEMA_CHANGES.md
128
+ jq -r '.updatedFiles[]' schema-update-result.json | while read file; do
129
+ echo "- \`$file\`" >> SCHEMA_CHANGES.md
130
+ done
131
+ echo "" >> SCHEMA_CHANGES.md
132
+ fi
133
+
134
+ # Expose summaries as step outputs for later steps (multiline-safe)
135
+ {
136
+ echo 'issues_summary<<EOF'
137
+ cat GRAPHQL_ISSUES.md
138
+ echo EOF
139
+ } >> $GITHUB_OUTPUT
140
+
141
+ {
142
+ echo 'schema_changes<<EOF'
143
+ if [ -f SCHEMA_CHANGES.md ]; then
144
+ cat SCHEMA_CHANGES.md
145
+ else
146
+ echo "- No files updated"
147
+ fi
148
+ echo EOF
149
+ } >> $GITHUB_OUTPUT
97
150
 
98
- - name: Commit and create PR with issues
151
+ - name: Commit and create PR
152
+ if: steps.update-schema.outputs.has_changes == 'true'
153
+ id: create-pr
99
154
  uses: peter-evans/create-pull-request@v6
100
155
  with:
101
- commit-message: "chore(api): GraphQL schema update${{ github.event_name == 'repository_dispatch' && format(' from {0}', github.event.client_payload.sourceRepo) || '' }}"
156
+ commit-message: "chore(api): Update GraphQL schema for ${{ steps.update-schema.outputs.service_name }}${{ github.event_name == 'repository_dispatch' && format(' from {0}', github.event.client_payload.sourceRepo) || '' }}"
102
157
  branch: "graphql/schema-update-${{ github.run_id }}"
103
- title: "GraphQL Schema Update (${{ steps.check-issues.outputs.issue_count }} issues)"
158
+ title: "GraphQL Schema Update - ${{ steps.update-schema.outputs.service_name }} (${{ steps.check-issues.outputs.issue_count }} issues)"
104
159
  body: |
105
160
  # GraphQL Schema Update Impact Report
106
161
 
107
- ${{ github.event_name == 'repository_dispatch' && format('**Schema Source:** {0}', github.event.client_payload.sourceRepo) || '' }}
108
- **Schema URL:** ${{ steps.schema-url.outputs.url }}
109
- ${{ github.event_name == 'repository_dispatch' && format('**Source Commit:** {0}', github.event.client_payload.commit) || '' }}
110
- ${{ github.event_name == 'repository_dispatch' && format('**Source Branch:** {0}', github.event.client_payload.branch) || '' }}
111
- ${{ github.event_name == 'repository_dispatch' && format('**Update Time:** {0}', github.event.client_payload.timestamp) || '' }}
112
- **Trigger:** ${{ github.event_name }}
162
+ ## Summary
163
+
164
+ **Service:** `${{ steps.update-schema.outputs.service_name }}`
165
+ **Updated Files:** ${{ steps.update-schema.outputs.updated_count }}
166
+ **Validation Issues:** ${{ steps.check-issues.outputs.issue_count }}
167
+ **Status:** ${{ steps.check-issues.outputs.has_issues == 'true' && '⚠️ Action Required' || '✅ Ready to Merge' }}
113
168
 
114
169
  ---
115
- ## ${{ steps.check-issues.outputs.has_issues == 'true' && 'Detected Issues' || '🎉 No Issues Found' }}
116
- ${{ steps.check-issues.outputs.has_issues == 'true' && steps.gen-summary.outputs.summary || 'The updated schema is compatible with your existing GraphQL queries' }}
117
170
 
118
- ## Next Steps
119
- 1. Review any compatibility issues above
120
- 2. Update your GraphQL queries to match the new schema
121
- 3. Test your changes thoroughly
122
- 4. Merge this PR once all issues are resolved
171
+ ## Schema Files Updated
172
+
173
+ The following schema files have been updated with the latest schema from the source:
174
+
175
+ ${{ steps.gen-summary.outputs.schema_changes }}
123
176
 
124
- - name: Display validation results (for manual runs)
177
+ ---
178
+
179
+ ## ${{ steps.check-issues.outputs.has_issues == 'true' && '⚠️ Validation Issues Found' || '✅ No Validation Issues' }}
180
+
181
+ ${{ steps.check-issues.outputs.has_issues == 'true' && 'The following GraphQL queries are incompatible with the updated schema and need to be fixed:\n\n' || 'All existing GraphQL queries are compatible with the updated schema. No changes to queries are required.\n\n' }}${{ steps.gen-summary.outputs.issues_summary }}
182
+
183
+ ---
184
+
185
+ ## Source Information
186
+
187
+ ${{ github.event_name == 'repository_dispatch' && format('- **Schema Source:** {0}', github.event.client_payload.sourceRepo) || '' }}
188
+ - **Schema URL:** ${{ github.event.client_payload.schemaUrl }}
189
+ ${{ github.event_name == 'repository_dispatch' && format('- **Source Commit:** {0}', github.event.client_payload.commit) || '' }}
190
+ ${{ github.event_name == 'repository_dispatch' && format('- **Source Branch:** {0}', github.event.client_payload.branch) || '' }}
191
+ ${{ github.event_name == 'repository_dispatch' && format('- **Update Time:** {0}', github.event.client_payload.timestamp) || '' }}
192
+ - **Trigger:** ${{ github.event_name }}
193
+
194
+ ---
195
+
196
+ ## 🚀 Next Steps
197
+
198
+ ${{ steps.check-issues.outputs.has_issues == 'true' && '1. ⚠️ **Review the validation issues above**\n2. 🔧 **Update the affected GraphQL queries** to match the new schema\n3. **Test your changes**\n4. **Push your fixes** to this branch\n5. **Merge this PR** once all issues are resolved' || '1. **Review the schema changes** in the Files Changed tab\n2. **Verify the changes** look correct\n3. **Merge this PR** to update your schema' }}
199
+
200
+ - name: Display validation results
125
201
  if: github.event_name == 'workflow_dispatch'
126
202
  run: |
127
- echo "## 📊 GraphQL Schema Validation Results" >> $GITHUB_STEP_SUMMARY
203
+ echo "## GraphQL Schema Validation Results" >> $GITHUB_STEP_SUMMARY
128
204
  echo "" >> $GITHUB_STEP_SUMMARY
129
- echo "**Schema URL:** ${{ steps.schema-url.outputs.url }}" >> $GITHUB_STEP_SUMMARY
205
+ echo "**Schema URL:** ${{ steps.set-schema-url.outputs.schema_url }}" >> $GITHUB_STEP_SUMMARY
130
206
  echo "**Event:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
131
207
  echo "" >> $GITHUB_STEP_SUMMARY
132
208
 
@@ -142,12 +218,14 @@ jobs:
142
218
  echo "The schema is compatible with all existing GraphQL queries." >> $GITHUB_STEP_SUMMARY
143
219
  fi
144
220
 
145
- - name: Create success comment
146
- if: steps.check-issues.outputs.has_issues == 'false'
221
+ - name: No changes needed
222
+ if: steps.update-schema.outputs.has_changes == 'false'
147
223
  run: |
148
- echo "✅ No GraphQL compatibility issues found!"
149
- if [ "${{ github.event_name }}" = "repository_dispatch" ]; then
150
- echo "Schema from ${{ github.event.client_payload.sourceRepo }} is compatible with existing queries."
151
- else
152
- echo "Schema from ${{ steps.schema-url.outputs.url }} is compatible with existing queries."
224
+ echo "✅ Schema is already up to date - no PR needed"
225
+ echo "### Schema Already Up To Date" >> $GITHUB_STEP_SUMMARY
226
+ echo "" >> $GITHUB_STEP_SUMMARY
227
+ echo "The fetched schema matches the current schema file(s). No changes or action needed." >> $GITHUB_STEP_SUMMARY
228
+ if [ "${{ steps.check-issues.outputs.has_issues }}" = "false" ]; then
229
+ echo "" >> $GITHUB_STEP_SUMMARY
230
+ echo "All existing queries are compatible with the schema." >> $GITHUB_STEP_SUMMARY
153
231
  fi