Fixes environment var in ansible #68
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Axiom auto-test + auto-deploy | |
permissions: | |
contents: read | |
pull-requests: write | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- 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.default | |
if: env.no_op != 'true' | |
run: | | |
echo "${{ secrets.ENV_CLOUD_DEFAULT }}" > .env.cloud.default | |
- name: Detect Connector Changes | |
if: env.no_op != 'true' | |
run: | | |
# Check if any changes occurred in the connector directories | |
if git diff --name-only ${{ github.sha }}~1 ${{ github.sha }} | grep -q 'connector/'; then | |
echo "connector_changes=true" >> $GITHUB_ENV | |
else | |
echo "connector_changes=false" >> $GITHUB_ENV | |
fi | |
- name: Build supergraph | |
if: env.no_op != 'true' | |
run: | | |
calculatedSha=$(git rev-parse --short ${{ github.sha }}) | |
if [ "${{ env.connector_changes }}" = "true" ]; then | |
echo "Building connectors..." | |
ddn supergraph build create \ | |
--supergraph ./supergraph-with-mutations.yaml \ | |
--context default \ | |
--description "${calculatedSha} [PR-${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}] Test build for commit $GITHUB_SHA" \ | |
--out=json > build_output.json | |
else | |
echo "Skipping connector build." | |
ddn supergraph build create --no-build-connectors \ | |
--supergraph ./supergraph-with-mutations.yaml \ | |
--context default \ | |
--description "${calculatedSha} [PR-${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}] Test build for commit $GITHUB_SHA" \ | |
--out=json > build_output.json | |
fi | |
- name: Extract URLs from JSON | |
if: env.no_op != 'true' | |
run: | | |
BUILD_URL=$(jq -r '.build_url' build_output.json) | |
CONSOLE_URL=$(jq -r '.console_url' build_output.json) | |
echo "build_url=$BUILD_URL" >> $GITHUB_ENV | |
echo "console_url=$CONSOLE_URL" >> $GITHUB_ENV | |
- name: Add PR comment with build details | |
if: env.no_op != 'true' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const buildUrl = process.env.build_url; | |
const consoleUrl = process.env.console_url; | |
const prNumber = context.payload.pull_request.number; | |
const commitId = context.sha; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: `Supergraph build was successful! 🎉\n\n**Build URL:** [${buildUrl}](${buildUrl})\n**Console URL:** [${consoleUrl}](${consoleUrl})\n**Commit ID:** ${commitId}` | |
}) | |
- name: Add PR comment with no-op | |
if: env.no_op != 'false' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const commitId = context.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 | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- 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/context.yaml.template .hasura/context.yaml | |
cp .env.template .env | |
cp .env.local.template .env.local | |
cp .data/.env.template .data/.env | |
- name: Build All Supergraphs | |
if: env.no_op != 'true' | |
run: | | |
ddn supergraph build local --env-file .env.local --env-file .env --supergraph supergraph-project-queries.yaml | |
ddn supergraph build local --env-file .env.local --env-file .env --supergraph supergraph-domain.yaml | |
ddn supergraph build local --env-file .env.local --env-file .env --supergraph supergraph.yaml | |
ddn supergraph build local --env-file .env.local --env-file .env --supergraph supergraph-with-mutations.yaml | |
- name: Set up demo databases | |
if: env.no_op != 'true' | |
run: DATASET=telco docker compose -f .data/compose.yaml --env-file .data/.env up --build --pull always -d | |
- name: Run DDN | |
if: env.no_op != 'true' | |
env: | |
HASURA_DDN_PAT: ${{ secrets.HASURA_PAT }} | |
run: | | |
docker compose -f compose.yaml \ | |
--env-file .env.local \ | |
--env-file .env \ | |
up --build --pull always -d | |
- name: Wait for GraphQL Service 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": "adam.mcdaniel@bigpond.com", "formatCreatedAtTimestamp": "Sun Aug 18 2024" }, | |
"customers": [{ | |
"firstName": "Adam", | |
"lastName": "Mcdaniel", | |
"email": "adam.mcdaniel@bigpond.com", | |
"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 |