-
Notifications
You must be signed in to change notification settings - Fork 3
251 lines (219 loc) · 9.28 KB
/
ddn-test.yaml
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
name: Axiom auto-test + auto-deploy
permissions:
contents: read
pull-requests: write
on:
# Manual approval of environment is required
pull_request_target:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
environment: CI
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Check for [no-op] in commit message
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^\[no-op\] ]]; then
echo "no_op=true" >> $GITHUB_ENV
else
echo "no_op=false" >> $GITHUB_ENV
fi
- name: Set up DDN CLI and Login
if: env.no_op != 'true'
uses: hasura/ddn-deployment@main
with:
hasura-pat: ${{ secrets.HASURA_PAT }}
- name: Install dependencies
if: env.no_op != 'true'
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Create .env.cloud.dev
working-directory: ./hasura
if: env.no_op != 'true'
run: |
echo "${{ secrets.ENV_CLOUD_DEFAULT }}" > .env.cloud.dev
- name: Detect Connector Changes
if: env.no_op != 'true'
run: |
# Pull the base branch
git fetch origin ${{ github.base_ref }}
# Check if any changes occurred in the connector directories
if git diff --name-only origin/${{ github.base_ref }} ${{ github.sha }} | grep -q 'connector/'; then
echo "connector_changes=true" >> $GITHUB_ENV
else
echo "connector_changes=false" >> $GITHUB_ENV
fi
- name: Install deploy script dependencies
if: env.no_op != 'true'
run: |
cd ./scripts/deploy
npm i
- name: Build supergraph
if: env.no_op != 'true'
run: |
calculatedSha=$(git rev-parse --short ${{ github.event.pull_request.head.sha }})
if [ "${{ env.connector_changes }}" = "true" ]; then
echo "Building connectors..."
./scripts/deploy/deploy.mjs \
--context axiom-dev \
--profile telco \
--override-description "${calculatedSha} [PR-${{ github.event.pull_request.number }}] ${{ github.event.pull_request.title }} | Build for commit ${{ github.event.pull_request.head.sha }}" \
--rebuild-connectors \
--override \
--log-level FATAL \
--quiet \
--no-interaction > build_output.json
else
echo "Skipping connector build."
./scripts/deploy/deploy.mjs \
--context axiom-dev \
--profile telco \
--override-description "${calculatedSha} [PR-${{ github.event.pull_request.number }}] ${{ github.event.pull_request.title }} | Build for commit ${{ github.event.pull_request.head.sha }}" \
--override \
--log-level FATAL \
--quiet \
--no-interaction > build_output.json
fi
- name: Extract URLs from JSON
if: env.no_op != 'true'
run: |
cat build_output.json
BUILD_URLS=$(jq -r '.build_url' build_output.json | tr '\n' ',')
CONSOLE_URLS=$(jq -r '.console_url' build_output.json | tr '\n' ',')
echo "build_urls=${BUILD_URLS%,}" >> $GITHUB_ENV
echo "console_urls=${CONSOLE_URLS%,}" >> $GITHUB_ENV
- name: Add PR comment with build details
if: env.no_op != 'true'
uses: actions/github-script@v7
with:
script: |
const buildUrls = process.env.build_urls.split(',').map(url => url.trim());
const consoleUrls = process.env.console_urls.split(',').map(url => url.trim());
const prNumber = context.payload.pull_request.number;
const commitId = context.payload.pull_request.head.sha;
const buildUrlsList = buildUrls.map(url => `- [${url}](${url})`).join('\n');
const consoleUrlsList = consoleUrls.map(url => `- [${url}](${url})`).join('\n');
const commentBody = `
Supergraph build was successful! 🎉
**Build URLs:**
${buildUrlsList}
**Console URLs:**
${consoleUrlsList}
**Commit ID:** ${commitId}
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: commentBody
})
- name: Add PR comment with no-op
if: env.no_op != 'false'
uses: actions/github-script@v7
with:
script: |
const commitId = context.payload.pull_request.head.sha;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `**[no-op] build detected:** No build attempted\n**Commit ID:** ${commitId}`
})
test:
runs-on: ubuntu-latest
environment: CI
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Check for [no-op] in commit message
run: |
if [[ "${{ github.event.pull_request.title }}" =~ ^\[no-op\] ]]; then
echo "no_op=true" >> $GITHUB_ENV
else
echo "no_op=false" >> $GITHUB_ENV
fi
- name: Set up DDN CLI and login
if: env.no_op != 'true'
uses: hasura/ddn-deployment@main
with:
hasura-pat: ${{ secrets.HASURA_PAT }}
- name: Install dependencies (jq)
if: env.no_op != 'true'
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Prep repository
if: env.no_op != 'true'
run: |
cp hasura/.env.telco.template hasura/.env.telco
cp .data/.env.template .data/telco/.env
- name: Build all supergraphs
working-directory: ./hasura
if: env.no_op != 'true'
run: |
ddn supergraph build local --supergraph supergraph-config/telco/1-supergraph-project-queries.yaml
ddn supergraph build local --supergraph supergraph-config/telco/2-supergraph-domain.yaml
ddn supergraph build local --supergraph supergraph-config/telco/3-supergraph.yaml
ddn supergraph build local --supergraph supergraph-config/telco/4-supergraph-with-mutations.yaml
- name: Set up demo databases & Run DDN
working-directory: ./hasura
if: env.no_op != 'true'
env:
HASURA_DDN_PAT: ${{ secrets.HASURA_PAT }}
run: |
ddn run demo-telco
- name: Wait for DDN to be ready
if: env.no_op != 'true'
run: |
echo "Waiting for GraphQL service to start..."
until curl -s http://localhost:3000/graphql -o /dev/null; do
echo "Service not ready, retrying in 5 seconds..."
sleep 5
done
echo "Service is up!"
- name: Query DDN endpoint and validate response
if: env.no_op != 'true'
run: |
QUERY='{
"query": "query getUsers { usersById(id: 1) { email formatCreatedAtTimestamp } customers(limit: 1) { firstName lastName email segment customerLinks { customerPreferences { socialMedia { linkedin } } supportDB { supportHistory { date status } } } creditCards { maskCreditCard expiry cvv } billings { formatBillingDate paymentStatus totalAmount } } calls(limit: 1) { callid } cdr(limit: 1) { guid } documents(limit: 1) { uuid } }"
}'
EXPECTED_RESPONSE='{
"data": {
"usersById": { "email": "[email protected]", "formatCreatedAtTimestamp": "Sun Aug 18 2024" },
"customers": [{
"firstName": "Adam",
"lastName": "Mcdaniel",
"email": "[email protected]",
"segment": "family",
"customerLinks": [{
"customerPreferences": { "socialMedia": { "linkedin": null } },
"supportDB": { "supportHistory": [{ "date": "2020-03-22", "status": "Resolved" }] }
}],
"creditCards": [{ "maskCreditCard": "***********8922", "expiry": "2028-04-23", "cvv": 651 }],
"billings": [{ "formatBillingDate": "Thu Feb 02 2023", "paymentStatus": "overdue", "totalAmount": "50.50" }]
}],
"calls": [{ "callid": 188359 }],
"cdr": [{ "guid": "dd264970-f61f-429f-97f8-4761fea4de2f" }],
"documents": [{ "uuid": "a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d" }]
}
}'
RESPONSE=$(curl -s -X POST http://localhost:3000/graphql \
-H "Content-Type: application/json" \
-d "$QUERY")
# Compare the actual response with the expected response
if echo "$RESPONSE" | jq --argjson expected "$EXPECTED_RESPONSE" 'if . == $expected then "MATCH" else "MISMATCH" end' | grep -q "MATCH"; then
echo "✅ Response matches expected output."
else
echo "❌ Response does not match expected output."
echo "Expected: $EXPECTED_RESPONSE"
echo "Got: $RESPONSE"
exit 1
fi