Skip to content

feat: use master branch for local env #23

feat: use master branch for local env

feat: use master branch for local env #23

name: E2E Tests
on:
push:
branches:
- feature/*
jobs:
# this is needed to wait for the new docker image to be build and published to the registry
# so that we can use the image to run ui of the needed commit related version as part of local-env
# the idea is taken from here https://stackoverflow.com/a/71489231
push_to_registry:
uses: ./.github/workflows/docker-build-and-push.yml
# without this it cannot login to the registry
secrets: inherit
e2e-test-without-local-env:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Run service via docker-compose and run Karate-tests
# Hide credentials and token from logs, get the number of failed and passed tests
# Find text with 'failed' and 'passed' in logs from karate-testing container
run: |
LOGS=$(docker compose --profile MockForPullRequest up --abort-on-container-exit)
FILTERED_LOGS=$(echo "$LOGS" | sed -E 's/"login":"[^"]*"/"login":"****"/g' \
| sed -E 's/"password":"[^"]*"/"password":"****"/g' \
| sed -E 's/"accessToken":[^,}]*"[^"]*"/"accessToken":"****"/g' \
| sed -E 's/"Authorization":"[^"]*"/"Authorization":"****"/g' \
| sed -E 's/"X-DEBUG-TOKEN":[^,}]*"[^"]*"/"X-DEBUG-TOKEN":"****"/g' \
| sed -E 's/accessToken":\{[^}]*\}/accessToken":{"value":"****"}/g' \
| sed -E 's/X-DEBUG-TOKEN: [^ ]*/X-DEBUG-TOKEN: ****/g')
echo "$FILTERED_LOGS"
FAILED=$(echo "$FILTERED_LOGS" | grep -oP 'failed: *\K\d+')
PASSED=$(echo "$FILTERED_LOGS" | grep -oP 'passed: *\K\d+')
echo "Failed tests: $FAILED"
echo "Passed tests: $PASSED"
if [ "$FAILED" -gt 0 ]; then
echo "Failed tests found! Failing the pipeline..."
exit 1
fi
if [ "$PASSED" -eq 0 ]; then
echo "No tests passed! Failing the pipeline..."
exit 1
fi
env:
TEST_AUTH_LOGIN: ${{ secrets.TEST_AUTH_LOGIN }}
TEST_AUTH_PASSWORD: ${{ secrets.TEST_AUTH_PASSWORD }}
e2e-test-with-local-env:
name: Run karate tests in local env
runs-on: ubuntu-22.04
# needs: [push_to_registry]
steps:
- name: Checkout local-env
uses: actions/checkout@v4
with:
repository: TourmalineCore/inner-circle-local-env
- name: cat values
run: cat deploy/values-auth-api.yaml.gotmpl
- name: Deploy Local Env to Kind k8s
uses: devcontainers/ci@v0.3
continue-on-error: true
with:
runCmd: |
# we need to override "latest" image tag of ui inside local-env to run e2e against the current commit ui version and not against latest from master
# We tried to use yq to change the image tag, but in the values files for helmfile we have non-yaml code that yq can`t parse or ignore
# so for that reason we use Stream EDitor which can find needed string using regular expressions and change it to a new value
# The -i flag is needed to write new image tag directly to values file
sed -i "0,/tag:.*/s//tag: \"sha-00f97f61067977dcfd1e44df39365684f61bdbfa\"/" deploy/values-auth-api.yaml.gotmpl
# we need to override "latest" ref of service chart inside local-env to run tests against the current commit service chart version and not against latest from master
sed -i "0,/git+https:\/\/github.com\/TourmalineCore\/${{ github.event.repository.name }}.git?ref=.*/s//git+https:\/\/github.com\/TourmalineCore\/${{ github.event.repository.name }}.git?ref=${{ github.sha }}/" deploy/helmfile.yaml
sed -i "0,/git::https:\/\/github.com\/TourmalineCore\/${{ github.event.repository.name }}.git@\/Api\/ci\/values-local-env.yaml?ref=.*/s//git::https:\/\/github.com\/TourmalineCore\/${{ github.event.repository.name }}.git@\/Api\/ci\/values-local-env.yaml?ref=${{ github.sha }}/" deploy/helmfile.yaml
kind create cluster --name inner-circle --config kind-local-config.yaml --kubeconfig ./.inner-circle-cluster-kubeconfig
# we need to properly expose KUBECONFIG as an absolute path, pwd prints current working directory path
export KUBECONFIG=$(pwd)/.inner-circle-cluster-kubeconfig
helmfile --environment local --namespace local -f deploy/helmfile.yaml apply
kubectl logs $(kubectl get pods -l app.kubernetes.io/instance=auth-api -n local -o jsonpath='{.items[0].metadata.name}') -n local
push: never
- name: cat values
run: cat deploy/values-auth-api.yaml.gotmpl
- name: Checkout api
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Download Karate JAR
run: |
curl -L https://github.com/karatelabs/karate/releases/download/v1.5.1/karate-1.5.1.jar -o karate.jar
- name: Run Karate Tests
run: |
java -jar karate.jar .
env:
API_ROOT_URL: "http://localhost:30090/api"
AUTH_LOGIN: "ceo@tourmalinecore.com"
AUTH_PASSWORD: "cEoPa$$wo1d"