Skip to content

Commit

Permalink
API Tests Example + GHA (#191)
Browse files Browse the repository at this point in the history
* add mocha tests

* add github action to run tests

* test GHA

* npm install

* npm don't fail test

* change to use branch tag for PR

* fix creds

* fix naming

* adding for all services

* add other GHAs

* test change for FE

* fix naming

* should fail test

* hide API key printing

* revert changes to services

* fix names of sandboxes
  • Loading branch information
foxish authored Nov 2, 2023
1 parent 5600d11 commit 340520e
Show file tree
Hide file tree
Showing 9 changed files with 2,606 additions and 16 deletions.
131 changes: 120 additions & 11 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,67 @@ jobs:
args: release --rm-dist
env:
GIT_SHA: ${{ github.sha }}

sandbox-route:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.route == 'true' }}
needs: [ build, changes ]
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

cli-sandbox:
- name: Create Sandbox
id: create-sandbox
env:
SIGNADOT_ORG: signadot
SIGNADOT_API_KEY: ${{ secrets.SIGNADOT_API_KEY }}
IMAGE_TAG: ${{ github.sha }}
run: |
# run the cli
# setting the gitsha to a short version to respect the name
# limit (30 chars)
docker run -i \
-e SIGNADOT_ORG=${SIGNADOT_ORG} \
-e SIGNADOT_API_KEY=${SIGNADOT_API_KEY} \
signadot/signadot-cli \
/signadot sandbox apply \
--set github-pr=${{ github.event.number }} \
--set image=signadot/hotrod:${IMAGE_TAG} \
--set git-branch=pr-${{ github.event.number }}-route \
-f - \
-o yaml \
< ${GITHUB_WORKSPACE}/.signadot/route-template.yaml \
> ${GITHUB_WORKSPACE}/.signadot/sbx-response.yaml
- name: Test Sandbox
run: |
sleep 20 # just to make sure our sandbox is ready.
go install github.com/mikefarah/yq/v4@latest
endpoint=$(yq '.endpoints[0].url' ${GITHUB_WORKSPACE}/.signadot/sbx-response.yaml)
pushd .
cd test
npm install
# don't exit with error code if test fails and fail action.
ENDPOINT=$endpoint SIGNADOT_API_KEY=${{ secrets.SIGNADOT_API_KEY }} npm test || true
popd
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/composite@v2
with:
files: |
test/*.xml
sandbox-frontend:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.frontend == 'true' }}
needs: [ build, changes ]
steps:
- uses: actions/checkout@v3
Expand All @@ -129,29 +186,81 @@ jobs:
-e SIGNADOT_API_KEY=${SIGNADOT_API_KEY} \
signadot/signadot-cli \
/signadot sandbox apply \
--set github-pr=${{ github.event.number }} \
--set image=signadot/hotrod:${IMAGE_TAG} \
--set git-short-commit=${IMAGE_TAG:0:6} \
--set git-branch=pr-${{ github.event.number }}-frontend \
-f - \
-o yaml \
< ${GITHUB_WORKSPACE}/.signadot/frontend-template.yaml \
> ${GITHUB_WORKSPACE}/.signadot/frontend-response.yaml
> ${GITHUB_WORKSPACE}/.signadot/sbx-response.yaml
- name: Test Sandbox
sandbox-customer:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.customer == 'true' }}
needs: [ build, changes ]
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Create Sandbox
id: create-sandbox
env:
SIGNADOT_ORG: signadot
SIGNADOT_API_KEY: ${{ secrets.SIGNADOT_API_KEY }}
IMAGE_TAG: ${{ github.sha }}
run: |
go install github.com/mikefarah/yq/v4@latest
endpoint=$(yq '.endpoints[0].url' ${GITHUB_WORKSPACE}/.signadot/frontend-response.yaml)
curl -H "signadot-api-key: ${{ secrets.SIGNADOT_API_KEY }}" $endpoint
# run the cli
# setting the gitsha to a short version to respect the name
# limit (30 chars)
docker run -i \
-e SIGNADOT_ORG=${SIGNADOT_ORG} \
-e SIGNADOT_API_KEY=${SIGNADOT_API_KEY} \
signadot/signadot-cli \
/signadot sandbox apply \
--set github-pr=${{ github.event.number }} \
--set image=signadot/hotrod:${IMAGE_TAG} \
--set git-branch=pr-${{ github.event.number }}-customer \
-f - \
-o yaml \
< ${GITHUB_WORKSPACE}/.signadot/customer-template.yaml \
> ${GITHUB_WORKSPACE}/.signadot/sbx-response.yaml
- name: Delete Sandbox
if: steps.create-sandbox.outcome == 'success'
sandbox-driver:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && needs.changes.outputs.driver == 'true' }}
needs: [ build, changes ]
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}

- name: Create Sandbox
id: create-sandbox
env:
SIGNADOT_ORG: signadot
SIGNADOT_API_KEY: ${{ secrets.SIGNADOT_API_KEY }}
IMAGE_TAG: ${{ github.sha }}
run: |
# run the cli
# setting the gitsha to a short version to respect the name
# limit (30 chars)
docker run -i \
-e SIGNADOT_ORG=${SIGNADOT_ORG} \
-e SIGNADOT_API_KEY=${SIGNADOT_API_KEY} \
signadot/signadot-cli \
/signadot sandbox delete \
/signadot sandbox apply \
--set github-pr=${{ github.event.number }} \
--set image=signadot/hotrod:${IMAGE_TAG} \
--set git-branch=pr-${{ github.event.number }}-driver \
-f - \
< ${GITHUB_WORKSPACE}/.signadot/frontend-response.yaml
-o yaml \
< ${GITHUB_WORKSPACE}/.signadot/driver-template.yaml \
> ${GITHUB_WORKSPACE}/.signadot/sbx-response.yaml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
/hotrod
/dist/
node_modules/
22 changes: 22 additions & 0 deletions .signadot/customer-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "@{git-branch}"
spec:
description: sandbox for customer service
cluster: demo
labels:
signadot/github-repo: "signadot/hotrod"
signadot/github-pull-request: "@{github-pr}"
forks:
- forkOf:
kind: Deployment
name: customer
namespace: hotrod
customizations:
images:
- container: hotrod
image: "@{image}"
defaultRouteGroup:
endpoints:
- name: route-endpoint
target: http://route.hotrod.svc:8081
- name: frontend-endpoint
target: http://frontend.hotrod.svc:8080
22 changes: 22 additions & 0 deletions .signadot/driver-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "@{git-branch}"
spec:
description: sandbox for driver service
cluster: demo
labels:
signadot/github-repo: "signadot/hotrod"
signadot/github-pull-request: "@{github-pr}"
forks:
- forkOf:
kind: Deployment
name: driver
namespace: hotrod
customizations:
images:
- container: hotrod
image: "@{image}"
defaultRouteGroup:
endpoints:
- name: driver-endpoint
target: grpc://driver.hotrod.svc:8082
- name: frontend-endpoint
target: http://frontend.hotrod.svc:8080
13 changes: 8 additions & 5 deletions .signadot/frontend-template.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: "hotrod-cli-@{git-short-commit}"
name: "@{git-branch}"
spec:
description: sandbox generated from signadot cli in GHA.
description: sandbox for frontend service
cluster: demo
labels:
signadot/github-repo: "signadot/hotrod"
signadot/github-pull-request: "@{github-pr}"
forks:
- forkOf:
kind: Deployment
Expand All @@ -11,7 +14,7 @@ spec:
images:
- container: hotrod
image: "@{image}"
defaultRouteGroup:
endpoints:
- name: frontend
port: 8080
protocol: http
- name: frontend-endpoint
target: http://frontend.hotrod.svc:8080
22 changes: 22 additions & 0 deletions .signadot/route-template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: "@{git-branch}"
spec:
description: sandbox for route service
cluster: demo
labels:
signadot/github-repo: "signadot/hotrod"
signadot/github-pull-request: "@{github-pr}"
forks:
- forkOf:
kind: Deployment
name: route
namespace: hotrod
customizations:
images:
- container: hotrod
image: "@{image}"
defaultRouteGroup:
endpoints:
- name: route-endpoint
target: http://route.hotrod.svc:8083
- name: frontend-endpoint
target: http://frontend.hotrod.svc:8080
Loading

0 comments on commit 340520e

Please sign in to comment.