Skip to content

E2E: Build and Test #65

E2E: Build and Test

E2E: Build and Test #65

Workflow file for this run

name: "E2E: Build and Test"
on:
schedule:
- cron: '0 10 * * 5' # Runs every Friday at 10:00 UTC
workflow_dispatch:
jobs:
build_and_test:
name: Test E2E
runs-on: ubuntu-latest
defaults:
run:
shell: pwsh
env:
ASPNETCORE_ENVIRONMENT: CI
XBK_DATABASE_BACKUP_FILENAME: ""
K13_DATABASE_BACKUP_FILENAME: ""
DOTNET_CLI_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_NOLOGO: 1
XBK_PROJECT_NAME: DancingGoat
K13_PROJECT_NAME: Kentico13_DancingGoat
XBK_STATUS_CHECK_URL: https://localhost:14066/status
K13_STATUS_CHECK_URL: http://localhost:65375/status
XPERIENCE_BY_KENTICO_LICENSE: ${{ secrets.XPERIENCE_BY_KENTICO_LICENSE }}
KENTICO_XPERIENCE_13_LICENSE: ${{ secrets.KENTICO_XPERIENCE_13_LICENSE }}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- 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 test/Playwright
npm ci
npx playwright install --with-deps
cd ../..
- name: Get Database Backup Name
run: |
$latestBackups = Get-Content -Path "./database/backups.txt" -TotalCount 2
"K13_DATABASE_BACKUP_FILENAME=$($latestBackups[0])" >> $env:GITHUB_ENV
"XBK_DATABASE_BACKUP_FILENAME=$($latestBackups[1])" >> $env:GITHUB_ENV
- name: Extract Database Backup
run: |
Expand-Archive `
-Path "./database/${{ env.K13_DATABASE_BACKUP_FILENAME }}.zip" `
-DestinationPath "./database"
Expand-Archive `
-Path "./database/${{ env.XBK_DATABASE_BACKUP_FILENAME }}.zip" `
-DestinationPath "./database"
- name: Install a SQL Server suite of tools (SQLEngine, SQLPackage)
uses: potatoqualitee/mssqlsuite@605af2310e2e22978ebf2c74d5995ba102094b8a # set as a commit hash for security - v1.8
with:
install: sqlpackage, sqlengine, sqlclient
sa-password: Pass@12345
version: 2022
- name: Restore Database .bak
run: |
docker exec sql mkdir /var/opt/mssql/backup
docker cp "./database/${{ env.K13_DATABASE_BACKUP_FILENAME }}" sql:/var/opt/mssql/backup
sqlcmd `
-S localhost `
-d master `
-U "sa" `
-P "Pass@12345" `
-C `
-Q "RESTORE DATABASE [Kentico13_DancingGoat] FROM DISK='/var/opt/mssql/backup/${{ env.K13_DATABASE_BACKUP_FILENAME }}' WITH MOVE 'Kentico13_DancingGoat' TO '/var/opt/mssql/data/Kentico13_DancingGoat.mdf', MOVE 'Kentico13_DancingGoat_log' TO '/var/opt/mssql/data/Kentico13_DancingGoat_log.ldf'"
docker cp "./database/${{ env.XBK_DATABASE_BACKUP_FILENAME }}" sql:/var/opt/mssql/backup
sqlcmd `
-S localhost `
-d master `
-U "sa" `
-P "Pass@12345" `
-C `
-Q "RESTORE DATABASE [XByK_DancingGoat_K13Ecommerce] FROM DISK='/var/opt/mssql/backup/${{ env.XBK_DATABASE_BACKUP_FILENAME }}' WITH MOVE 'XByK_DancingGoat_K13Ecommerce' TO '/var/opt/mssql/data/XByK_DancingGoat_K13Ecommerce.mdf', MOVE 'XByK_DancingGoat_K13Ecommerce_log' TO '/var/opt/mssql/data/XByK_DancingGoat_K13Ecommerce_log.ldf'"
- name: Imports license key to DB
run: |
sqlcmd `
-S localhost `
-d Kentico13_DancingGoat `
-U "sa" `
-P "Pass@12345" `
-C `
-Q "INSERT INTO [dbo].[CMS_LicenseKey] VALUES ('localhost', '${{ env.KENTICO_XPERIENCE_13_LICENSE }}', 'X', '10/20/2025', 1);"
sqlcmd `
-S localhost `
-d XByK_DancingGoat_K13Ecommerce `
-U "sa" `
-P "Pass@12345" `
-C `
-Q "UPDATE CMS_SettingsKey SET KeyValue='${{ env.XPERIENCE_BY_KENTICO_LICENSE }}' WHERE KeyName='CMSLicenseKey'"
- 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/Kentico13_DancingGoatStore `
-c Release `
-o ./publish/K13 `
--no-build `
--no-restore
dotnet publish `
./examples/DancingGoat-K13Ecommerce `
-c Release `
-o ./publish/XbK `
--no-build `
--no-restore
- name: Test Solution
run: |
dotnet test `
--filter TestCategory!~Integration `
--configuration Release `
--no-build `
--no-restore
- name: Run Applications and E2E Tests
run: |
# Run the ASP.NET Core app as a background job
cd ./publish/K13
Start-Job -ScriptBlock {
dotnet --version
dotnet ./${{ env.K13_PROJECT_NAME }}.dll
} -Name ${{ env.K13_PROJECT_NAME }}
Receive-Job -Name ${{ env.K13_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 = 30
$attempts = 0
$success = $false
while ($attempts -lt $limit -and -not $success) {
Start-Sleep -Seconds 1
try {
$response = Invoke-WebRequest -Uri ${{ env.K13_STATUS_CHECK_URL }} -Method Get -SkipCertificateCheck
if ($response.StatusCode -eq 200) {
Write-Output "K13 store: Application is ready."
$success = $true
}
}
catch {
Write-Output "Attempt $attempts - Application not ready yet."
}
$attempts++
}
if (-not $success) {
Write-Output "K13 store: Application did not respond in time."
Receive-Job -Name ${{ env.K13_PROJECT_NAME }}
Stop-Job -Name ${{ env.K13_PROJECT_NAME }}
Remove-Job -Name ${{ env.K13_PROJECT_NAME }}
exit 1
}
# Run the ASP.NET Core app as a background job
cd ./publish/XbK
Start-Job -ScriptBlock {
dotnet --version
dotnet ./${{ env.XBK_PROJECT_NAME }}.dll
} -Name ${{ env.XBK_PROJECT_NAME }}
Receive-Job -Name ${{ env.XBK_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 = 30
$attempts = 0
$success = $false
while ($attempts -lt $limit -and -not $success) {
Start-Sleep -Seconds 1
try {
$response = Invoke-WebRequest -Uri ${{ env.XBK_STATUS_CHECK_URL }} -Method Get -SkipCertificateCheck
if ($response.StatusCode -eq 200) {
Write-Output "XbK Application is ready."
$success = $true
}
}
catch {
Write-Output "Attempt $attempts - Application not ready yet."
}
$attempts++
}
if (-not $success) {
Write-Output "XbK Application did not respond in time."
Receive-Job -Name ${{ env.XBK_PROJECT_NAME }}
Stop-Job -Name ${{ env.XBK_PROJECT_NAME }}
Remove-Job -Name ${{ env.XBK_PROJECT_NAME }}
exit 1
}
# Sleep for finishing initialization
Start-Sleep -Seconds 10
# Run the E2E tests
cd test/Playwright
npx playwright test
cd ../..
# Stop the background ASP.NET Core application
Receive-Job -Name ${{ env.K13_PROJECT_NAME }}
Stop-Job -Name ${{ env.K13_PROJECT_NAME }}
Remove-Job -Name ${{ env.K13_PROJECT_NAME }}
Receive-Job -Name ${{ env.XBK_PROJECT_NAME }}
Stop-Job -Name ${{ env.XBK_PROJECT_NAME }}
Remove-Job -Name ${{ env.XBK_PROJECT_NAME }}
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: ./test/Playwright/playwright-report/
retention-days: 30
# Create an issue if this job fails
- name: "Create GitHub Issue on Failure"
if: ${{ failure() && github.event_name != 'workflow_dispatch' }} # Runs only on failure and not manual trigger
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const date = new Date();
const issueTitle = `🚨 ${date.toLocaleDateString('en-GB')} E2E Test Failed: Weekly Cron Job`;
const issueBody = `### Workflow Failure Alert
- **Repository**: ${{ github.repository }}
- **Workflow**: [Test E2E](https://github.com/Kentico/xperience-by-kentico-k13ecommerce/actions/runs/${{ github.run_id }})
- **Timestamp**: ${date.toISOString()}
Please check the logs and resolve the issue.`;
try {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: issueTitle,
body: issueBody,
labels: ["workflow-failure"]
});
} catch (error) {
console.error("Error creating issue:", error);
}