Skip to content

Commit 21d7d21

Browse files
authored
freeze ndc-lambda-sdk version (#100)
1 parent faa78ed commit 21d7d21

File tree

10 files changed

+462
-839
lines changed

10 files changed

+462
-839
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
# test files
55
**/test-data/**
66
./tests/**
7-
**/*.test.ts
7+
**/*.test.ts
8+
9+
# scripts
10+
./scripts/**
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
name: Auto Update NDC Lambda SDK
2+
3+
on:
4+
schedule:
5+
# Run daily at 9 AM UTC
6+
- cron: '0 9 * * *'
7+
workflow_dispatch: # Allow manual triggering
8+
9+
jobs:
10+
check-and-update-ndc-lambda-sdk:
11+
runs-on: ubuntu-24.04
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
env:
16+
RUNNING_IN_CI: "true"
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
with:
24+
node-version: '20.x'
25+
26+
- name: Verify GitHub CLI availability
27+
run: |
28+
if ! command -v gh &> /dev/null; then
29+
echo "❌ GitHub CLI is not available in CI environment"
30+
echo "This is required for PR creation and management"
31+
exit 1
32+
fi
33+
echo "✅ GitHub CLI is available"
34+
gh --version
35+
36+
- name: Get current version from context.ts
37+
id: current-version
38+
run: |
39+
CURRENT_VERSION=$(grep -E "const NDC_NODEJS_LAMBDA_SDK_VERSION = " src/app/context.ts | sed -E 's/.*"([^"]+)".*/\1/')
40+
echo "current-version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
41+
echo "Current version in context.ts: $CURRENT_VERSION"
42+
43+
- name: Get latest release from GitHub API
44+
id: latest-release
45+
run: |
46+
LATEST_RELEASE=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest | jq -r '.tag_name')
47+
echo "latest-version=$LATEST_RELEASE" >> $GITHUB_OUTPUT
48+
echo "Latest release: $LATEST_RELEASE"
49+
50+
- name: Compare versions
51+
id: compare
52+
run: |
53+
CURRENT="${{ steps.current-version.outputs.current-version }}"
54+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
55+
56+
if [ "$CURRENT" = "$LATEST" ]; then
57+
echo "needs-update=false" >> $GITHUB_OUTPUT
58+
echo "✅ Already up to date: $CURRENT"
59+
else
60+
echo "needs-update=true" >> $GITHUB_OUTPUT
61+
echo "🔄 Update needed: $CURRENT -> $LATEST"
62+
fi
63+
64+
- name: Check for existing PR
65+
id: check-pr
66+
if: steps.compare.outputs.needs-update == 'true'
67+
run: |
68+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
69+
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')
73+
74+
if [ -n "$EXISTING_PR" ]; then
75+
echo "pr-exists=true" >> $GITHUB_OUTPUT
76+
echo "pr-number=$EXISTING_PR" >> $GITHUB_OUTPUT
77+
echo "✅ PR already exists: #$EXISTING_PR"
78+
else
79+
echo "pr-exists=false" >> $GITHUB_OUTPUT
80+
echo "🆕 No existing PR found"
81+
fi
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
85+
- name: Get release changelog
86+
id: changelog
87+
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
88+
run: |
89+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
90+
91+
# Get release notes from GitHub API
92+
RELEASE_NOTES=$(curl -s https://api.github.com/repos/hasura/ndc-nodejs-lambda/releases/latest | jq -r '.body // "No release notes available"')
93+
94+
# Save to file to handle multiline content
95+
echo "$RELEASE_NOTES" > release_notes.txt
96+
echo "Release notes saved to release_notes.txt"
97+
98+
- name: Create branch and update files
99+
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
100+
run: |
101+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
102+
BRANCH_NAME="auto-update/ndc-lambda-sdk-$LATEST"
103+
104+
# Configure git
105+
git config user.name "github-actions[bot]"
106+
git config user.email "github-actions[bot]@users.noreply.github.com"
107+
108+
# Create and switch to new branch
109+
git checkout -b "$BRANCH_NAME"
110+
111+
# Update context.ts
112+
sed -i "s/const NDC_NODEJS_LAMBDA_SDK_VERSION = \".*\";/const NDC_NODEJS_LAMBDA_SDK_VERSION = \"$LATEST\";/" src/app/context.ts
113+
114+
# Update Dockerfile
115+
sed -i "s|FROM ghcr.io/hasura/ndc-nodejs-lambda:.*|FROM ghcr.io/hasura/ndc-nodejs-lambda:$LATEST|" connector-definition/.hasura-connector/Dockerfile
116+
117+
# Commit changes
118+
git add src/app/context.ts connector-definition/.hasura-connector/Dockerfile
119+
git commit -m "chore: update NDC Lambda SDK to $LATEST"
120+
121+
# Push branch
122+
git push origin "$BRANCH_NAME"
123+
124+
echo "branch-name=$BRANCH_NAME" >> $GITHUB_OUTPUT
125+
env:
126+
GITHUB_OUTPUT: ${{ github.output }}
127+
128+
- name: Create Pull Request
129+
if: steps.compare.outputs.needs-update == 'true' && steps.check-pr.outputs.pr-exists == 'false'
130+
run: |
131+
LATEST="${{ steps.latest-release.outputs.latest-version }}"
132+
CURRENT="${{ steps.current-version.outputs.current-version }}"
133+
BRANCH_NAME="auto-update/ndc-lambda-sdk-$LATEST"
134+
135+
# Create PR description
136+
cat > pr_description.md << EOF
137+
## 🚀 Auto Update: NDC Lambda SDK $CURRENT → $LATEST
138+
139+
This PR automatically updates the NDC Lambda SDK version from \`$CURRENT\` to \`$LATEST\`.
140+
141+
### 📋 Changes Made
142+
- Updated \`NDC_NODEJS_LAMBDA_SDK_VERSION\` in \`src/app/context.ts\`
143+
- Updated Docker image version in \`connector-definition/.hasura-connector/Dockerfile\`
144+
145+
### 🔗 Release Information
146+
**Release:** [hasura/ndc-nodejs-lambda@$LATEST](https://github.com/hasura/ndc-nodejs-lambda/releases/tag/$LATEST)
147+
148+
### 📝 Changelog
149+
\`\`\`
150+
$(cat release_notes.txt)
151+
\`\`\`
152+
153+
### ✅ Verification
154+
Please verify that:
155+
- [ ] The version update is correct
156+
- [ ] All tests pass
157+
- [ ] The changelog looks reasonable
158+
159+
---
160+
*This PR was automatically created by the Auto Update NDC Lambda SDK workflow.*
161+
EOF
162+
163+
# Create the PR
164+
gh pr create \
165+
--title "chore: update NDC Lambda SDK to $LATEST" \
166+
--body-file pr_description.md \
167+
--head "$BRANCH_NAME" \
168+
--base main \
169+
--reviewer m-Bilal \
170+
--label "dependencies" \
171+
--label "automated"
172+
173+
echo "✅ Pull Request created successfully!"
174+
env:
175+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176+
177+
- name: Summary
178+
run: |
179+
if [ "${{ steps.compare.outputs.needs-update }}" = "false" ]; then
180+
echo "✅ NDC Lambda SDK is already up to date"
181+
elif [ "${{ steps.check-pr.outputs.pr-exists }}" = "true" ]; then
182+
echo "✅ Update needed but PR already exists: #${{ steps.check-pr.outputs.pr-number }}"
183+
else
184+
echo "✅ Created new PR to update NDC Lambda SDK to ${{ steps.latest-release.outputs.latest-version }}"
185+
fi
186+
187+
- name: Create failure issue
188+
if: failure()
189+
run: |
190+
# Get the workflow run URL
191+
WORKFLOW_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
192+
193+
# Create issue description
194+
cat > issue_description.md << EOF
195+
## 🚨 Auto Update NDC Lambda SDK Workflow Failed
196+
197+
The automated workflow to check and update the NDC Lambda SDK has failed.
198+
199+
### 📋 Failure Details
200+
- **Workflow Run**: [${{ github.run_id }}]($WORKFLOW_URL)
201+
- **Repository**: ${{ github.repository }}
202+
- **Branch**: ${{ github.ref_name }}
203+
- **Triggered by**: ${{ github.event_name }}
204+
- **Run Date**: $(date -u '+%Y-%m-%d %H:%M:%S UTC')
205+
206+
### 🔍 What to Check
207+
Please review the workflow logs to determine the cause of the failure:
208+
1. Check if GitHub CLI is available and authenticated
209+
2. Verify API access to hasura/ndc-nodejs-lambda repository
210+
3. Check for any network or permission issues
211+
4. Review the version comparison logic
212+
213+
### 🔗 Links
214+
- [Failed Workflow Run]($WORKFLOW_URL)
215+
- [Workflow File](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/.github/workflows/auto-update-ndc-lambda-sdk.yaml)
216+
- [Manual Check Script](https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/scripts/check-ndc-lambda-sdk-updates.sh)
217+
218+
### 🛠️ Manual Workaround
219+
You can manually check for updates by running:
220+
\`\`\`bash
221+
npm run check-ndc-updates
222+
\`\`\`
223+
224+
---
225+
226+
@m-Bilal Please investigate this failure and fix the automated workflow.
227+
228+
*This issue was automatically created by the failed Auto Update NDC Lambda SDK workflow.*
229+
EOF
230+
231+
# Create the issue
232+
gh issue create \
233+
--title "🚨 Auto Update NDC Lambda SDK Workflow Failed - Run #${{ github.run_id }}" \
234+
--body-file issue_description.md \
235+
--assignee m-Bilal \
236+
--label "bug" \
237+
--label "automation" \
238+
--label "high-priority"
239+
240+
echo "✅ Failure issue created successfully!"
241+
env:
242+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ name: Test
33
on: pull_request
44

55
jobs:
6+
verify-ndc-lambda-sdk-version:
7+
runs-on: ubuntu-24.04
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Verify NDC Lambda SDK Version Consistency
12+
run: bash tests/scripts/verify-ndc-lambda-sdk-version.sh
13+
614
unit-tests:
715
runs-on: ubuntu-24.04
816
steps:
@@ -15,7 +23,7 @@ jobs:
1523

1624
- name: Install dependencies
1725
run: npm ci
18-
26+
1927
- name: Compile
2028
run: npm run compile
2129

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Freeze `ndc-nodejs-lambda` to `v1.15.0` ([#100](https://github.com/hasura/ndc-open-api-lambda/pull/100))
6+
57
## [[1.7.0](https://github.com/hasura/ndc-open-api-lambda/releases/tag/v1.7.0)] 2025-07-15
68

79
- Update NDC NodeJS Lambda to `v1.15.0` ([#98](https://github.com/hasura/ndc-open-api-lambda/pull/98))

0 commit comments

Comments
 (0)