-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathauto-update-ndc-lambda-sdk.yaml
More file actions
415 lines (344 loc) · 16.7 KB
/
auto-update-ndc-lambda-sdk.yaml
File metadata and controls
415 lines (344 loc) · 16.7 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
name: Auto Update NDC Lambda SDK
on:
schedule:
# Run daily at 9 AM UTC
- cron: '0 9 * * *'
workflow_dispatch: # Allow manual triggering
jobs:
check-and-update-ndc-lambda-sdk:
runs-on: ubuntu-24.04
permissions:
contents: write
pull-requests: write
issues: write
env:
RUNNING_IN_CI: "true"
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Verify GitHub CLI availability
run: |
if ! command -v gh &> /dev/null; then
echo "❌ GitHub CLI is not available in CI environment"
echo "This is required for PR creation and management"
exit 1
fi
echo "✅ GitHub CLI is available"
gh --version
- name: Get current version from context.ts
id: current-version
run: |
echo "Debugging: Looking for version in context.ts"
grep -n "NDC_NODEJS_LAMBDA_SDK_VERSION" src/app/context.ts || echo "Pattern not found"
CURRENT_VERSION=$(grep -E "const NDC_NODEJS_LAMBDA_SDK_VERSION = " src/app/context.ts | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$CURRENT_VERSION" ]; then
echo "❌ Failed to extract current version from context.ts"
echo "File content around the version:"
grep -A2 -B2 "NDC_NODEJS_LAMBDA_SDK_VERSION" src/app/context.ts || echo "No matches found"
exit 1
fi
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
echo "Current version in context.ts: $CURRENT_VERSION"
- name: Get latest release from GitHub API
id: latest-release
run: |
echo "Debugging: Fetching latest release from GitHub API"
API_RESPONSE=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest)
echo "API Response: $API_RESPONSE"
LATEST_RELEASE=$(echo "$API_RESPONSE" | jq -r '.tag_name')
if [ -z "$LATEST_RELEASE" ] || [ "$LATEST_RELEASE" = "null" ]; then
echo "❌ Failed to extract latest release version"
echo "API Response was: $API_RESPONSE"
exit 1
fi
echo "latest-version=$LATEST_RELEASE" >> $GITHUB_OUTPUT
echo "Latest release: $LATEST_RELEASE"
- name: Compare versions
id: compare
run: |
CURRENT="${{ steps.current-version.outputs.current-version }}"
LATEST="${{ steps.latest-release.outputs.latest-version }}"
echo "Debugging version comparison:"
echo "CURRENT: '$CURRENT'"
echo "LATEST: '$LATEST'"
# Validate that we have non-empty versions
if [ -z "$CURRENT" ] || [ "$CURRENT" = "null" ]; then
echo "❌ Current version is empty or null"
exit 1
fi
if [ -z "$LATEST" ] || [ "$LATEST" = "null" ]; then
echo "❌ Latest version is empty or null"
exit 1
fi
if [ "$CURRENT" = "$LATEST" ]; then
echo "needs-update=false" >> $GITHUB_OUTPUT
echo "✅ Already up to date: $CURRENT"
else
echo "needs-update=true" >> $GITHUB_OUTPUT
echo "🔄 Update needed: $CURRENT -> $LATEST"
fi
- name: Check for existing PR
id: check-pr
if: steps.compare.outputs.needs-update == 'true'
run: |
LATEST="${{ steps.latest-release.outputs.latest-version }}"
PR_TITLE="chore: update NDC Lambda SDK to $LATEST"
BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
# Check if PR already exists (check by branch name for more accuracy)
EXISTING_PR=$(gh pr list --state open --head "$BRANCH_NAME" --json number --jq '.[0].number // empty' 2>/dev/null || echo "")
if [ -n "$EXISTING_PR" ]; then
echo "pr-exists=true" >> $GITHUB_OUTPUT
echo "pr-number=$EXISTING_PR" >> $GITHUB_OUTPUT
echo "✅ PR already exists: #$EXISTING_PR"
else
echo "pr-exists=false" >> $GITHUB_OUTPUT
echo "🆕 No existing PR found"
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get release changelog
id: changelog
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
run: |
LATEST="${{ steps.latest-release.outputs.latest-version }}"
# Get release notes from GitHub API
RELEASE_NOTES=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest | jq -r '.body // "No release notes available"')
# Save to file to handle multiline content
echo "$RELEASE_NOTES" > release_notes.txt
echo "Release notes saved to release_notes.txt"
- name: Create branch and update files
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
run: |
LATEST="${{ steps.latest-release.outputs.latest-version }}"
# Use github-ci/ prefix for branch name
BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Delete the branch if it exists remotely to avoid conflicts
git push origin --delete "$BRANCH_NAME" 2>/dev/null || echo "Branch doesn't exist remotely, continuing..."
# Create and switch to new branch
git checkout -b "$BRANCH_NAME"
# Update context.ts
sed -i "s/const NDC_NODEJS_LAMBDA_SDK_VERSION = \".*\";/const NDC_NODEJS_LAMBDA_SDK_VERSION = \"$LATEST\";/" src/app/context.ts
# Update Dockerfile
sed -i "s|FROM ghcr.io/hasura/ndc-nodejs-lambda:.*|FROM ghcr.io/hasura/ndc-nodejs-lambda:$LATEST|" connector-definition/.hasura-connector/Dockerfile
# Commit changes
git add src/app/context.ts connector-definition/.hasura-connector/Dockerfile
git commit -m "chore: update NDC Lambda SDK to $LATEST"
# Push the new branch
git push origin "$BRANCH_NAME"
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
env:
GITHUB_OUTPUT: ${{ github.output }}
- name: Create Pull Request
id: create-pr
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
run: |
LATEST="${{ steps.latest-release.outputs.latest-version }}"
CURRENT="${{ steps.current-version.outputs.current-version }}"
BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
# Create PR description
cat > pr_description.md << EOF
## 🚀 Auto Update: NDC Lambda SDK $CURRENT → $LATEST
This PR automatically updates the NDC Lambda SDK version from \`$CURRENT\` to \`$LATEST\`.
### 📋 Changes Made
- Updated \`NDC_NODEJS_LAMBDA_SDK_VERSION\` in \`src/app/context.ts\`
- Updated Docker image version in \`connector-definition/.hasura-connector/Dockerfile\`
### 🔗 Release Information
**Release:** [hasura/ndc-nodejs-lambda@$LATEST](https://github.com/hasura/ndc-nodejs-lambda/releases/tag/$LATEST)
### 📝 Changelog
\`\`\`
$(cat release_notes.txt)
\`\`\`
### ✅ Verification
Please verify that:
- [ ] The version update is correct
- [ ] All tests pass
- [ ] The changelog looks reasonable
---
*This PR was automatically created by the Auto Update NDC Lambda SDK workflow.*
EOF
# Create the PR
gh pr create \
--title "chore: update NDC Lambda SDK to $LATEST" \
--body-file pr_description.md \
--head "$BRANCH_NAME" \
--base main \
--reviewer m-Bilal \
--label "automation"
echo "✅ Pull Request created successfully!"
# Get the PR URL and number for changelog
PR_INFO=$(gh pr view "$BRANCH_NAME" --json url,number)
PR_URL=$(echo "$PR_INFO" | jq -r '.url')
PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
echo "PR URL: $PR_URL"
echo "PR Number: $PR_NUMBER"
echo "pr-url=$PR_URL" >> $GITHUB_OUTPUT
echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update changelog
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
run: |
LATEST="${{ steps.latest-release.outputs.latest-version }}"
CURRENT="${{ steps.current-version.outputs.current-version }}"
BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
PR_URL="${{ steps.create-pr.outputs.pr-url }}"
PR_NUMBER="${{ steps.create-pr.outputs.pr-number }}"
# Get current date
CURRENT_DATE=$(date '+%Y-%m-%d')
# Create changelog entry matching existing format
CHANGELOG_ENTRY="- Update NDC NodeJS Lambda to \`$LATEST\` ([#$PR_NUMBER]($PR_URL))"
# Check if changelog.md exists
if [ ! -f "changelog.md" ]; then
echo "❌ changelog.md not found"
exit 1
fi
# Create a temporary file with the new entry
echo "" > temp_entry.txt
echo "$CHANGELOG_ENTRY" >> temp_entry.txt
# Find the "## Unreleased" section and add the entry
if grep -q "## Unreleased" changelog.md; then
# Find line number of "## Unreleased" and insert after it
LINE_NUM=$(grep -n "## Unreleased" changelog.md | head -1 | cut -d: -f1)
NEXT_LINE=$((LINE_NUM + 1))
# Split file and insert entry
head -n $LINE_NUM changelog.md > changelog_temp.md
cat temp_entry.txt >> changelog_temp.md
tail -n +$NEXT_LINE changelog.md >> changelog_temp.md
mv changelog_temp.md changelog.md
echo "✅ Added changelog entry: $CHANGELOG_ENTRY"
else
# If no "## Unreleased" section, add it at the top
echo "Adding new Unreleased section to changelog.md"
echo "# Changelog" > changelog_temp.md
echo "" >> changelog_temp.md
echo "## Unreleased" >> changelog_temp.md
echo "" >> changelog_temp.md
echo "$CHANGELOG_ENTRY" >> changelog_temp.md
echo "" >> changelog_temp.md
cat changelog.md >> changelog_temp.md
mv changelog_temp.md changelog.md
echo "✅ Created Unreleased section and added entry"
fi
# Clean up temp file
rm -f temp_entry.txt
# Commit and push the changelog update
git add changelog.md
git commit -m "docs: add changelog entry for NDC Lambda SDK $LATEST update"
git push origin "$BRANCH_NAME"
echo "✅ Changelog updated and pushed to PR branch"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
run: |
if [ "${{ steps.compare.outputs.needs-update }}" = "false" ]; then
echo "✅ NDC Lambda SDK is already up to date"
elif [ "${{ steps.check-pr.outputs.pr-exists }}" = "true" ]; then
echo "✅ Update needed but PR already exists: #${{ steps.check-pr.outputs.pr-number }}"
else
echo "✅ Created new PR to update NDC Lambda SDK to ${{ steps.latest-release.outputs.latest-version }}"
fi
- name: Create failure issue
if: failure()
continue-on-error: true
run: |
# Ensure GitHub CLI is available for issue creation
if ! command -v gh &> /dev/null; then
echo "❌ GitHub CLI not available - cannot create failure issue"
exit 1
fi
# Test GitHub CLI authentication
if ! gh auth status &> /dev/null; then
echo "❌ GitHub CLI not authenticated - cannot create failure issue"
exit 1
fi
echo "✅ GitHub CLI is available and authenticated"
# Get the workflow run URL
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
# Create issue description
cat > issue_description.md << EOF
## 🚨 Auto Update NDC Lambda SDK Workflow Failed
The automated workflow to check and update the NDC Lambda SDK has failed.
### 📋 Failure Details
- **Workflow Run**: [${{ github.run_id }}]($WORKFLOW_URL)
- **Repository**: ${{ github.repository }}
- **Branch**: ${{ github.ref_name }}
- **Triggered by**: ${{ github.event_name }}
- **Run Date**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
### 🔍 What to Check
Please review the workflow logs to determine the cause of the failure:
1. Check if GitHub CLI is available and authenticated
2. Verify API access to hasura/ndc-nodejs-lambda repository
3. Check for any network or permission issues
4. Review the version comparison logic
### 🔗 Links
- [Failed Workflow Run]($WORKFLOW_URL)
- [Workflow File](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/.github/workflows/auto-update-ndc-lambda-sdk.yaml)
- [Manual Check Script](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/scripts/check-ndc-lambda-sdk-updates.sh)
### 🛠️ Manual Workaround
You can manually check for updates by running:
\`\`\`bash
npm run check-ndc-updates
\`\`\`
---
**@m-Bilal** Please investigate this failure and fix the automated workflow.
*This issue was automatically created by the failed Auto Update NDC Lambda SDK workflow.*
EOF
# Create the issue
echo "Creating failure issue..."
if gh issue create \
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
--body-file issue_description.md \
--assignee m-Bilal \
--label "bug" \
--label "automation" \
--label "high-priority"; then
echo "✅ Failure issue created successfully!"
else
echo "❌ Failed to create issue with assignee and labels"
echo "Attempting to create issue without assignee..."
# Fallback: try without assignee in case user doesn't exist or there are permission issues
if gh issue create \
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
--body-file issue_description.md \
--label "bug" \
--label "automation" \
--label "high-priority"; then
echo "✅ Fallback issue created successfully (please assign manually)"
else
echo "❌ Failed to create issue with labels, trying without labels..."
# Final fallback: try without labels in case they don't exist
if gh issue create \
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
--body-file issue_description.md \
--assignee m-Bilal; then
echo "✅ Issue created without labels (please add labels manually)"
else
echo "❌ Failed to create issue with assignee, trying minimal issue..."
# Create a simple fallback description that ensures you're tagged
cat > fallback_issue_description.md << EOF
🚨 **Auto Update NDC Lambda SDK Workflow Failed**
The automated workflow failed. Please check the logs:
https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
**@m-Bilal** Please investigate this failure.
EOF
# Ultimate fallback: just title and simple body with mention
if gh issue create \
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
--body-file fallback_issue_description.md; then
echo "✅ Minimal issue created successfully (please assign and label manually)"
else
echo "❌ Failed to create issue entirely"
exit 1
fi
fi
fi
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}