Skip to content

Commit

Permalink
converted to windows runner
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Medek authored and Martin Medek committed Nov 1, 2024
1 parent e7dca1f commit 4b96262
Showing 1 changed file with 89 additions and 39 deletions.
128 changes: 89 additions & 39 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,13 @@ on:

env:
XBK_DIR: ${{ github.workspace }}/../xbk
SA_PASSWORD: "Your_password123"
SA_PASSWORD: "asdfg12345!@#$%"
XBK_ADMIN_PASSWORD: "administrator"
LICENCE_FILE: "licence.txt"

jobs:
build:
runs-on: ubuntu-latest
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
SA_PASSWORD: ${{ env.SA_PASSWORD }}
ACCEPT_EULA: "Y"
ports:
- 1433:1433
options: >-
--health-cmd "exit 0"
--health-interval 10s
--health-timeout 5s
--health-retries 5
runs-on: windows-latest

steps:
# UMT setup
Expand All @@ -60,22 +47,81 @@ jobs:
with:
global-json-file: global.json

- name: Install dependencies
- name: Install dependencies and build
run: |
dotnet restore --locked-mode
dotnet tool restore
- name: Build Solution
- name: <DB> Install SQL Server
uses: Particular/[email protected]
with:
connection-string-env-var: SQL_SERVER_CONNECTION_STRING
catalog: kentico-boilerplate

