12
12
permissions :
13
13
contents : write
14
14
pull-requests : write
15
+ issues : write
15
16
env :
16
17
RUNNING_IN_CI : " true"
17
18
steps :
@@ -36,14 +37,36 @@ jobs:
36
37
- name : Get current version from context.ts
37
38
id : current-version
38
39
run : |
40
+ echo "Debugging: Looking for version in context.ts"
41
+ grep -n "NDC_NODEJS_LAMBDA_SDK_VERSION" src/app/context.ts || echo "Pattern not found"
42
+
39
43
CURRENT_VERSION=$(grep -E "const NDC_NODEJS_LAMBDA_SDK_VERSION = " src/app/context.ts | sed -E 's/.*"([^"]+)".*/\1/')
44
+
45
+ if [ -z "$CURRENT_VERSION" ]; then
46
+ echo "❌ Failed to extract current version from context.ts"
47
+ echo "File content around the version:"
48
+ grep -A2 -B2 "NDC_NODEJS_LAMBDA_SDK_VERSION" src/app/context.ts || echo "No matches found"
49
+ exit 1
50
+ fi
51
+
40
52
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
41
53
echo "Current version in context.ts: $CURRENT_VERSION"
42
54
43
55
- name : Get latest release from GitHub API
44
56
id : latest-release
45
57
run : |
46
- LATEST_RELEASE=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest | jq -r '.tag_name')
58
+ echo "Debugging: Fetching latest release from GitHub API"
59
+ API_RESPONSE=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest)
60
+ echo "API Response: $API_RESPONSE"
61
+
62
+ LATEST_RELEASE=$(echo "$API_RESPONSE" | jq -r '.tag_name')
63
+
64
+ if [ -z "$LATEST_RELEASE" ] || [ "$LATEST_RELEASE" = "null" ]; then
65
+ echo "❌ Failed to extract latest release version"
66
+ echo "API Response was: $API_RESPONSE"
67
+ exit 1
68
+ fi
69
+
47
70
echo "latest-version=$LATEST_RELEASE" >> $GITHUB_OUTPUT
48
71
echo "Latest release: $LATEST_RELEASE"
49
72
52
75
run : |
53
76
CURRENT="${{ steps.current-version.outputs.current-version }}"
54
77
LATEST="${{ steps.latest-release.outputs.latest-version }}"
55
-
78
+
79
+ echo "Debugging version comparison:"
80
+ echo "CURRENT: '$CURRENT'"
81
+ echo "LATEST: '$LATEST'"
82
+
83
+ # Validate that we have non-empty versions
84
+ if [ -z "$CURRENT" ] || [ "$CURRENT" = "null" ]; then
85
+ echo "❌ Current version is empty or null"
86
+ exit 1
87
+ fi
88
+
89
+ if [ -z "$LATEST" ] || [ "$LATEST" = "null" ]; then
90
+ echo "❌ Latest version is empty or null"
91
+ exit 1
92
+ fi
93
+
56
94
if [ "$CURRENT" = "$LATEST" ]; then
57
95
echo "needs-update=false" >> $GITHUB_OUTPUT
58
96
echo "✅ Already up to date: $CURRENT"
@@ -67,9 +105,10 @@ jobs:
67
105
run : |
68
106
LATEST="${{ steps.latest-release.outputs.latest-version }}"
69
107
PR_TITLE="chore: update NDC Lambda SDK to $LATEST"
70
-
71
- # Check if PR already exists
72
- EXISTING_PR=$(gh pr list --state open --search "in:title \"update NDC Lambda SDK to $LATEST\"" --json number --jq '.[0].number // empty')
108
+ BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
109
+
110
+ # Check if PR already exists (check by branch name for more accuracy)
111
+ EXISTING_PR=$(gh pr list --state open --head "$BRANCH_NAME" --json number --jq '.[0].number // empty' 2>/dev/null || echo "")
73
112
74
113
if [ -n "$EXISTING_PR" ]; then
75
114
echo "pr-exists=true" >> $GITHUB_OUTPUT
@@ -99,38 +138,43 @@ jobs:
99
138
if : steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
100
139
run : |
101
140
LATEST="${{ steps.latest-release.outputs.latest-version }}"
102
- BRANCH_NAME="auto-update/ndc-lambda-sdk-$LATEST"
103
-
141
+ # Use github-ci/ prefix for branch name
142
+ BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
143
+
104
144
# Configure git
105
145
git config user.name "github-actions[bot]"
106
146
git config user.email "github-actions[bot]@users.noreply.github.com"
107
-
147
+
148
+ # Delete the branch if it exists remotely to avoid conflicts
149
+ git push origin --delete "$BRANCH_NAME" 2>/dev/null || echo "Branch doesn't exist remotely, continuing..."
150
+
108
151
# Create and switch to new branch
109
152
git checkout -b "$BRANCH_NAME"
110
-
153
+
111
154
# Update context.ts
112
155
sed -i "s/const NDC_NODEJS_LAMBDA_SDK_VERSION = \".*\";/const NDC_NODEJS_LAMBDA_SDK_VERSION = \"$LATEST\";/" src/app/context.ts
113
-
156
+
114
157
# Update Dockerfile
115
158
sed -i "s|FROM ghcr.io/hasura/ndc-nodejs-lambda:.*|FROM ghcr.io/hasura/ndc-nodejs-lambda:$LATEST|" connector-definition/.hasura-connector/Dockerfile
116
-
159
+
117
160
# Commit changes
118
161
git add src/app/context.ts connector-definition/.hasura-connector/Dockerfile
119
162
git commit -m "chore: update NDC Lambda SDK to $LATEST"
120
-
121
- # Push branch
163
+
164
+ # Push the new branch
122
165
git push origin "$BRANCH_NAME"
123
-
166
+
124
167
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
125
168
env :
126
169
GITHUB_OUTPUT : ${{ github.output }}
127
170
128
171
- name : Create Pull Request
172
+ id : create-pr
129
173
if : steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
130
174
run : |
131
175
LATEST="${{ steps.latest-release.outputs.latest-version }}"
132
176
CURRENT="${{ steps.current-version.outputs.current-version }}"
133
- BRANCH_NAME="auto-update/ ndc-lambda-sdk-$LATEST"
177
+ BRANCH_NAME="github-ci/update- ndc-lambda-sdk-$LATEST"
134
178
135
179
# Create PR description
136
180
cat > pr_description.md << EOF
@@ -167,10 +211,81 @@ jobs:
167
211
--head "$BRANCH_NAME" \
168
212
--base main \
169
213
--reviewer m-Bilal \
170
- --label "dependencies" \
171
- --label "automated"
214
+ --label "automation"
172
215
173
216
echo "✅ Pull Request created successfully!"
217
+
218
+ # Get the PR URL and number for changelog
219
+ PR_INFO=$(gh pr view "$BRANCH_NAME" --json url,number)
220
+ PR_URL=$(echo "$PR_INFO" | jq -r '.url')
221
+ PR_NUMBER=$(echo "$PR_INFO" | jq -r '.number')
222
+ echo "PR URL: $PR_URL"
223
+ echo "PR Number: $PR_NUMBER"
224
+ echo "pr-url=$PR_URL" >> $GITHUB_OUTPUT
225
+ echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT
226
+ env :
227
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
228
+
229
+ - name : Update changelog
230
+ if : steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
231
+ run : |
232
+ LATEST="${{ steps.latest-release.outputs.latest-version }}"
233
+ CURRENT="${{ steps.current-version.outputs.current-version }}"
234
+ BRANCH_NAME="github-ci/update-ndc-lambda-sdk-$LATEST"
235
+ PR_URL="${{ steps.create-pr.outputs.pr-url }}"
236
+ PR_NUMBER="${{ steps.create-pr.outputs.pr-number }}"
237
+
238
+ # Get current date
239
+ CURRENT_DATE=$(date '+%Y-%m-%d')
240
+
241
+ # Create changelog entry matching existing format
242
+ CHANGELOG_ENTRY="- Update NDC NodeJS Lambda to \`$LATEST\` ([#$PR_NUMBER]($PR_URL))"
243
+
244
+ # Check if changelog.md exists
245
+ if [ ! -f "changelog.md" ]; then
246
+ echo "❌ changelog.md not found"
247
+ exit 1
248
+ fi
249
+
250
+ # Create a temporary file with the new entry
251
+ echo "" > temp_entry.txt
252
+ echo "$CHANGELOG_ENTRY" >> temp_entry.txt
253
+
254
+ # Find the "## Unreleased" section and add the entry
255
+ if grep -q "## Unreleased" changelog.md; then
256
+ # Find line number of "## Unreleased" and insert after it
257
+ LINE_NUM=$(grep -n "## Unreleased" changelog.md | head -1 | cut -d: -f1)
258
+ NEXT_LINE=$((LINE_NUM + 1))
259
+
260
+ # Split file and insert entry
261
+ head -n $LINE_NUM changelog.md > changelog_temp.md
262
+ cat temp_entry.txt >> changelog_temp.md
263
+ tail -n +$NEXT_LINE changelog.md >> changelog_temp.md
264
+ mv changelog_temp.md changelog.md
265
+ echo "✅ Added changelog entry: $CHANGELOG_ENTRY"
266
+ else
267
+ # If no "## Unreleased" section, add it at the top
268
+ echo "Adding new Unreleased section to changelog.md"
269
+ echo "# Changelog" > changelog_temp.md
270
+ echo "" >> changelog_temp.md
271
+ echo "## Unreleased" >> changelog_temp.md
272
+ echo "" >> changelog_temp.md
273
+ echo "$CHANGELOG_ENTRY" >> changelog_temp.md
274
+ echo "" >> changelog_temp.md
275
+ cat changelog.md >> changelog_temp.md
276
+ mv changelog_temp.md changelog.md
277
+ echo "✅ Created Unreleased section and added entry"
278
+ fi
279
+
280
+ # Clean up temp file
281
+ rm -f temp_entry.txt
282
+
283
+ # Commit and push the changelog update
284
+ git add changelog.md
285
+ git commit -m "docs: add changelog entry for NDC Lambda SDK $LATEST update"
286
+ git push origin "$BRANCH_NAME"
287
+
288
+ echo "✅ Changelog updated and pushed to PR branch"
174
289
env :
175
290
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
176
291
@@ -186,7 +301,22 @@ jobs:
186
301
187
302
- name : Create failure issue
188
303
if : failure()
304
+ continue-on-error : true
189
305
run : |
306
+ # Ensure GitHub CLI is available for issue creation
307
+ if ! command -v gh &> /dev/null; then
308
+ echo "❌ GitHub CLI not available - cannot create failure issue"
309
+ exit 1
310
+ fi
311
+
312
+ # Test GitHub CLI authentication
313
+ if ! gh auth status &> /dev/null; then
314
+ echo "❌ GitHub CLI not authenticated - cannot create failure issue"
315
+ exit 1
316
+ fi
317
+
318
+ echo "✅ GitHub CLI is available and authenticated"
319
+
190
320
# Get the workflow run URL
191
321
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
192
322
@@ -223,20 +353,63 @@ jobs:
223
353
224
354
---
225
355
226
- @m-Bilal Please investigate this failure and fix the automated workflow.
356
+ ** @m-Bilal** Please investigate this failure and fix the automated workflow.
227
357
228
358
*This issue was automatically created by the failed Auto Update NDC Lambda SDK workflow.*
229
359
EOF
230
360
231
361
# Create the issue
232
- gh issue create \
362
+ echo "Creating failure issue..."
363
+ if gh issue create \
233
364
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
234
365
--body-file issue_description.md \
235
366
--assignee m-Bilal \
236
367
--label "bug" \
237
368
--label "automation" \
238
- --label "high-priority"
369
+ --label "high-priority"; then
370
+ echo "✅ Failure issue created successfully!"
371
+ else
372
+ echo "❌ Failed to create issue with assignee and labels"
373
+ echo "Attempting to create issue without assignee..."
374
+ # Fallback: try without assignee in case user doesn't exist or there are permission issues
375
+ if gh issue create \
376
+ --title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
377
+ --body-file issue_description.md \
378
+ --label "bug" \
379
+ --label "automation" \
380
+ --label "high-priority"; then
381
+ echo "✅ Fallback issue created successfully (please assign manually)"
382
+ else
383
+ echo "❌ Failed to create issue with labels, trying without labels..."
384
+ # Final fallback: try without labels in case they don't exist
385
+ if gh issue create \
386
+ --title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
387
+ --body-file issue_description.md \
388
+ --assignee m-Bilal; then
389
+ echo "✅ Issue created without labels (please add labels manually)"
390
+ else
391
+ echo "❌ Failed to create issue with assignee, trying minimal issue..."
392
+ # Create a simple fallback description that ensures you're tagged
393
+ cat > fallback_issue_description.md << EOF
394
+ 🚨 **Auto Update NDC Lambda SDK Workflow Failed**
239
395
240
- echo "✅ Failure issue created successfully!"
396
+ The automated workflow failed. Please check the logs:
397
+ https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
398
+
399
+ **@m-Bilal** Please investigate this failure.
400
+ EOF
401
+
402
+ # Ultimate fallback: just title and simple body with mention
403
+ if gh issue create \
404
+ --title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
405
+ --body-file fallback_issue_description.md; then
406
+ echo "✅ Minimal issue created successfully (please assign and label manually)"
407
+ else
408
+ echo "❌ Failed to create issue entirely"
409
+ exit 1
410
+ fi
411
+ fi
412
+ fi
413
+ fi
241
414
env :
242
415
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments