Skip to content

Commit

Permalink
chore(ci): load tests (#1793)
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekRoberts authored Feb 8, 2024
1 parent 4eef8d3 commit 885d71a
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/.deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
description: Autoscaling enabled or not for the deployments
required: false
type: string
default: true
default: false
environment:
description: Environment name; omit for PRs
required: false
Expand Down
40 changes: 28 additions & 12 deletions .github/workflows/.tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ name: .Tests
on:
workflow_call:
inputs:
### Required
### Typical / recommended
target:
description: PR number, test or prod
required: true
type: string
default: test

env:
DOMAIN: apps.silver.devops.gov.bc.ca
PREFIX: ${{ github.event.repository.name }}-${{ inputs.target }}

jobs:
integration-tests:
name: Integration Tests
name: Integration
runs-on: ubuntu-22.04
timeout-minutes: 1
steps:
Expand All @@ -26,21 +31,17 @@ jobs:
${{ runner.os }}-build-
${{ runner.os }}-
- name: Integration tests
env:
- env:
API_NAME: nest
BASE_URL: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca
BASE_URL: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.${{ env.DOMAIN }}
run: |
cd integration-tests
npm ci
node src/main.js
cypress-e2e:
name: E2E Tests
cypress-e2e-tests:
name: E2E
runs-on: ubuntu-22.04
defaults:
run:
working-directory: frontend
strategy:
matrix:
browser: [chrome, firefox, edge]
Expand All @@ -58,9 +59,8 @@ jobs:
${{ runner.os }}-
- uses: cypress-io/github-action@v6
name: Cypress run
env:
CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.apps.silver.devops.gov.bc.ca/
CYPRESS_baseUrl: https://${{ github.event.repository.name }}-${{ inputs.target }}-frontend.${{ env.DOMAIN }}/
with:
config: pageLoadTimeout=10000
working-directory: ./frontend
Expand All @@ -72,3 +72,19 @@ jobs:
name: cypress-screenshots
path: ./cypress/screenshots
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn`

load-tests:
runs-on: ubuntu-latest
name: Load
strategy:
matrix:
name: [backend, frontend]
steps:
- uses: actions/checkout@v4
- uses: grafana/k6-action@v0.3.1
env:
BACKEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}/api
FRONTEND_URL: https://${{ env.PREFIX }}-frontend.${{ env.DOMAIN }}
with:
filename: ./load-test/${{ matrix.name }}-test.js
flags: --vus 10 --duration 30s
42 changes: 0 additions & 42 deletions .github/workflows/load-test.yml

This file was deleted.

17 changes: 8 additions & 9 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ on:
- '*.md'
- '.github/**'
- '.graphics/**'
- '!.github/workflows/.deploy.yml'
- '!.github/workflows/merge.yml'
- '!.github/workflows/**'
workflow_dispatch:
inputs:
pr_no:
Expand All @@ -35,28 +34,28 @@ jobs:
uses: ./.github/workflows/.deploy.yml
secrets: inherit
with:
autoscaling: false
environment: test
tag: ${{ needs.vars.outputs.pr }}
release: test

integration-e2e:
name: Integration and E2E Tests
tests:
name: Tests
needs: [deploy-test, vars]
uses: ./.github/workflows/.tests.yml
with:
target: test

deploy-prod:
name: Deploy (prod)
needs: [integration-e2e, vars]
needs: [tests, vars]
uses: ./.github/workflows/.deploy.yml
secrets: inherit
with:
autoscaling: true
environment: prod
tag: ${{ needs.vars.outputs.pr }}
release: prod
params: --set backend.deploymentStrategy.type=RollingUpdate --set frontend.deploymentStrategy.type=RollingUpdate
params:
--set backend.deploymentStrategy.type=RollingUpdate
--set frontend.deploymentStrategy.type=RollingUpdate

promote:
name: Promote Images
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/pr-open.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
uses: ./.github/workflows/.deploy.yml
secrets: inherit
with:
autoscaling: false
tag: ${{ github.event.number }}
release: ${{ github.event.number }}
triggers: ('backend/' 'frontend/' 'migrations/' 'charts/')
110 changes: 57 additions & 53 deletions .github/workflows/scheduled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,45 @@ concurrency:
cancel-in-progress: true

jobs:
zap_scan:
runs-on: ubuntu-latest
name: Penetration Tests
ageOutPRs:
name: PR Env Purge
env:
DOMAIN: apps.silver.devops.gov.bc.ca
PREFIX: ${{ github.event.repository.name }}-test
strategy:
matrix:
name: [backend, frontend]
# https://tecadmin.net/getting-yesterdays-date-in-bash/
CUTOFF: "1 week ago"
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: ZAP Scan
uses: zaproxy/action-full-scan@v0.9.0
with:
allow_issue_writing: true
artifact_name: "zap_${{ matrix.name }}"
cmd_options: "-a"
issue_title: "ZAP: ${{ matrix.name }}"
target: https://${{ env.PREFIX }}-${{ matrix.name }}.${{ env.DOMAIN }}
- name: Clean up Helm Releases
run: |
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }}
oc project ${{ vars.OC_NAMESPACE }} # Safeguard!
# Catch errors, unset variables, and pipe failures (e.g. grep || true )
set -euo pipefail
# Echos
echo "Delete stale Helm releases"
echo "Cutoff: ${{ env.CUTOFF }}"
# Before date, list of releases
BEFORE=$(date +%s -d "${{ env.CUTOFF }}")
RELEASES=$(helm ls -aq | grep ${{ github.event.repository.name }} || :)
# If releases, then iterate
[ -z "${RELEASES}" ]|| for r in ${RELEASES[@]}; do
# Get last update and convert the date
UPDATED=$(date "+%s" -d <<< echo $(helm status $r -o json | jq -r .info.last_deployed))
# Compare to cutoff and delete as necessary
if [[ ${UPDATED} < ${BEFORE} ]]; then
echo -e "\nOlder than cutoff: ${r}"
helm uninstall --no-hooks ${r}
else
echo -e "\nNewer than cutoff: ${r}"
echo "No need to delete"
fi
done
generate-schema-spy:
name: Generate SchemaSpy Documentation
Expand Down Expand Up @@ -71,42 +92,25 @@ jobs:
folder: output
target-folder: schemaspy

ageOutPRs:
name: PR Env Purge
env:
# https://tecadmin.net/getting-yesterdays-date-in-bash/
CUTOFF: "1 week ago"
tests:
name: Tests
uses: ./.github/workflows/.tests.yml

zap_scan:
runs-on: ubuntu-latest
timeout-minutes: 10
name: Penetration Tests
env:
DOMAIN: apps.silver.devops.gov.bc.ca
PREFIX: ${{ github.event.repository.name }}-test
strategy:
matrix:
name: [backend, frontend]
steps:
- name: Clean up Helm Releases
run: |
oc login --token=${{ secrets.OC_TOKEN }} --server=${{ vars.OC_SERVER }}
oc project ${{ vars.OC_NAMESPACE }} # Safeguard!
# Catch errors, unset variables, and pipe failures (e.g. grep || true )
set -euo pipefail
# Echos
echo "Delete stale Helm releases"
echo "Cutoff: ${{ env.CUTOFF }}"
# Before date, list of releases
BEFORE=$(date +%s -d "${{ env.CUTOFF }}")
RELEASES=$(helm ls -aq | grep ${{ github.event.repository.name }} || :)
# If releases, then iterate
[ -z "${RELEASES}" ]|| for r in ${RELEASES[@]}; do
# Get last update and convert the date
UPDATED=$(date "+%s" -d <<< echo $(helm status $r -o json | jq -r .info.last_deployed))
# Compare to cutoff and delete as necessary
if [[ ${UPDATED} < ${BEFORE} ]]; then
echo -e "\nOlder than cutoff: ${r}"
helm uninstall --no-hooks ${r}
else
echo -e "\nNewer than cutoff: ${r}"
echo "No need to delete"
fi
done
- name: ZAP Scan
uses: zaproxy/action-full-scan@v0.9.0
with:
allow_issue_writing: true
artifact_name: "zap_${{ matrix.name }}"
cmd_options: "-a"
issue_title: "ZAP: ${{ matrix.name }}"
target: https://${{ env.PREFIX }}-${{ matrix.name }}.${{ env.DOMAIN }}

0 comments on commit 885d71a

Please sign in to comment.