From 7f42ccfd4426361eab13b587b1d56615163e7847 Mon Sep 17 00:00:00 2001 From: David Justo Date: Tue, 5 Mar 2024 14:18:45 -0800 Subject: [PATCH] Add GitHub Actions improvements: allow actions to be triggered manually, implement (best effort) fail fast, and get MSSQL working again (#2753) --- .../smoketest-dotnet-isolated-v4.yml | 1 + .github/workflows/smoketest-dotnet-v2.yml | 1 + .github/workflows/smoketest-dotnet-v3.yml | 1 + .github/workflows/smoketest-java8-v4.yml | 1 + .../workflows/smoketest-mssql-inproc-v4.yml | 1 + .../smoketest-netherite-inproc-v4.yml | 1 + .github/workflows/smoketest-node14-v4.yml | 1 + .github/workflows/smoketest-python37-v4.yml | 1 + .../BackendSmokeTests/MSSQL/Dockerfile | 2 +- test/SmokeTests/e2e-test.ps1 | 34 ++++++++++++++----- 10 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.github/workflows/smoketest-dotnet-isolated-v4.yml b/.github/workflows/smoketest-dotnet-isolated-v4.yml index 2e5b3842f..f818ff7ae 100644 --- a/.github/workflows/smoketest-dotnet-isolated-v4.yml +++ b/.github/workflows/smoketest-dotnet-isolated-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - .NET Isolated on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-dotnet-v2.yml b/.github/workflows/smoketest-dotnet-v2.yml index 0b4ab0e7b..2dc5c5417 100644 --- a/.github/workflows/smoketest-dotnet-v2.yml +++ b/.github/workflows/smoketest-dotnet-v2.yml @@ -1,6 +1,7 @@ name: Smoke Test - .NET on Functions V2 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-dotnet-v3.yml b/.github/workflows/smoketest-dotnet-v3.yml index a7ab2d8e6..4644c5df9 100644 --- a/.github/workflows/smoketest-dotnet-v3.yml +++ b/.github/workflows/smoketest-dotnet-v3.yml @@ -1,6 +1,7 @@ name: Smoke Test - .NET on Functions V3 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-java8-v4.yml b/.github/workflows/smoketest-java8-v4.yml index dfec91f79..e118632bb 100644 --- a/.github/workflows/smoketest-java8-v4.yml +++ b/.github/workflows/smoketest-java8-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - Java 8 on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-mssql-inproc-v4.yml b/.github/workflows/smoketest-mssql-inproc-v4.yml index d5bf3c13a..8c373fc5c 100644 --- a/.github/workflows/smoketest-mssql-inproc-v4.yml +++ b/.github/workflows/smoketest-mssql-inproc-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - .NET in-proc w/ MSSQL on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-netherite-inproc-v4.yml b/.github/workflows/smoketest-netherite-inproc-v4.yml index 607e2ad71..c8d62c1d7 100644 --- a/.github/workflows/smoketest-netherite-inproc-v4.yml +++ b/.github/workflows/smoketest-netherite-inproc-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - .NET in-proc w/ Netherite on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-node14-v4.yml b/.github/workflows/smoketest-node14-v4.yml index 376c67933..3078b8d10 100644 --- a/.github/workflows/smoketest-node14-v4.yml +++ b/.github/workflows/smoketest-node14-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - Node 14 on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/.github/workflows/smoketest-python37-v4.yml b/.github/workflows/smoketest-python37-v4.yml index b5ac000ec..70b7b5378 100644 --- a/.github/workflows/smoketest-python37-v4.yml +++ b/.github/workflows/smoketest-python37-v4.yml @@ -1,6 +1,7 @@ name: Smoke Test - Python 3.7 on Functions V4 on: + workflow_dispatch: push: branches: [ main, dev ] paths: diff --git a/test/SmokeTests/BackendSmokeTests/MSSQL/Dockerfile b/test/SmokeTests/BackendSmokeTests/MSSQL/Dockerfile index 504eb0cd3..8a2dea435 100644 --- a/test/SmokeTests/BackendSmokeTests/MSSQL/Dockerfile +++ b/test/SmokeTests/BackendSmokeTests/MSSQL/Dockerfile @@ -3,7 +3,7 @@ FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env -# Build the app +# Build the DF MSSQL app COPY . /root RUN cd /root/test/SmokeTests/BackendSmokeTests/MSSQL && \ mkdir -p /home/site/wwwroot && \ diff --git a/test/SmokeTests/e2e-test.ps1 b/test/SmokeTests/e2e-test.ps1 index f271507c1..845c35eb2 100644 --- a/test/SmokeTests/e2e-test.ps1 +++ b/test/SmokeTests/e2e-test.ps1 @@ -1,5 +1,4 @@ -# Installing PowerShell: https://docs.microsoft.com/powershell/scripting/install/installing-powershell - + param( [Parameter(Mandatory=$true)] [string]$DockerfilePath, @@ -10,7 +9,6 @@ param( [switch]$NoSetup=$false, [switch]$NoValidation=$false, [int]$Sleep=30, - [string]$additinalRunFlags="", [switch]$SetupSQLServer=$false, [string]$pw="$env:SA_PASSWORD", [string]$sqlpid="Express", @@ -20,6 +18,13 @@ param( [string]$collation="Latin1_General_100_BIN2_UTF8" ) +function Exit-OnError() { + # There appears to be a known problem in GitHub Action's `pwsh` shell preventing it from failing fast on an error: + # https://github.com/actions/runner-images/issues/6668#issuecomment-1364540817 + # Therefore, we manually check if there was an error an fail if so. + if (!$LASTEXITCODE.Equals(0)) {exit $LASTEXITCODE} +} + $ErrorActionPreference = "Stop" $AzuriteVersion = "3.26.0" @@ -27,37 +32,46 @@ if ($NoSetup -eq $false) { # Build the docker image first, since that's the most critical step Write-Host "Building sample app Docker container from '$DockerfilePath'..." -ForegroundColor Yellow docker build -f $DockerfilePath -t $ImageName --progress plain $PSScriptRoot/../../ + Exit-OnError # Next, download and start the Azurite emulator Docker image Write-Host "Pulling down the mcr.microsoft.com/azure-storage/azurite:$AzuriteVersion image..." -ForegroundColor Yellow docker pull "mcr.microsoft.com/azure-storage/azurite:${AzuriteVersion}" + Exit-OnError Write-Host "Starting Azurite storage emulator using default ports..." -ForegroundColor Yellow docker run --name 'azurite' -p 10000:10000 -p 10001:10001 -p 10002:10002 -d "mcr.microsoft.com/azure-storage/azurite:${AzuriteVersion}" + Exit-OnError if ($SetupSQLServer -eq $true) { Write-Host "Pulling down the mcr.microsoft.com/mssql/server:$tag image..." docker pull mcr.microsoft.com/mssql/server:$tag - + Exit-OnError + # Start the SQL Server docker container with the specified edition Write-Host "Starting SQL Server $tag $sqlpid docker container on port $port" -ForegroundColor DarkYellow - docker run $additinalRunFlags --name mssql-server -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$pw" -e "MSSQL_PID=$sqlpid" -p ${port}:1433 -d mcr.microsoft.com/mssql/server:$tag - + docker run --name mssql-server -e 'ACCEPT_EULA=Y' -e "MSSQL_SA_PASSWORD=$pw" -e "MSSQL_PID=$sqlpid" -p ${port}:1433 -d mcr.microsoft.com/mssql/server:$tag + Exit-OnError + # Wait for SQL Server to be ready Write-Host "Waiting for SQL Server to be ready..." -ForegroundColor Yellow Start-Sleep -Seconds 30 # Adjust the sleep duration based on your SQL Server container startup time + Exit-OnError # Get SQL Server IP Address - used to create SQLDB_Connection Write-Host "Getting IP Address..." -ForegroundColor Yellow $serverIpAddress = docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mssql-server - + Exit-OnError + # Create the database with strict binary collation Write-Host "Creating '$dbname' database with '$collation' collation" -ForegroundColor DarkYellow docker exec -d mssql-server /opt/mssql-tools/bin/sqlcmd -S . -U sa -P "$pw" -Q "CREATE DATABASE [$dbname] COLLATE $collation" + Exit-OnError # Wait for database to be ready Write-Host "Waiting for database to be ready..." -ForegroundColor Yellow Start-Sleep -Seconds 30 # Adjust the sleep duration based on your database container startup time + Exit-OnError # Finally, start up the application container, connecting to the SQL Server container Write-Host "Starting the $ContainerName application container" -ForegroundColor Yellow @@ -66,6 +80,7 @@ if ($NoSetup -eq $false) { --env 'AzureWebJobsStorage=UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://host.docker.internal' ` --env 'WEBSITE_HOSTNAME=localhost:8080' ` $ImageName + Exit-OnError } else { Write-Host "Starting $ContainerName application container" -ForegroundColor Yellow @@ -74,6 +89,7 @@ if ($NoSetup -eq $false) { --env 'WEBSITE_HOSTNAME=localhost:8080' ` $ImageName } + Exit-OnError } if ($sleep -gt 0) { @@ -84,12 +100,14 @@ if ($sleep -gt 0) { # Check to see what containers are running docker ps +Exit-OnError try { # Make sure the Functions runtime is up and running $pingUrl = "http://localhost:8080/admin/host/ping" Write-Host "Pinging app at $pingUrl to ensure the host is healthy" -ForegroundColor Yellow Invoke-RestMethod -Method Post -Uri "http://localhost:8080/admin/host/ping" + Exit-OnError if ($NoValidation -eq $false) { # Note that any HTTP protocol errors (e.g. HTTP 4xx or 5xx) will cause an immediate failure @@ -134,4 +152,4 @@ try { throw } -Write-Host "Success!" -ForegroundColor Green +Write-Host "Success!" -ForegroundColor Green \ No newline at end of file