diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 6a1cf0a6..80851c01 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -26,6 +26,7 @@ on: - cron: "45 15 * * *" env: RAD_CLI_URL: https://get.radapp.dev/tools/rad/install.sh + RUN_IDENTIFIER: samplestest-${{ github.run_id }}-${{ github.run_attempt }} jobs: test: name: Sample tests @@ -39,7 +40,7 @@ jobs: app: demo path: ./demo/app.bicep args: --application demo - uiTestFile: tests/demo.app.spec.ts + uiTestFile: tests/demo/demo.app.spec.ts port: 3000 container: demo enableDapr: false @@ -62,21 +63,22 @@ jobs: runOnPullRequest: true app: eshop path: ./reference-apps/eshop/iac/eshop.bicep - args: --application eshop + args: --appName eshop uiTestFile: tests/eshop/container.app.spec.ts enableDapr: false - name: eshop-azure runOnPullRequest: false - app: eshop + app: eshop-azure path: ./reference-apps/eshop/iac/eshop.bicep - args: --application eshop -p platform=azure + args: -p platform=azure appName=eshop-azure uiTestFile: tests/eshop/container.app.spec.ts credential: azure enableDapr: false - name: eshop-aws - app: eshop + runOnPullRequest: false + app: eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws path: ./reference-apps/eshop/iac/eshop.bicep - args: --application eshop -p platform=aws + args: -p platform=aws eksClusterName=eks-samplestest-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws --appName eshop-aws-${{ github.run_id }}-${{ github.run_attempt }}-eshop-aws uiTestFile: tests/eshop/container.app.spec.ts credential: aws enableDapr: false @@ -90,9 +92,8 @@ jobs: - name: Generate output variables id: gen-id run: | - BASE_STR="SAMPLES|${GITHUB_SHA}|${GITHUB_SERVER_URL}|${GITHUB_REPOSITORY}|${GITHUB_RUN_ID}|${GITHUB_RUN_ATTEMPT}" - UNIQUE_ID=$(echo $BASE_STR | sha1sum | head -c 10) - + RUN_IDENTIFIER=${{ env.RUN_IDENTIFIER }}-${{ matrix.name }} + if [[ "${{ github.event_name }}" == "pull_request" && "${{ matrix.runOnPullRequest }}" == "false" ]]; then RUN_TEST=false else @@ -106,10 +107,9 @@ jobs: fi # Set output variables to be used in the other jobs - echo "UNIQUE_ID=${UNIQUE_ID}" >> $GITHUB_OUTPUT - echo "TEST_RESOURCE_GROUP_PREFIX=samplestest-${UNIQUE_ID}" >> $GITHUB_OUTPUT - echo "TEST_EKS_CLUSTER_NAME=samplestest-eks-${UNIQUE_ID}" >> $GITHUB_OUTPUT - echo "TEST_UNIQUE_APP_NAME=${{ matrix.name }}-${UNIQUE_ID}" >> $GITHUB_OUTPUT + echo "RUN_IDENTIFIER=${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT + echo "TEST_AZURE_RESOURCE_GROUP=rg-samplestest-${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT + echo "TEST_EKS_CLUSTER_NAME=eks-samplestest-${RUN_IDENTIFIER}" >> $GITHUB_OUTPUT echo "RUN_TEST=${RUN_TEST}" >> $GITHUB_OUTPUT echo "ENABLE_DAPR=${ENABLE_DAPR}" >> $GITHUB_OUTPUT - name: Checkout code @@ -125,7 +125,7 @@ jobs: with: node-version: 16 - name: az CLI login - if: matrix.credential == 'azure' && steps.gen-id.outputs.RUN_TEST == 'true' + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'azure' run: | az login --service-principal \ --username ${{ secrets.AZURE_SP_TESTS_APPID }} \ @@ -133,51 +133,56 @@ jobs: --tenant ${{ secrets.AZURE_SP_TESTS_TENANTID }} # Create and install test environment - name: Create Azure resource group + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'azure' id: create-azure-resource-group - if: matrix.credential == 'azure' && steps.gen-id.outputs.RUN_TEST == 'true' - env: - RESOURCE_GROUP: ${{ steps.gen-id.outputs.TEST_RESOURCE_GROUP_PREFIX }}-${{ matrix.name }} - SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} run: | current_time=$(date +%s) az group create \ --location ${{ env.AZURE_LOCATION }} \ - --name $RESOURCE_GROUP \ + --name ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} \ --subscription $SUBSCRIPTION_ID \ --tags creationTime=$current_time - while [ $(az group exists --name $RESOURCE_GROUP --subscription $SUBSCRIPTION_ID) = false ]; do - echo "Waiting for resource group $RESOURCE_GROUP to be created..." + while [ $(az group exists --name ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} --subscription ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }}) = false ]; do + echo "Waiting for resource group ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} to be created..." sleep 5 done - name: Configure AWS - if: matrix.credential == 'aws' + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'aws' run: | aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }} aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws configure set region ${{ env.AWS_REGION }} aws configure set output json - name: Create EKS Cluster + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential == 'aws' id: create-eks env: - EKS_CLUSTER_NAME: ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} - if: matrix.credential == 'aws' + EKS_CLUSTER_NAME: run: | curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp sudo mv /tmp/eksctl /usr/local/bin - eksctl create cluster --name $EKS_CLUSTER_NAME \ + eksctl create cluster --name ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} \ --nodes-min 1 --nodes-max 2 --node-type t3.large \ --managed \ --region ${{ env.AWS_REGION }} - while [[ "$(eksctl get cluster $EKS_CLUSTER_NAME --region ${{ env.AWS_REGION }} -o json | jq -r .[0].Status)" != "ACTIVE" ]]; do + while [[ "$(eksctl get cluster ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }} -o json | jq -r .[0].Status)" != "ACTIVE" ]]; do echo "Waiting for EKS cluster to be created..." sleep 60 - aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name $EKS_CLUSTER_NAME + aws eks update-kubeconfig --region ${{ env.AWS_REGION }} --name ${{ steps.gen-id.outputs.TEST_EKS_CLUSTER_NAME }} done timeout-minutes: 60 continue-on-error: false - name: Download k3d if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.credential != 'aws' 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" + - name: Install Dapr + if: steps.gen-id.outputs.RUN_TEST == 'true' && steps.gen-id.outputs.ENABLE_DAPR == '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: | @@ -194,23 +199,10 @@ jobs: break fi done - - 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" - - name: Install Dapr - if: steps.gen-id.outputs.RUN_TEST == 'true' && steps.gen-id.outputs.ENABLE_DAPR == '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: Initialize local environment if: steps.gen-id.outputs.RUN_TEST == 'true' - env: - RESOURCE_GROUP: ${{ steps.gen-id.outputs.TEST_RESOURCE_GROUP_PREFIX }}-${{ matrix.name }} - SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} run: | - rad install kubernetes --set rp.publicEndpointOverride=localhost if [[ "${{ matrix.credential }}" == "aws" ]]; then - kubectl config current-context rad install kubernetes else rad install kubernetes --set rp.publicEndpointOverride=localhost @@ -223,9 +215,13 @@ jobs: rad recipe register default -e default -w default --template-kind bicep --template-path radius.azurecr.io/recipes/dev/rediscaches:latest --link-type Applications.Datastores/redisCaches rad recipe register default -e default -w default --template-kind bicep --template-path radius.azurecr.io/recipes/dev/mongodatabases:latest --link-type Applications.Datastores/mongoDatabases if [[ "${{ matrix.credential }}" == "azure" ]]; then - rad env update default --azure-subscription-id $SUBSCRIPTION_ID --azure-resource-group $RESOURCE_GROUP + rad env update default --azure-subscription-id ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} --azure-resource-group ${{ steps.gen-id.outputs.TEST_AZURE_RESOURCE_GROUP }} rad credential register azure --client-id ${{ secrets.AZURE_SP_TESTS_APPID }} --client-secret ${{ secrets.AZURE_SP_TESTS_PASSWORD }} --tenant-id ${{ secrets.AZURE_SP_TESTS_TENANTID }} fi + if [[ "${{ matrix.credential }}" == "aws" ]]; then + rad env update default --aws-region ${{ env.AWS_REGION }} --aws-account-id ${{ secrets.AWS_ACCOUNT_ID }} + rad credential register aws --access-key-id ${{ secrets.AWS_ACCOUNT_ID }} --secret-access-key ${{ secrets.AWS_SECRET_ACCESS_KEY }} + fi # Deploy application and run tests - name: Deploy app if: steps.gen-id.outputs.RUN_TEST == 'true' @@ -237,8 +233,8 @@ jobs: label="radius.dev/application=${{ matrix.app }}" kubectl wait --for=condition=Ready pod -l $label -n $namespace --timeout=5m - name: Run Playwright Test + if: steps.gen-id.outputs.RUN_TEST == 'true' && matrix.uiTestFile != '' id: run-playwright-test - if: matrix.uiTestFile != '' && steps.gen-id.outputs.RUN_TEST == 'true' run: | if [[ "${{ matrix.container }}" != "" ]]; then rad resource expose containers ${{ matrix.container }} ${{ matrix.args }} --port ${{ matrix.port }} & @@ -246,17 +242,11 @@ jobs: cd ui-tests/ npm ci npx playwright install --with-deps - app_name=${{ matrix.app }} - if [[ "${{ matrix.credential }}" == "aws" ]]; then - app_name=$UNIQUE_APP_NAME - fi if [[ "${{ matrix.app }}" == "eshop" ]]; then - endpoint="$(rad app status -a $app_name | sed 's/ /\n/g' | grep http)" + endpoint="$(rad app status -a ${{ matrix.app }} | sed 's/ /\n/g' | grep http)" echo $endpoint - ENDPOINT=$endpoint npx playwright test ${{ matrix.uiTestFile }} --retries 3 - else - npx playwright test ${{ matrix.uiTestFile }} --retries 3 - fi + ENDPOINT=$endpoint + npx playwright test ${{ matrix.uiTestFile }} --retries 3 - name: Upload Playwright Results uses: actions/upload-artifact@v3 if: always() && ( steps.run-playwright-test.outcome == 'success' || steps.run-playwright-test.outcome == 'failure' ) @@ -269,17 +259,15 @@ jobs: - name: Get Pod logs for failed tests id: get-pod-logs if: failure() && steps.run-playwright-test.outcome == 'failure' - env: - UNIQUE_APP_NAME: ${{ steps.gen-id.outputs.TEST_UNIQUE_APP_NAME }} run: | # Create pod-logs directory mkdir -p ui-tests/pod-logs/${{ matrix.name }} # Get pod logs and save to file - namespace="default-$UNIQUE_APP_NAME" - label="radius.dev/application=$UNIQUE_APP_NAME + namespace="default-${{ matrix.app }}" + label="radius.dev/application=${{ matrix.app }}" if [[ "${{ matrix.credential }}" == "aws" ]]; then - namespace="default-$UNIQUE_APP_NAME" - label="radius.dev/application=$UNIQUE_APP_NAME" + namespace="default-${{ matrix.app }}"" + label="radius.dev/application=${{ matrix.app }}" fi pod_names=($(kubectl get pods -l $label -n $namespace -o jsonpath='{.items[*].metadata.name}')) for pod_name in "${pod_names[@]}"; do @@ -301,22 +289,16 @@ jobs: run: gh issue create --title "Samples deployment failed for ${{ matrix.app }}" --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." --repo ${{ github.repository }} # Cleanup - name: Delete app - env: - UNIQUE_APP_NAME: ${{ steps.gen-id.outputs.TEST_UNIQUE_APP_NAME }} if: steps.gen-id.outputs.RUN_TEST == 'true' run: | - app_name=${{ matrix.app }} - if [[ "${{ matrix.credential }}" == "aws" ]]; then - app_name=$UNIQUE_APP_NAME - fi - rad app delete $app_name -y + rad app delete -y - name: Delete Azure resource group if: always() && steps.create-azure-resource-group.outcome == 'success' env: RESOURCE_GROUP: ${{ steps.gen-id.outputs.TEST_RESOURCE_GROUP_PREFIX }}-${{ matrix.name }} SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTIONID_TESTS }} run: | - # if deletion fails, purge workflow will purge the resource group and its resources later. + # if deletion fails, purge workflow will purge the resource group and its resources later az group delete \ --subscription $SUBSCRIPTION_ID \ --name $RESOURCE_GROUP \ @@ -334,7 +316,8 @@ jobs: - name: Delete AWS Resources if: always() && matrix.credential == 'aws' run: | - ./.github/scripts/delete-aws-resources.sh ${{ steps.gen-id.outputs.TEST_UNIQUE_APP_NAME }} + # if deletion fails, purge workflow will purge the resource group and its resources later + ./.github/scripts/delete-aws-resources.sh ${{ matrix.app }} - name: Create GitHub issue on failure - if: failure() && github.event_name != 'pull_request' + if: failure() && github.event_name != 'pull_request' && github.event_name != 'workflow_dispatch' run: gh issue create --title "Samples deployment failed for ${{ matrix.app }}" --body "Test failed on ${{ github.repository }}. See [workflow logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for more details." --repo ${{ github.repository }} diff --git a/ui-tests/tests/demo.app.spec.ts b/ui-tests/tests/demo/demo.app.spec.ts similarity index 100% rename from ui-tests/tests/demo.app.spec.ts rename to ui-tests/tests/demo/demo.app.spec.ts