generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 0
197 lines (174 loc) · 6.29 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: "CI: Build and Test"
on:
push:
branches: [main, feat/automatic_E2E_testing]
# 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: 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: Install Azurite
id: azuright
uses: potatoqualitee/azuright@e56d2754eb15218d507961493bc83ca037216887 # set as a commit hash for security - v1.1
- 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
with:
name: playwright-report
path: ./tests/Playwright/playwright-report/
retention-days: 30