Tests In Browser|API|Marketplace #258
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build and run In Browser Selenium Web Driver Tests | |
# | |
# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples | |
name: Test|In Browser|Marketplace | |
on: | |
#manually trigger deploy | |
workflow_dispatch: | |
# Trigger the workflow on push | |
#push: | |
# branches: | |
# - develop | |
# - main | |
#pull_request: | |
# branches: | |
# - develop | |
# - main | |
env: | |
# Hides some of the differences between running in a Github action and running | |
# in nektos/act on Microsoft Windows with Docker Desktop | |
ONGITHUB: true | |
# Main project path | |
MARKETPLACE_PROJECT_DIRECTORY: './api/CESMII.Marketplace.API/' | |
# Main project file name | |
MARKETPLACE_PROJECT_FILE: 'CESMII.Marketplace.API.csproj' | |
# Main project fqn | |
MARKETPLACE_PROJECT_FQDN: './api/CESMII.Marketplace.API/CESMII.Marketplace.API.csproj' | |
# Paths to Test 1 (In Browser) | |
TEST1_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.InBrowser/' | |
TEST1_PROJECT_FILE: 'CESMII.Marketplace.InBrowser.Tests.csproj' | |
TEST1_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.InBrowser/CESMII.Marketplace.InBrowser.Tests.csproj' | |
TEST1_PROJECT_DLL: 'CESMII.Marketplace.InBrowser.Tests.dll' | |
# Paths to Test 2 (MongoDB) | |
TEST2_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.MongoDB/' | |
TEST2_PROJECT_FILE: 'CESMII.Marketplace.Tests.MongoDB.csproj' | |
TEST2_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.MongoDB/CESMII.Marketplace.Tests.MongoDB.csproj' | |
TEST2_PROJECT_ABSOLUTE: '/src/api/Tests/CESMII.Marketplace.Tests.MongoDB/CESMII.Marketplace.Tests.MongoDB.csproj' | |
TEST2_PROJECT_DLL: 'CESMII.Marketplace.Tests.MongoDB.dll' | |
# Paths to Test 3 (RestApi) | |
TEST3_PROJECT_DIRECTORY: './api/Tests/CESMII.Marketplace.Tests.RestApi/' | |
TEST3_PROJECT_FILE: 'CESMII.Marketplace.Tests.RestApi.csproj' | |
TEST3_PROJECT_FQDN: './api/Tests/CESMII.Marketplace.Tests.RestApi/CESMII.Marketplace.Tests.RestApi.csproj' | |
TEST3_PROJECT_ABSOLUTE: '/src/api/Tests/CESMII.Marketplace.Tests.RestApi/CESMII.Marketplace.Tests.RestApi.csproj' | |
TEST3_PROJECT_DLL: 'CESMII.Marketplace.Tests.RestApi.dll' | |
# set this to the .NET core version to use | |
NETCORE_VERSION: "6.0.x" | |
# set this to the NODE JS version to use | |
NODEJS_VERSION: "16.17.0" | |
# set this to npm working directory | |
NPM_WORKING_DIRECTORY: 'frontend' | |
# Access to our MongoDB | |
MONGODB_DATABASE_NAME: "test" | |
MONGODB_LOCAL_CONNECTION: "mongodb://testuser:password@localhost:27017" | |
MONGODB_SECUR_CONNECTION: "mongodb://testuser:password@MyMongoDB:27017?ssl=true" | |
MOUNT_SOURCE_GITHUB: '/home/runner/work/Marketplace/Marketplace/mongo-data' | |
MOUNT_SOURCE_DESKTOP: 'c:/CESMII.github/Marketplace/mongo-data' | |
#VOLUME_APP: '/home/runner/work/Marketplace/Marketplace/api/CESMII.Marketplace.API:/app' | |
#VOLUME_APP: './api/CESMII.Marketplace.API:/app' | |
#VOLUME_APP: 'C:/CESMII.github/Marketplace/api/CESMII.Marketplace.API:/app' | |
#VOLUME_SRC: '/home/runner/work/Marketplace/Marketplace:/src' | |
#VOLUME_SRC: './:/src' | |
#VOLUME_SRC: 'C:/CESMII.github/Marketplace:/src' | |
#DOCKER_VOLUME_PUBLISH: '/home/runner/work/Marketplace/Marketplace/publish:/publish' | |
#DOCKER_VOLUME_PUBLISH: './publish:/publish' | |
#DOCKER_VOLUME_PUBLISH: '/mnt/c/CESMII.github/Marketplace/publish:/publish' | |
#DOCKER_FILE_MARKETPLACE: '/home/runner/work/Marketplace/Marketplace/Dockerfile' | |
#DOCKER_FILE_MARKETPLACE: './api/CESMII.Marketplace.API/Dockerfile' | |
#DOCKER_FILE_MARKETPLACE: '/mnt/c/CESMII.github/Marketplace/api/CESMII.Marketplace.API/Dockerfile' | |
jobs: | |
runner-job: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 1__Marketplace API - Check out the repo | |
uses: actions/checkout@v3 | |
with: | |
submodules: true | |
# Create bridge network for communication between containers | |
- name: 2__Docker - Set up networking | |
run: | | |
docker network remove --force mysubnet1 ; | |
docker network create mysubnet1 ; | |
# Initialize a Mongo DB database (on Github) | |
# Note: the "env" section seems not to work and so the -e switches are necessary | |
- name: 3__MongoDB - Create MongoDB Docker container (On Github) | |
if: env.ONGITHUB == 'true' | |
run: docker run -d -p 27017:27017 --name=MyMongoDB --network mysubnet1 -e MONGO_INIT_DATABASE=test -e MONGO_INITDB_ROOT_USERNAME=testuser -e MONGO_INITDB_ROOT_PASSWORD=password --mount src="${{env.MOUNT_SOURCE_GITHUB}}",target=/data,type=bind mongo:6.0 | |
env: | |
MONGO_INIT_DATABASE: test | |
MONGO_INITDB_ROOT_USERNAME: testuser | |
MONGO_INITDB_ROOT_PASSWORD: password | |
# Initialize a Mongo DB database (on the Desktop) | |
- name: 3__MongoDB - Create MongoDB Docker container (On Desktop) | |
if: env.ONGITHUB == 'false' | |
run: docker run -d -p 27017:27017 --name=MyMongoDB --network mysubnet1 -e MONGO_INIT_DATABASE=test -e MONGO_INITDB_ROOT_USERNAME=testuser -e MONGO_INITDB_ROOT_PASSWORD=password --mount src="${{env.MOUNT_SOURCE_DESKTOP}}",target=/data,type=bind mongo:6.0 | |
env: | |
MONGO_INIT_DATABASE: test | |
MONGO_INITDB_ROOT_USERNAME: testuser | |
MONGO_INITDB_ROOT_PASSWORD: password | |
# Putting steps 4, 5 & 6 between "Create mongoDB container" and "Populate mongo database" seems to help the mongo container settle down | |
- name: 4__Marketplace API - Set up dotnet core ${{ env.NETCORE_VERSION }} | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.NETCORE_VERSION }} | |
# Publish the app and the tests | |
- name: 5__Marketplace - Publish Marketplace Api | |
run: | | |
dotnet publish --framework:net6.0 ${{env.MARKETPLACE_PROJECT_FQDN}} -c Release -o ./publish ; | |
dotnet publish ./DumpAppLog/DumpAppLog.csproj | |
# Create a Docker Container for Marketplace | |
- name: 6__Marketplace - Build Docker Image | |
run: docker build -f "./api/CESMII.Marketplace.API/Dockerfile" --force-rm -t cesmiimarketplaceapi:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=CESMII.Marketplace.API" "./" | |
# Populate mongo database - | |
- name: 7__MongoDB - Populate mongo database | |
run: docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=app_log --file=/data/app_log.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=JobLog --file=/data/JobLog.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=LookupItem --file=/data/LookupItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=MarketplaceItem --file=/data/MarketplaceItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=MarketplaceItemAnalytics --file=/data/MarketplaceItemAnalytics.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Organization --file=/data/Organization.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Permission --file=/data/Permission.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=ProfileItem --file=/data/ProfileItem.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=Publisher --file=/data/Publisher.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=RequestInfo --file=/data/RequestInfo.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
docker exec -i MyMongoDB mongoimport --authenticationDatabase=admin --collection=SearchKeyword --file=/data/SearchKeyword.json --uri="${{env.MONGODB_LOCAL_CONNECTION}}" ; | |
- name: 8__MongoDB - Test access to Mongo database | |
run: dotnet test ${{env.TEST2_PROJECT_DIRECTORY}}${{env.TEST2_PROJECT_FILE}} | |
env: | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_LOCAL_CONNECTION}} | |
MARKETPLACE_MONGODB_DATABASE: ${{env.MONGODB_DATABASE_NAME}} | |
# Start Marketplace Container (On Github) | |
- name: 9__Marketplace - Start the Container (On Github) | |
if: env.ONGITHUB == 'true' | |
env: | |
ASPNETCORE_ENVIRONMENT: Development | |
ASPNETCORE_URLS: http://+:80 | |
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true | |
DOTNET_RUNNING_IN_CONTAINER: true | |
DOTNET_USE_POLLING_FILE_WATCHER: 1 | |
EnableCloudLibSearch: false | |
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_SECUR_CONNECTION}} | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: | | |
docker run -dt --network mysubnet1 -v "/home/runner/work/Marketplace/Marketplace/api/CESMII.Marketplace.API:/app" -v "/home/runner/work/Marketplace/Marketplace:/src/" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "EnableCloudLibSearch=false" -e "ASPNETCORE_URLS=http://+:80" -p 5000:80 -p:5001:443 --name CESMII.Marketplace.API --entrypoint tail cesmiimarketplaceapi:dev -f /dev/null | |
# Start Marketplace Container (On Desktop) | |
- name: 9__Marketplace - Start the Container (On Desktop) | |
if: env.ONGITHUB == 'false' | |
env: | |
ASPNETCORE_ENVIRONMENT: Development | |
ASPNETCORE_URLS: http://+:80 | |
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true | |
DOTNET_RUNNING_IN_CONTAINER: true | |
DOTNET_USE_POLLING_FILE_WATCHER: 1 | |
EnableCloudLibSearch: false | |
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_SECUR_CONNECTION}} | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: | | |
docker run -dt --network mysubnet1 -v "C:\Users\paul\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\paul\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Sdks\Microsoft.Docker.Sdk\tools\TokenService.Proxy\linux-x64\net6.0:/TokenService.Proxy:ro" -v "C:\CESMII.github\Marketplace\api\CESMII.Marketplace.API:/app" -v "C:\CESMII.github\Marketplace:/src/" -v "C:\Users\paul\.nuget\packages\:/root/.nuget/fallbackpackages" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "ASPNETCORE_URLS=http://+:80" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" -e "EnableCloudLibSearch=false" -p 5000:80 -p 5001:443 --name CESMII.Marketplace.API --entrypoint tail cesmiimarketplaceapi:dev -f /dev/null | |
# Start the Main Dll in the Container (On Github) | |
## Github can accommodate "docker exec -i.... & ", ampersand at the end!!!) | |
## In Windows, docker exec -id works better | |
- name: 10__Marketplace - Start the Main Dll in the Container (Github) | |
if: env.ONGITHUB == 'true' | |
env: | |
ASPNETCORE_ENVIRONMENT: Development | |
ASPNETCORE_URLS: http://+:80 | |
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true | |
DOTNET_RUNNING_IN_CONTAINER: true | |
DOTNET_USE_POLLING_FILE_WATCHER: 1 | |
EnableCloudLibSearch: false | |
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_SECUR_CONNECTION}} | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: | | |
docker exec -i CESMII.Marketplace.API dotnet /src/publish/CESMII.Marketplace.API.dll & | |
# Start the Main Dll in the Container (On the Desktop) | |
- name: 10__Marketplace - Start the Main Dll in the Container (Desktop) | |
if: env.ONGITHUB == 'false' | |
env: | |
ASPNETCORE_ENVIRONMENT: Development | |
ASPNETCORE_URLS: http://+:80 | |
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS: true | |
DOTNET_RUNNING_IN_CONTAINER: true | |
DOTNET_USE_POLLING_FILE_WATCHER: 1 | |
EnableCloudLibSearch: false | |
MARKETPLACE_GITHUB_WORKFLOW_COMMANDS: true | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_SECUR_CONNECTION}} | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: | | |
docker exec -di CESMII.Marketplace.API dotnet /src/publish/CESMII.Marketplace.API.dll | |
# Dump from the log database | |
- name: A__Diagnostic__MarketplaceAPI - Dump Log | |
if: always() | |
env: | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: mongodb://testuser:password@localhost:27017 | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: dotnet run --project ./DumpAppLog/DumpAppLog.csproj | |
# # # # Dotnet -- diagnostics | |
# # # - name: A__Diagnostic__DotNet - Diagnostics | |
# # # #run: docker exec -i MyMarketplace /usr/share/dotnet/dotnet --diagnostics | |
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --diagnostics | |
# # # # Dotnet -- info | |
# # # - name: B__Diagnostic__DotNet - Info | |
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --info | |
# # # # Dotnet -- list-runtimes | |
# # # - name: C__Diagnostic__DotNet - list-runtimes | |
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --list-runtimes | |
# # # # Dotnet -- list-sdks | |
# # # - name: D__Diagnostic__DotNet - list-sdks | |
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --list-sdks | |
# # # # Dotnet --version | |
# # # - name: E__Diagnostic__DotNet - Version | |
# # # run: docker exec -i CESMII.Marketplace.API /usr/share/dotnet/dotnet --version | |
# # # # MyMongoDB - Check the Logs | |
# # # - name: F__Diagnostic__MyMongoDB Container - Check the Logs | |
# # # run: docker logs --details MyMongoDB | |
# # # # CESMII.Marketplace.API - Check the Logs | |
# # # - name: G__Diagnostic__CESMII.Marketplace.API Container - Check the Logs | |
# # # run: docker logs --details CESMII.Marketplace.API | |
# Peek at docker status | |
# # # - name: H__Diagnostic__Docker - Peeking at docker status | |
# # # run: docker container ls --all ; | |
# # # docker network ls ; | |
# # # docker network inspect mysubnet1 ; | |
# # # docker container inspect CESMII.Marketplace.API ; | |
# # # docker container inspect MyMongoDB ; | |
# # # docker system info ; | |
# # # docker port CESMII.Marketplace.API ; | |
# # # - name: I__Diagnostic____MongoDB - Test access to Mongo database (Reprise - repeat with slower, more meaningful phrasing) | |
# # # run: dotnet test ${{env.TEST2_PROJECT_FQDN}} | |
# # # env: | |
# # # MARKETPLACE_MONGODB_CONNECTIONSTRING: ${{env.MONGODB_SECUR_CONNECTION}} | |
# # # MARKETPLACE_MONGODB_DATABASE: ${{env.MONGODB_DATABASE_NAME}} | |
# # Testing -- Call into Marketplace Rest Api (call from inside container) - On Github | |
# # Does not work | |
# - name: 11__Tests - Access to RectApi inside container (On Github) | |
# if: env.ONGITHUB == 'true' | |
# env: | |
# MARKETPLACE_URL1: "http://localhost:80/api" | |
# run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:80/api" ${{env.TEST3_PROJECT_ABSOLUTE}} | |
# Testing -- Call into Marketplace Rest Api (call from runner) - On Github | |
- name: 12__Tests - Access to RectApi from outside container (On Github) | |
if: env.ONGITHUB == 'true' | |
env: | |
MARKETPLACE_URL1: "http://localhost:5000/api" | |
run: dotnet test -e "MARKETPLACE_URL1=http://localhost:5000/api" ${{env.TEST3_PROJECT_FQDN}} | |
# Testing -- Call into Marketplace Rest Api (call from inside container ) - On Desktop | |
- name: 11__Tests - Access to RectApi inside container (On Desktop) | |
if: env.ONGITHUB == 'false' | |
env: | |
MARKETPLACE_URL1: "http://localhost:80/api" | |
run: docker exec -i CESMII.Marketplace.API dotnet test -e "MARKETPLACE_URL1=http://localhost:80/api" ${{env.TEST3_PROJECT_ABSOLUTE}} | |
# Testing -- Call into Marketplace Rest Api (call from runner ) - On Desktop | |
- name: 12__Tests - Access to RectApi from outside container (On Desktop) | |
if: env.ONGITHUB == 'false' | |
env: | |
MARKETPLACE_URL1: "http://localhost:5000/api" | |
run: dotnet test -e "MARKETPLACE_URL1=http://localhost:5000/api" ${{env.TEST3_PROJECT_FQDN}} | |
# Dump from the log database | |
- name: A__Diagnostic__MarketplaceAPI - Dump Log | |
if: always() | |
env: | |
MARKETPLACE_MONGODB_CONNECTIONSTRING: mongodb://testuser:password@localhost:27017 | |
MARKETPLACE_MONGODB_DATABASE: test | |
run: dotnet run --project ./DumpAppLog/DumpAppLog.csproj | |
####################################################################################################### | |
#- name: FrontEnd - Start browser and fetch version | |
# run: chrome --version | |
#- name: FrontEnd - Use Node.js version (${{env.NODEJS_VERSION}}) | |
# uses: actions/setup-node@v3 | |
# with: | |
# node-version: ${{env.NODEJS_VERSION}} | |
#- name: FrontEnd - Build React Code - npm install, build | |
# working-directory: ${{env.NPM_WORKING_DIRECTORY}} | |
# env: | |
# CI: '' #when process-env-ci is true, warnings are ignored and not treated as errors | |
# run: | | |
# npm install | |
# npm run build:in-browser-test | |
# npm run start-in-browser-test & | |
##- name: Docker - launch standalone chrome browser | |
## run: | | |
## docker run -d -p 4444:4444 selenium/standalone-chrome | |
#- name: In-Browser Testing - Restore dependencies CESMII.Marketplace.InBrowser.Tests | |
# working-directory: ${{env.SOLUTION_DIRECTORY}} | |
# run: dotnet restore | |
#- name: In-Browser Testing - Run Test on project (${{env.TEST1_PROJECT_FILE}}) | |
# run: dotnet test ${{env.SOLUTION_DIRECTORY}}api/Tests/CESMII.Marketplace.InBrowser.Tests/${{env.TEST1_PROJECT_FILE}}.csproj --configuration Staging --verbosity normal -l:"console;verbosity=normal" | |
# working-directory: ${{env.SOLUTION_DIRECTORY}} |