Skip to content

Commit

Permalink
Feat/automatic e2 e testing (#36)
Browse files Browse the repository at this point in the history
* backup init, ci store setup, pipeline for e2e testing preparation

* adding ci store script

* fix restore ci file

* update scripts, setting auto hotfix from pipeline

* defining asp urls in pipeline

* updated bak

* insert license from secrets

* E2E Playwright tests wth updated ci.yml

* Update ci.yml

fixed typo

* Update ci.yml

typo fix

* ignoreHTTPSErrors set to True

* seeding db for testing purposes

* Adding more triggers to seed db

* Test update +change in workflow-upload artifacts if not cancelled

* creating schedule task for e2e tests

* removing commented unused code from appsettings.ci.json

* ci store after hotfix

* CR: Replacing var with const in BasePage.ts

---------

Co-authored-by: Andrej Ryška <andrej.ryska@bluesoft.cz>
Co-authored-by: andrejrblue <167293373+andrejrblue@users.noreply.github.com>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent 6264434 commit 3364725
Show file tree
Hide file tree
Showing 1,435 changed files with 32,915 additions and 128 deletions.
132 changes: 66 additions & 66 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,66 @@
name: "CI: Build and Test"

on:
push:
branches: [main]
paths:
- "**.cs"
- "**.tsx"
- "**.js"
- "**.csproj"
- "**.props"
- "**.targets"
- "**.sln"
- "**/Client/**/*.json"
pull_request:
branches: [main]
paths:
- "**.cs"
- "**.cshtml"
- "**.tsx"
- "**.js"
- "**.json"
- "**.csproj"
- "**.props"
- "**.targets"
- "**.sln"

jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh

env:
ASPNETCORE_ENVIRONMENT: CI
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: 1

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Install dependencies
run: |
dotnet restore `
--locked-mode
- name: Build Solution
run: |
dotnet build `
--configuration Release `
--no-restore
- name: Test Solution
run: |
dotnet test `
--configuration Release `
--no-build `
--no-restore
name: "CI: Build and Test"

on:
push:
branches: [main]
paths:
- "**.cs"
- "**.tsx"
- "**.js"
- "**.csproj"
- "**.props"
- "**.targets"
- "**.sln"
- "**/Client/**/*.json"
pull_request:
branches: [main]
paths:
- "**.cs"
- "**.cshtml"
- "**.tsx"
- "**.js"
- "**.json"
- "**.csproj"
- "**.props"
- "**.targets"
- "**.sln"

jobs:
build_and_test:
name: Build and Test
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh

env:
ASPNETCORE_ENVIRONMENT: CI
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: 1

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Install dependencies
run: |
dotnet restore `
--locked-mode
- name: Build Solution
run: |
dotnet build `
--configuration Release `
--no-restore
- name: Test Solution
run: |
dotnet test `
--configuration Release `
--no-build `
--no-restore
172 changes: 172 additions & 0 deletions .github/workflows/e2etest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
name: "E2E: Build and Test"

on:
schedule:
- cron: '0 10 * * 5' # Runs every Friday at 10:00 UTC

jobs:
build_and_test:
name: Test E2E
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh

env:
ASPNETCORE_ENVIRONMENT: CI
DATABASE_BACKUP_FILENAME: ""
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: 1
PROJECT_NAME: DancingGoat
ASPNETCORE_URLS: https://localhost:14070
STATUS_CHECK_URL: https://localhost:14070/status
DATABASE_USER: "sa"
DATABASE_PASSWORD: "Pass@12345"
DATABASE_NAME: "XByK_DancingGoat_Zapier"
XPERIENCE_BY_KENTICO_LICENSE: ${{ secrets.XPERIENCE_BY_KENTICO_LICENSE }}

steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: lts/*

- name: Install NPM
run: |
cd tests/Playwright
npm ci
npx playwright install --with-deps
cd ../..
- name: Get Database Backup Name
run: |
$latestBackup = Get-Content -Path "./database/backups.txt" -TotalCount 1
"DATABASE_BACKUP_FILENAME=$latestBackup" >> $env:GITHUB_ENV
- name: Extract Database Backup
run: |
Expand-Archive `
-Path "./database/${{ env.DATABASE_BACKUP_FILENAME }}.zip" `
-DestinationPath "./database"
- name: Install a SQL Server suite of tools (SQLEngine, SQLPackage)
uses: potatoqualitee/mssqlsuite@9a0136e208df60b8ecb62909f076bc34854fa55a # set as a commit hash for security - v1.7
with:
install: sqlpackage, sqlengine
sa-password: ${{ env.DATABASE_PASSWORD }}
version: 2022

- name: Restore Database .bak
run: |
docker exec sql mkdir /var/opt/mssql/backup
docker cp "./database/${{ env.DATABASE_BACKUP_FILENAME }}" sql:/var/opt/mssql/backup
sqlcmd `
-S localhost `
-d master `
-U ${{ env.DATABASE_USER }} `
-P ${{ env.DATABASE_PASSWORD }} `
-Q "RESTORE DATABASE [XByK_DancingGoat_Zapier] FROM DISK='/var/opt/mssql/backup/${{ env.DATABASE_BACKUP_FILENAME }}' WITH MOVE 'XByK_DancingGoat_Zapier' TO '/var/opt/mssql/data/XByK_DancingGoat_Zapier.mdf', MOVE 'XByK_DancingGoat_Zapier_log' TO '/var/opt/mssql/data/XByK_DancingGoat_Zapier_log.ldf'"
- name: Imports license key to DB
run: |
sqlcmd `
-S localhost `
-d ${{ env.DATABASE_NAME }} `
-U ${{ env.DATABASE_USER }} `
-P ${{ env.DATABASE_PASSWORD }} `
-Q "UPDATE CMS_SettingsKey SET KeyValue='${{ env.XPERIENCE_BY_KENTICO_LICENSE }}' WHERE KeyName='CMSLicenseKey'"
- name: Seed DB with data for testing purposes
run: |
cd scripts
./Seed-Database.ps1
cd ..
- name: Reset DB consistency for last applied hotfix
run: |
dotnet build `
--configuration Release
cd scripts
./Reset-DatabaseConsistency.ps1
cd ..
- name: Build Solution for last hotfix
run: |
dotnet build `
--configuration Release `
-p:XbyKVersion=*
cd scripts
./Reset-DatabaseConsistency.ps1 -ExcludeCIRestore
cd ..
- name: Publish Application
run: |
dotnet publish `
./examples/${{ env.PROJECT_NAME }} `
-c Release `
-o ./publish `
--no-build `
--no-restore
- name: Test Solution
run: |
dotnet test `
--configuration Release `
--no-build `
--no-restore
- name: Run Application and E2E Tests
run: |
# Run the ASP.NET Core app as a background job
cd ./publish
Start-Job -ScriptBlock { dotnet ./${{ env.PROJECT_NAME }}.dll } -Name ${{ env.PROJECT_NAME }}
Receive-Job -Name ${{ env.PROJECT_NAME }}
cd ../
# The ASP.NET Core app can take a few seconds to start, so we delay running tests
# until it is ready, and fail if we go over a maximum wait time
$limit = 10
$attempts = 0
$success = $false
while ($attempts -lt $limit -and -not $success) {
Start-Sleep -Seconds 1
try {
$response = Invoke-WebRequest -Uri ${{ env.STATUS_CHECK_URL }} -Method Get -SkipCertificateCheck
if ($response.StatusCode -eq 200) {
Write-Output "Application is ready."
$success = $true
}
}
catch {
Write-Output "Attempt $attempts - Application not ready yet."
}
$attempts++
}
if (-not $success) {
Write-Output "Application did not respond in time."
exit 1
}
# Run the E2E tests
cd tests/Playwright
npx playwright test
cd ../..

# Stop the background ASP.NET Core application
Receive-Job -Name ${{ env.PROJECT_NAME }}
Stop-Job -Name ${{ env.PROJECT_NAME }}
Remove-Job -Name ${{ env.PROJECT_NAME }}

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: ./tests/Playwright/playwright-report/
retention-days: 30
45 changes: 24 additions & 21 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageVersionOverrideEnabled>false</CentralPackageVersionOverrideEnabled>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Kentico.Xperience.Admin" Version="29.7.0" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="29.7.0" />
<PackageVersion Include="kentico.xperience.azurestorage" Version="29.7.0" />
<PackageVersion Include="kentico.xperience.imageprocessing" Version="29.7.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.6.0.74858" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="AspNetCore.Authentication.ApiKey" Version="8.0.1" />
</ItemGroup>
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageVersionOverrideEnabled>true</CentralPackageVersionOverrideEnabled>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<DisableImplicitNuGetFallbackFolder>true</DisableImplicitNuGetFallbackFolder>
<CentralPackageFloatingVersionsEnabled>true</CentralPackageFloatingVersionsEnabled>
<LastAppliedHotfix>29.7.0</LastAppliedHotfix>
<XbyKVersion Condition="'$(XbyKVersion)' == ''">$(LastAppliedHotfix)</XbyKVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Kentico.Xperience.Admin" Version="$(LastAppliedHotfix)" />
<PackageVersion Include="Kentico.Xperience.WebApp" Version="$(LastAppliedHotfix)" />
<PackageVersion Include="kentico.xperience.azurestorage" Version="$(LastAppliedHotfix)" />
<PackageVersion Include="kentico.xperience.imageprocessing" Version="$(LastAppliedHotfix)" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="9.6.0.74858" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="NUnit" Version="4.2.2" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="NUnit.Analyzers" Version="4.4.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="AspNetCore.Authentication.ApiKey" Version="8.0.1" />
</ItemGroup>
</Project>
Binary file added database/XByK_DancingGoat_Zapier.bak.zip
Binary file not shown.
1 change: 1 addition & 0 deletions database/backups.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
XByK_DancingGoat_Zapier.bak
Empty file.
Empty file.
Empty file.
Loading

0 comments on commit 3364725

Please sign in to comment.