- name: Install SQL Server Management Studio
run: |
choco install sql-server-management-studio -y
- name: <DB> Create Kentico DB user
run: |
sqlcmd -Q "CREATE LOGIN kentico WITH PASSWORD = '${{ env.SA_PASSWORD }}';
CREATE USER kentico FOR LOGIN kentico;
GO"
- name: <DB> Add kentico user to sysadmin role
run: |
dotnet build --configuration Release --no-restore
sqlcmd -Q "sp_addsrvrolemember 'kentico', 'sysadmin';
GO"
- name: <DB> Enable SQL authentication
run: |
Write-Output "SQL Server: Configuring Remote Access on SQL Server Express."
$assemblyList = 'Microsoft.SqlServer.Management.Common', 'Microsoft.SqlServer.Smo', 'Microsoft.SqlServer.SqlWmiManagement', 'Microsoft.SqlServer.SmoExtended'
foreach ($assembly in $assemblyList) {
$assembly = [System.Reflection.Assembly]::LoadWithPartialName($assembly)
}
$wmi = New-Object Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer # connects to localhost by default
$instance = $wmi.ServerInstances | Where-Object { $_.Name -eq 'SQLEXPRESS' }
$np = $instance.ServerProtocols | Where-Object { $_.Name -eq 'Np' }
$np.IsEnabled = $true
$np.Alter()
$tcp = $instance.ServerProtocols | Where-Object { $_.Name -eq 'Tcp' }
$tcp.IsEnabled = $true
$tcp.Alter()
$tcpIpAll = $tcp.IpAddresses | Where-Object { $_.Name -eq 'IpAll' }
$tcpDynamicPorts = $tcpIpAll.IpAddressProperties | Where-Object { $_.Name -eq 'TcpDynamicPorts' }
$tcpDynamicPorts.Value = ""
$tcp.Alter()
$tcpPort = $tcpIpAll.IpAddressProperties | Where-Object { $_.Name -eq 'TcpPort' }
$tcpPort.Value = "1433"
$tcp.Alter()
Write-Output "SQL Server: Setting Mixed Mode Authentication."
New-ItemProperty 'HKLM:\Software\Microsoft\Microsoft SQL Server\MSSQL16.SQLEXPRESS\MSSQLServer\' -Name 'LoginMode' -Value 2 -Force
- name: <DB> Restart SQL Server instance
run: |
Get-Service
Restart-Service -Name "MSSQL$SQLEXPRESS"
- name: <DB> Test SQL Server login as admin
run: |
sqlcmd -S ".\SQLEXPRESS" -U 'kentico' -P '${{ env.SA_PASSWORD }}' -Q "SELECT 'Login successful' AS Message"
# Xperience by Kentico setup
- name: <XbK> Install kentico templates
run: |
XBK_CORE_VERSION=$(grep -oP '(?<=<PackageVersion Include="Kentico.Xperience.Core" Version=")[^"]*' Directory.Packages.props)
echo "Kentico.Xperience.Core version: $XBK_CORE_VERSION"
$XBK_CORE_VERSION = Select-String -Path "Directory.Packages.props" -Pattern '<PackageVersion Include="Kentico.Xperience.Core" Version="([^"]*)"' | ForEach-Object { $_.Matches.Groups[1].Value }
mkdir $XBK_DIR
cd $DIR
mkdir $env:XBK_DIR
cd $env:XBK_DIR
dotnet new install Kentico.Xperience.Templates::$XBK_CORE_VERSION
- name: <XbK> Create Kentico Xperience project
Expand All @@ -86,23 +132,27 @@ jobs:
- name: <XbK> Run kentico dbmanager with license
working-directory: ${{ env.XBK_DIR }}
run: |
echo ${{ secrets.XPERIENCE_BY_KENTICO_LICENSE }} > $LICENCE_FILE
dotnet kentico-xperience-dbmanager -- -s "localhost" -d "pwtest" -u "sa" -p "$SA_PASSWORD" -a "$XBK_ADMIN_PASSWORD" --recreate-existing-database --hash-string-salt "<hash_string_salt>" --license-file "$LICENCE_FILE"
rm $LICENCE_FILE
echo ${{ secrets.XPERIENCE_BY_KENTICO_LICENSE }} > $env:LICENCE_FILE
Write-Output "SQL_SERVER_CONNECTION_STRING: $env:SQL_SERVER_CONNECTION_STRING"
dotnet kentico-xperience-dbmanager -- -s ".\SQLEXPRESS" -d "pwtest" -u "kentico" -p "$env:SA_PASSWORD" -a "$env:XBK_ADMIN_PASSWORD" --recreate-existing-database --hash-string-salt "<hash_string_salt>" --license-file "$LICENCE_FILE"
rm $env:LICENCE_FILE
- name: <XbK> Run kentico boilerplate
working-directory: ${{ env.XBK_DIR }}
run: |
nohup dotnet run &> nohup.out &
Start-Process -FilePath "dotnet" -ArgumentList "run" -RedirectStandardOutput "nohup.out" -NoNewWindow -PassThru
# Run example migration
- name: Prepare appsettings.json
- name: Prepare appsettings.json for migration
run: |
EXAMPLE_APPSETTINS="examples/Kentico.Xperience.UMT.Example.Console/appsettings.json"
CMS_CONNECTION_STRING=$(jq -r '.ConnectionStrings.CMSConnectionString' $XBK_DIR/appsettings.json)
jq ".ConnectionStrings.CMSConnectionString = \"$CMS_CONNECTION_STRING\" | .WebApplicationPhysicalPath = \"$XBK_DIR\"" $EXAMPLE_APPSETTINS > appsettings.json.tmp
mv appsettings.json.tmp $EXAMPLE_APPSETTINS
cat $EXAMPLE_APPSETTINS
$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: Run example migration
working-directory: ${{ github.workspace }}/examples/Kentico.Xperience.UMT.Example.Console
Expand All @@ -114,22 +164,22 @@ jobs:
working-directory: ${{ github.workspace }}/tests/Kentico.Xperience.UMT.Tests
run: |
dotnet build
pwsh bin/Debug/net8.0/playwright.ps1 install --with-deps
bin/Debug/net8.0/playwright.ps1 install --with-deps
- name: Replace BASE_URL in test.runsettings
run: |
cat $XBK_DIR/Properties/launchSettings.json
export BASE_URL=$(cat $XBK_DIR/Properties/launchSettings.json | jq -r '.profiles.kentico_boilerplate.applicationUrl')
sed -i -e "s|http://localhost:53798|$BASE_URL|g" test.runsettings # TODO: Replace with regex
Get-Content "$env:XBK_DIR/Properties/launchSettings.json"
$BASE_URL = (Get-Content "$env:XBK_DIR/Properties/launchSettings.json" | ConvertFrom-Json).profiles.kentico_boilerplate.applicationUrl
(Get-Content test.runsettings) -replace '<BASE_URL>([^<]*)</BASE_URL>', '<BASE_URL>asd</BASE_URL>' | Set-Content test.runsettings
- name: Print xbk output
run: |
cat $XBK_DIR/nohup.out
Get-Content $env:XBK_DIR/nohup.out
- name: run tests
run: |
xvfb-run dotnet test --settings:test.runsettings
dotnet test --settings:test.runsettings
- name: Stop XbK
run: |
pkill -f "dotnet"
Stop-Process -Name "dotnet" -Force

0 comments on commit 4b96262

Please sign in to comment.