Merge pull request #86 from Kentico/feat/optimized-image-asset-samples #410
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
name: "CI: Build and Test" | |
on: | |
push: | |
branches: [main, feat/github-actions-pipeline] | |
paths: | |
- "**.cs" | |
- "**.cshtml" | |
- "**.tsx" | |
- "**.js" | |
- "**.json" | |
- "**.csproj" | |
- "**.props" | |
- "**.targets" | |
- "**.sln" | |
- "**.yml" | |
pull_request: | |
branches: [main] | |
paths: | |
- "**.cs" | |
- "**.cshtml" | |
- "**.tsx" | |
- "**.js" | |
- "**.json" | |
- "**.csproj" | |
- "**.props" | |
- "**.targets" | |
- "**.sln" | |
env: | |
XBK_DIR: "${{ github.workspace }}\\xbk" | |
UMT_DIR: "${{ github.workspace }}\\umt" | |
DB_USER: "kentico" | |
DB_DATABASE: "pwtest" | |
LICENSE_FILE: "${{ github.workspace }}\\license.txt" | |
XBK_URL: "" | |
SQLSERVER_NAME: ".\\SQLEXPRESS" | |
jobs: | |
build: | |
runs-on: windows-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
path: ${{ env.UMT_DIR }} | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
global-json-file: "${{ env.UMT_DIR}}\\global.json" | |
- name: <DB> Install SQL Server | |
uses: Particular/[email protected] | |
with: | |
connection-string-env-var: SQL_SERVER_CONNECTION_STRING | |
catalog: kentico-boilerplate | |
- name: <DB> Create Kentico DB user | |
run: | | |
sqlcmd -Q "CREATE LOGIN ${{ env.DB_USER}} WITH PASSWORD = '${{ secrets.XPERIENCE_BY_KENTICO_DB_PASSWORD }}'; | |
CREATE USER kentico FOR LOGIN kentico; | |
GO" | |
- name: <DB> Add kentico user to sysadmin role | |
run: | | |
sqlcmd -Q "sp_addsrvrolemember '${{ env.DB_USER}}', 'sysadmin'; | |
GO" | |
- name: <DB> Enable SQL authentication | |
run: | | |
Write-Output "SQL Server: Setting Mixed Mode Authentication." | |
New-ItemProperty 'HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL16.SQLEXPRESS\MSSQLServer\' -Name 'LoginMode' -Value 2 -Force | |
Write-Output "SQL Server: Forcing Restart of Instance." | |
Restart-Service -Force 'MSSQL$SQLEXPRESS' | |
- name: <DB> Create database | |
run: | | |
sqlcmd -S "${{ env.SQLSERVER_NAME}}" -U '${{ env.DB_USER}}' -P '${{ secrets.XPERIENCE_BY_KENTICO_DB_PASSWORD }}' -Q "CREATE DATABASE ${{ env.DB_DATABASE}};" | |
- name: <XbK> Install kentico templates | |
working-directory: ${{ env.UMT_DIR }} | |
run: | | |
$XBK_CORE_VERSION = Select-String -Path "Directory.Packages.props" -Pattern '<PackageVersion Include="Kentico.Xperience.Core" Version="([^"]*)"' | ForEach-Object { $_.Matches.Groups[1].Value } | |
mkdir ${{ env.XBK_DIR }} | |
cd ${{ env.XBK_DIR }} | |
dotnet new install Kentico.Xperience.Templates::$XBK_CORE_VERSION | |
- name: <XbK> Create Kentico Xperience project | |
working-directory: ${{ env.XBK_DIR }} | |
run: | | |
echo "y" | dotnet new kentico-xperience-mvc -n kentico-boilerplate | |
- name: <XbK> Run kentico dbmanager with license | |
working-directory: ${{ env.XBK_DIR }} | |
run: | | |
echo ${{ secrets.XPERIENCE_BY_KENTICO_LICENSE }} > ${{ env.LICENSE_FILE }} | |
Write-Output "SQL_SERVER_CONNECTION_STRING: $env:SQL_SERVER_CONNECTION_STRING" | |
dotnet kentico-xperience-dbmanager -- -s "${{ env.SQLSERVER_NAME}}" -d "${{ env.DB_DATABASE }}" -u "${{ env.DB_USER }}" -p "${{ secrets.XPERIENCE_BY_KENTICO_DB_PASSWORD }}" -a "${{ secrets.XPERIENCE_BY_KENTICO_ADMIN_PASSWORD }}" --license-file "${{ env.LICENSE_FILE }}" --use-existing-database --hash-string-salt "<hash_string_salt>" | |
sqlcmd -S "${{ env.SQLSERVER_NAME}}" -U 'kentico' -P '${{ secrets.XPERIENCE_BY_KENTICO_DB_PASSWORD }}' -d "${{ env.DB_DATABASE }}" -Q "SELECT * FROM CMS_User" | |
- name: <UMT> Prepare appsettings.json for migration | |
working-directory: ${{ env.UMT_DIR }} | |
run: | | |
$EXAMPLE_APPSETTINGS = "examples/Kentico.Xperience.UMT.Example.Console/appsettings.json" | |
$CMS_CONNECTION_STRING = (Get-Content "${{ env.XBK_DIR }}/appsettings.json" | ConvertFrom-Json).ConnectionStrings.CMSConnectionString | |
$appsettings = Get-Content $EXAMPLE_APPSETTINGS | ConvertFrom-Json | |
$appsettings.ConnectionStrings.CMSConnectionString = $CMS_CONNECTION_STRING | |
$appsettings.WebApplicationPhysicalPath = "${{ env.XBK_DIR }}" | |
$appsettings | ConvertTo-Json -Compress | Set-Content $EXAMPLE_APPSETTINGS | |
Get-Content $EXAMPLE_APPSETTINGS | |
- name: <UMT> Install dependencies and build | |
working-directory: ${{ env.UMT_DIR }} | |
run: | | |
dotnet restore --locked-mode | |
dotnet tool restore | |
dotnet build | |
- name: <UMT> Run example migration | |
working-directory: ${{ env.UMT_DIR }}\examples\Kentico.Xperience.UMT.Example.Console\ | |
run: | | |
dotnet run --no-build | |
- name: Install Playwright | |
working-directory: ${{ env.UMT_DIR }}\tests\Kentico.Xperience.UMT.Tests | |
run: | | |
bin\Debug\net8.0\playwright.ps1 install --with-deps | |
- name: Prepare test.runsettings | |
working-directory: ${{ env.UMT_DIR }} | |
run: | | |
Get-Content "${{ env.XBK_DIR }}\Properties\launchSettings.json" | |
$url = (Get-Content "${{ env.XBK_DIR }}\Properties\launchSettings.json" | ConvertFrom-Json).profiles.kentico_boilerplate.applicationUrl | |
echo "XBK_URL=$url" | Out-File -FilePath ${{ github.env }} -Encoding utf8 -Append | |
Write-Output "Setting XbK URL for tests: $url" | |
(Get-Content test.runsettings) -replace "<BASE_URL>([^<]*)</BASE_URL>", "<BASE_URL>$url</BASE_URL>" | Set-Content test.runsettings | |
(Get-Content test.runsettings) -replace "<ADMINISTRATION_PASSWORD>([^<]*)</ADMINISTRATION_PASSWORD>", "<ADMINISTRATION_PASSWORD>${{ secrets.XPERIENCE_BY_KENTICO_ADMIN_PASSWORD }}</ADMINISTRATION_PASSWORD>" | Set-Content test.runsettings | |
Get-Content test.runsettings | |
- name: Start xbk and run tests | |
run: | | |
cd ${{ env.XBK_DIR }} | |
Start-Job -ScriptBlock { dotnet run --project "${{ env.XBK_DIR }}\kentico-boilerplate.csproj" } -Name "XbK" | |
Write-Output "XbK starting..." | |
$timeout = 100 | |
$elapsed = 0 | |
$adminUrl = $env:XBK_URL + "/admin" | |
while ($elapsed -lt $timeout) { | |
try { | |
$response = Invoke-WebRequest -Uri $adminUrl -UseBasicParsing | |
if ($response.StatusCode -eq 200) { | |
Write-Output "XbK is accessible" | |
break | |
} | |
else { | |
Write-Output "XbK status: $($response.StatusCode)" | |
} | |
} catch { | |
Write-Output "Waiting for XbK to be accessible..." | |
} | |
Start-Sleep -Seconds 5 | |
$elapsed += 5 | |
} | |
cd ${{ env.UMT_DIR }} | |
Write-Output "Running tests..." | |
mkdir reports | |
dotnet test --settings:test.runsettings --logger:"html;LogFileName=${{ env.UMT_DIR }}\reports\logFile.html" | |
- uses: actions/upload-artifact@v4 | |
if: ${{ !cancelled() }} | |
with: | |
name: playwright-report | |
path: ${{ env.UMT_DIR }}\reports\ | |
retention-days: 10 |