Skip to content

Adding test workflow #44

Adding test workflow

Adding test workflow #44

Workflow file for this run

name: Test Recipes
on:
workflow_dispatch:
inputs:
version:
description: 'Radius version number to use (e.g. 0.1.0, 0.1.0-rc1, edge). Defaults to edge.'
required: false
default: 'edge'
type: string
push:
branches:
- v*.*
- edge
paths:
- "local-dev/**"
- ".github/workflows/**"
pull_request:
types: [opened, synchronize, reopened]
env:
RUN_IDENTIFIER: recipestest-${{ github.run_id }}-${{ github.run_attempt }}
jobs:
test:
name: "Recipe tests"
runs-on: [ubuntu-latest]
strategy:
fail-fast: false
matrix:
include:
- name: mongodatabases
app: dsrp-resources-mongodb-recipe
namespace: dsrp-resources-mongodb-recipe-app
path: ./tests/mongodatabases.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
- name: sqldatabases
app: dsrp-resources-sqldb-recipe
namespace: dsrp-resources-sqldb-recipe-app
path: ./tests/sqldatabases.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
- name: rediscaches
app: dsrp-resources-redis-recipe
namespace: dsrp-resources-redis-recipe-app
path: ./tests/rediscaches.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
- name: rabbitmqqueues
app: msgrp-resources-rabbitmq-recipe
namespace: msgrp-resources-rabbitmq-default-recipe-app
path: ./tests/rabbitmqqueues.bicep
args: --parameters magpieimage="radiusdev.azurecr.io/magpiego:latest"
- name: secretstores
app: daprrp-rs-secretstore-recipe
namespace: daprrp-rs-secretstore-recipe
path: ./tests/secretstores.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
- name: statestores
app: daprrp-rs-sts-recipe
namespace: daprrp-rs-sts-recipe
path: ./tests/statestores.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
- name: pubsubbrokers
app: dpsb-recipe-app
namespace: dpsb-recipe-app
path: ./tests/pubsubbrokers.bicep
args: --parameters magpieimage="reciperegistry:5000/magpiego:latest"
steps:
- name: Generate output variables
id: gen-id
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
RUN_TEST=true
else
RUN_TEST=true
fi
# Set output variables to be used in the other jobs
echo "RUN_IDENTIFIER=${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT
echo "RUN_TEST=${RUN_TEST}" >> $GITHUB_OUTPUT
- name: Checkout code
if: steps.gen-id.outputs.RUN_TEST == 'true'
uses: actions/checkout@v3
- name: Setup Node
if: steps.gen-id.outputs.RUN_TEST == 'true'
uses: actions/setup-node@v3
with:
node-version: 16
- name: Download k3d
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: wget -q -O - https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
- name: Create k3d cluster
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: k3d cluster create --agents 2 -p "80:80@loadbalancer" --k3s-arg "--disable=traefik@server:0" --registry-create reciperegistry:51351
- name: Install Dapr
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
helm repo add dapr https://dapr.github.io/helm-charts/
helm install dapr dapr/dapr --version=1.6 --namespace dapr-system --create-namespace --wait
- name: Download rad CLI
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
RADIUS_VERSION="${{ inputs.version }}"
if [[ -z "${{ inputs.version }}" ]]; then
RADIUS_VERSION=edge
fi
chmod +x ./.github/scripts/install-radius.sh
./.github/scripts/install-radius.sh $RADIUS_VERSION
- name: Publish Recipes
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
files_list=$(ls "local-dev")
for file in $files_list; do
echo "Publishing recipe: local-dev/$file"
recipeName="${file%.*}"
rad bicep publish --file local-dev/$file --target br:localhost:51351/recipes/local-dev/$recipeName:latest --plain-http
done
- name: Initialize default environment
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
rad install kubernetes --set rp.publicEndpointOverride=localhost
rad group create default
rad workspace create kubernetes default --group default
rad group switch default
rad env create default
rad env switch default
- name: Build Magpie image
if: steps.gen-id.outputs.RUN_TEST == 'true'
run: |
pushd tests/magpiego
docker build -t magpiego .
docker tag magpiego:latest localhost:51351/magpiego:latest
docker push localhost:51351/magpiego:latest
popd
- name: Deploy app
if: steps.gen-id.outputs.RUN_TEST == 'true'
id: deploy-app
run: rad deploy ${{ matrix.path }} ${{ matrix.args }}
- name: Wait for all pods to be ready
if: steps.gen-id.outputs.RUN_TEST == 'true'
id: wait-for-pods
run: |
label="radapp.io/application=${{ matrix.app }}"
kubectl wait --for=condition=Ready pod -l $label -n ${{ matrix.namespace }} --timeout=5m
- name: Get Pod logs for failed tests
id: get-pod-logs
if: failure() && (steps.deploy-app.outcome == 'failure' || steps.wait-for-pods.outcome == 'failure')
run: |
# Create pod-logs directory
mkdir -p recipe-tests/pod-logs/${{ matrix.name }}
# Get pod logs and save to file
label="radapp.io/application=${{ matrix.app }}"
pod_names=($(kubectl get pods -l $label -n ${{ matrix.namespace }} -o jsonpath='{.items[*].metadata.name}'))
for pod_name in "${pod_names[@]}"; do
kubectl logs $pod_name -n $namespace > recipe-tests/pod-logs/${{ matrix.name }}/${pod_name}.txt
done
echo "Pod logs saved to recipe-tests/pod-logs/${{ matrix.name }}/"
# Get kubernetes events and save to file
kubectl get events -n ${{ matrix.namespace }} > recipe-tests/pod-logs/${{ matrix.name }}/events.txt
- name: Upload Pod logs for failed tests
uses: actions/upload-artifact@v3
if: failure() && steps.get-pod-logs.outcome == 'success'
with:
name: ${{ matrix.name }}-pod-logs
path: recipe-tests/pod-logs/${{ matrix.name }}
retention-days: 30
if-no-files-found: error