Skip to content

Commit 9dbdf70

Browse files
authored
fix issue creation for ndc-nodejs-lambda auto version bump job (#101)
1 parent 21d7d21 commit 9dbdf70

File tree

1 file changed

+194
-21
lines changed

1 file changed

+194
-21
lines changed

.github/workflows/auto-update-ndc-lambda-sdk.yaml

Lines changed: 194 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ jobs:
1212
permissions:
1313
contents: write
1414
pull-requests: write
15+
issues: write
1516
env:
1617
RUNNING_IN_CI: "true"
1718
steps:
@@ -36,14 +37,36 @@ jobs:
3637
- name: Get current version from context.ts
3738
id: current-version
3839
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+
3943
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+
4052
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
4153
echo "Current version in context.ts: $CURRENT_VERSION"
4254
4355
- name: Get latest release from GitHub API
4456
id: latest-release
4557
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+
4770
echo "latest-version=$LATEST_RELEASE" >> $GITHUB_OUTPUT
4871
echo "Latest release: $LATEST_RELEASE"
4972
@@ -52,7 +75,22 @@ jobs:
5275
run: |
5376
CURRENT="${{ steps.current-version.outputs.current-version }}"
5477
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+
5694
if [ "$CURRENT" = "$LATEST" ]; then
5795
echo "needs-update=false" >> $GITHUB_OUTPUT
5896
echo "✅ Already up to date: $CURRENT"
@@ -67,9 +105,10 @@ jobs:
67105
run: |
68106
LATEST="${{ steps.latest-release.outputs.latest-version }}"
69107
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 "")
73112
74113
if [ -n "$EXISTING_PR" ]; then
75114
echo "pr-exists=true" >> $GITHUB_OUTPUT
@@ -99,38 +138,43 @@ jobs:
99138
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
100139
run: |
101140
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+
104144
# Configure git
105145
git config user.name "github-actions[bot]"
106146
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+
108151
# Create and switch to new branch
109152
git checkout -b "$BRANCH_NAME"
110-
153+
111154
# Update context.ts
112155
sed -i "s/const NDC_NODEJS_LAMBDA_SDK_VERSION = \".*\";/const NDC_NODEJS_LAMBDA_SDK_VERSION = \"$LATEST\";/" src/app/context.ts
113-
156+
114157
# Update Dockerfile
115158
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+
117160
# Commit changes
118161
git add src/app/context.ts connector-definition/.hasura-connector/Dockerfile
119162
git commit -m "chore: update NDC Lambda SDK to $LATEST"
120-
121-
# Push branch
163+
164+
# Push the new branch
122165
git push origin "$BRANCH_NAME"
123-
166+
124167
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
125168
env:
126169
GITHUB_OUTPUT: ${{ github.output }}
127170

128171
- name: Create Pull Request
172+
id: create-pr
129173
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
130174
run: |
131175
LATEST="${{ steps.latest-release.outputs.latest-version }}"
132176
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"
134178
135179
# Create PR description
136180
cat > pr_description.md << EOF
@@ -167,10 +211,81 @@ jobs:
167211
--head "$BRANCH_NAME" \
168212
--base main \
169213
--reviewer m-Bilal \
170-
--label "dependencies" \
171-
--label "automated"
214+
--label "automation"
172215
173216
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"
174289
env:
175290
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176291

@@ -186,7 +301,22 @@ jobs:
186301
187302
- name: Create failure issue
188303
if: failure()
304+
continue-on-error: true
189305
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+
190320
# Get the workflow run URL
191321
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
192322
@@ -223,20 +353,63 @@ jobs:
223353
224354
---
225355
226-
@m-Bilal Please investigate this failure and fix the automated workflow.
356+
**@m-Bilal** Please investigate this failure and fix the automated workflow.
227357
228358
*This issue was automatically created by the failed Auto Update NDC Lambda SDK workflow.*
229359
EOF
230360
231361
# Create the issue
232-
gh issue create \
362+
echo "Creating failure issue..."
363+
if gh issue create \
233364
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
234365
--body-file issue_description.md \
235366
--assignee m-Bilal \
236367
--label "bug" \
237368
--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**
239395
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
241414
env:
242415
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)