Skip to content

Commit

Permalink
Move localstack test to an external file
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed Sep 12, 2024
1 parent f093444 commit fe79051
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
37 changes: 37 additions & 0 deletions .github/execute-localstack-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -euo pipefail

log() {
echo $@ >&2
}

(cd cdk

set -x

log "Installing dependencies"
npm ci

log "Bootstrapping"
npm run cdklocal -- bootstrap

log "Deploying"
npm run cdklocal -- deploy --require-approval never --outputs-file outputs.json

export TEST_URL=$(jq -r .CdkStack.GraphQLURL outputs.json)
export TEST_API_KEY=$(jq -r .CdkStack.ApiKey outputs.json)

log "Accessing URL ${TEST_URL} with api key ${TEST_API_KEY}"
curl \
--connect-timeout 30 \
--retry 10 \
--retry-delay 6 \
-X POST \
-H "x-api-key:$TEST_API_KEY" \
-H "Accept:application/json" \
-H "Content-Type:application/json" \
$TEST_URL \
-d '{"query": "query { foo }"}'

)
25 changes: 4 additions & 21 deletions .github/workflows/test-appsync-utils.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: Test AppSync utils

on:
Expand Down Expand Up @@ -49,8 +48,8 @@ jobs:
- name: Start LocalStack
uses: LocalStack/[email protected]
with:
image-tag: 'latest'
use-pro: 'true'
image-tag: "latest"
use-pro: "true"
env:
LOCALSTACK_API_KEY: ${{ secrets.LOCALSTACK_API_KEY }}
APPSYNC_JS_LIBS_VERSION: ${{ github.sha }}
Expand All @@ -59,24 +58,8 @@ jobs:
- name: Ensure pro image is used
run: curl -s http://localhost:4566/_localstack/health | grep appsync
- uses: actions/setup-node@v4
- name: Install cdk project
working-directory: cdk
run: npm install
- name: CDK bootstrap
working-directory: cdk
run: npm run cdklocal -- bootstrap
- name: CDK deploy
working-directory: cdk
run: npm run cdklocal -- deploy --require-approval never --outputs-file outputs.json
- name: Fetch output variables for test step
working-directory: cdk
run: |
jq -r '"TEST_URL=\(.CdkStack.GraphQLURL)"' outputs.json >> $GITHUB_ENV
jq -r '"TEST_API_KEY=\(.CdkStack.ApiKey)"' outputs.json >> $GITHUB_ENV
- name: Invoke the URL
run: |
set -x
curl --connect-timeout 30 --retry 10 --retry-delay 6 -X POST -H "x-api-key:$TEST_API_KEY" -H "Accept:application/json" -H "Content-Type:application/json" $TEST_URL -d '{"query": "query { foo }"}'
- name: Execute test script
run: bash .github/execute-localstack-test.sh
- name: Get the LocalStack logs
if: success() || failure()
run: |
Expand Down

0 comments on commit fe79051

Please sign in to comment.