Skip to content

Commit 6cc81cc

Browse files
authored
Tweak more github CI setup (#235)
1 parent 5cb75ca commit 6cc81cc

File tree

5 files changed

+105
-41
lines changed

5 files changed

+105
-41
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "MSSQL Sample Database"
2+
author: "lowlydba"
3+
branding:
4+
icon: "database"
5+
color: "red"
6+
description: "Restores a sample database to an instance."
7+
inputs:
8+
sql-instance:
9+
description: "Target SQL instance."
10+
required: false
11+
default: "localhost"
12+
database:
13+
description: "Sample database to download and restore."
14+
required: false
15+
default: "WideWorldImporters"
16+
runs:
17+
using: "composite"
18+
steps:
19+
- shell: pwsh
20+
id: "mssql-sample-database"
21+
run: |
22+
$params = @{
23+
Database = "${{ inputs.database }}"
24+
SqlInstance = "${{ inputs.sql-instance }}"
25+
}
26+
27+
${{ github.action_path }}\main.ps1 @params
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
param(
2+
[Parameter(Mandatory = $true)]
3+
[ValidateSet("WideWorldImporters")]
4+
[string]$Database,
5+
[Parameter(Mandatory = $true)]
6+
[string]$SqlInstance
7+
)
8+
9+
if ($Env:RUNNER_OS -ne "Windows") {
10+
Write-Error "This action only supported on Windows runners." -ErrorAction "Stop"
11+
}
12+
13+
14+
15+
if ($Database -eq "WideWorldImporters") {
16+
$BackupPath = Join-Path -Path $Env:RUNNER_TEMP -ChildPath "$Database.bak"
17+
$Uri = "https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak"
18+
$Documentation = "https://docs.microsoft.com/en-us/sql/samples/wide-world-importers-what-is"
19+
}
20+
21+
Write-Output "Thanks for using MSSQL Sample Database!"
22+
Write-Output "📃: $Documentation"
23+
Write-Output "-----"
24+
Write-Output "Downloading '$Database' to '$BackupPath' ..."
25+
Invoke-WebRequest -Uri $Uri -OutFile $BackupPath
26+
Write-Output "Restoring '$Database' ..."
27+
$null = Restore-DbaDatabase -SqlInstance $SqlInstance -DatabaseName $Database -Path $BackupPath -WithReplace -EnableException
28+
Get-DbaDatabase -SqlInstance $SqlInstance -Database $Database | Select-Object -Property Name, Status, SizeMB, SqlInstance

.github/actions/sqlcover/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ branding:
66
description: "Installs, starts, and stops SQLCover by GoEddie."
77
inputs:
88
sql-instance:
9-
description: "Target SQL instance. Only used by the 'start' action."
9+
description: "Target SQL instance."
1010
required: false
1111
default: "localhost"
1212
database:

.github/workflows/bundled-installer.yml renamed to .github/workflows/artifacts.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
name: Generate Bundled Installer
2+
name: Generate Installer Script
33
on:
44
workflow_dispatch:
55
push:
@@ -22,7 +22,10 @@ env:
2222
jobs:
2323
bundle:
2424
runs-on: ubuntu-latest
25-
name: Create bundled installer script
25+
name: Generate installer
26+
defaults:
27+
run:
28+
shell: pwsh
2629

2730
steps:
2831
- name: Check out code
@@ -31,14 +34,13 @@ jobs:
3134
repository: ${{ github.event.pull_request.head.repo.full_name }}
3235
ref: ${{ github.event.pull_request.head.ref }}
3336

34-
- name: Create installer script
35-
shell: pwsh
37+
- name: Create bundled installer script
3638
run: |
3739
Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter "sp_*.sql" | Get-Content | Out-File $Env:INSTALLER_FILE -Encoding ascii
38-
Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter $Env:INSTALLER_FILE
40+
Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter $Env:INSTALLER_FILE | Select-Object -Property Name, Size, LastWriteTime, User
3941
40-
- name: Commit bundled installer
42+
- name: Commit bundled installer script
4143
uses: stefanzweifel/[email protected]
4244
with:
4345
commit_message: Updated bundled installer
44-
file_pattern: "*.sql"
46+
file_pattern: ${{ env.INSTALLER_FILE }}

.github/workflows/sqlserver-unit.yml

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ on:
99
- main
1010
paths-ignore:
1111
- .vscode/*
12-
- '**.md'
12+
- "**.md"
1313
pull_request:
1414
paths-ignore:
1515
- .vscode/*
16-
- '**.md'
16+
- "**.md"
1717

1818
# Run CI once per day (at 06:00 UTC)
1919
schedule:
@@ -27,10 +27,9 @@ concurrency:
2727
env:
2828
SQLINSTANCE: "localhost"
2929
DATABASE: "tsqlt"
30-
INSTALLER_FILE: "install_dba-multitool.sql"
31-
SAMPLE_DATABASE: "WideWorldImporters"
32-
SP_DOC_FILE: "WideWorldImporters.md"
3330
COVERAGE_HTML_FILE: "coverage.html"
31+
COBERTURA_FILE: "cobertura.xml"
32+
SAMPLE_DATABASE: "WideWorldImporters"
3433

3534
jobs:
3635
integration:
@@ -52,6 +51,15 @@ jobs:
5251
ref: ${{ github.head_ref }}
5352

5453
- name: Install SQL Server
54+
continue-on-error: true
55+
id: mssqlsuite
56+
uses: potatoqualitee/[email protected]
57+
with:
58+
install: sqlengine
59+
sa-password: L0wlydb4
60+
61+
- name: Retry SQL Server install
62+
if: steps.mssqlsuite.outcome == 'failure'
5563
uses: potatoqualitee/[email protected]
5664
with:
5765
install: sqlengine
@@ -63,21 +71,18 @@ jobs:
6371
modules-to-cache: dbatools
6472
shell: powershell
6573

66-
- name: Create database
67-
run: |
68-
$null = New-DbaDatabase -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE
69-
7074
- name: Install tSQLt
7175
uses: lowlydba/tsqlt-installer@v1
7276
with:
7377
sql-instance: ${{ env.SQLINSTANCE }}
7478
database: ${{ env.DATABASE }}
7579
version: "latest"
80+
create: true
7681

7782
- name: Install multitool
7883
run: |
7984
foreach ($script in (Get-ChildItem -Path "." -Filter "sp_*.sql").Name) {
80-
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE -File $script
85+
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE -File $script -EnableException
8186
}
8287
8388
- name: Run Pester tests with SQLCover
@@ -86,38 +91,40 @@ jobs:
8691
sql-instance: ${{ env.SQLINSTANCE }}
8792
database: ${{ env.DATABASE }}
8893

94+
- name: Restore sample database
95+
uses: ./.github\actions\mssql-sample-db
96+
with:
97+
sql-instance: ${{ env.SQLINSTANCE }}
98+
database: ${{ env.SAMPLE_DATABASE }}
99+
100+
- name: Generate sp_doc sample
101+
env:
102+
SQL_VERSION: ${{ matrix.sql_server }}
103+
run: |
104+
Write-Output "Generating '$Env:SAMPLE_DATABASE' markdown sample."
105+
$Query = "EXEC sp_doc @DatabaseName = '$Env:SAMPLE_DATABASE';"
106+
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:DATABASE -Query $Query -As SingleValue -EnableException | Out-File "$($Env:SAMPLE_DATABASE)-$($Env:SQL_VERSION).md"
107+
108+
- name: Upload sp_doc sample artifact
109+
uses: actions/upload-artifact@v3
110+
with:
111+
name: sp_doc-sample
112+
path: "${{ env.SAMPLE_DATABASE }}-${{ matrix.sql_server}}.md"
113+
114+
# Only do cov report on latest SQL Server version
89115
- name: Produce the coverage report
90116
uses: insightsengineering/coverage-action@v2
117+
id: cov-report
118+
if: ${{ matrix.sql_server == 2019 }}
91119
with:
92-
path: "cobertura.xml"
120+
path: ${{ env.COBERTURA_FILE }}
93121
threshold: 90
94122
fail: false
95123
publish: true
96-
diff: true
97-
diff-branch: main
98-
99-
- name: Create sp_doc sample artifact
100-
run: |
101-
$Url = "https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak"
102-
$BackupPath = Join-Path -Path $Env:RUNNER_TEMP -ChildPath "$Env:SAMPLE_DATABASE-Full.bak"
103-
104-
Write-Output "Downloading $Env:SAMPLE_DATABASE."
105-
Invoke-WebRequest -Uri $Url -OutFile $BackupPath
106-
$null = Restore-DbaDatabase -SqlInstance $Env:SQLINSTANCE -DatabaseName $Env:SAMPLE_DATABASE -Path $BackupPath -WithReplace
107-
108-
Write-Output "Generating $Env:SAMPLE_DATABASE markdown sample."
109-
$Query = "EXEC sp_doc @DatabaseName = '$Env:SAMPLE_DATABASE';"
110-
Invoke-DbaQuery -SqlInstance $Env:SQLINSTANCE -Database $Env:Database -Query $Query -As SingleValue | Out-File $Env:SP_DOC_FILE
111-
Get-ChildItem -Path "." -Filter $Env:SP_DOC_FILE
112124

113125
- name: Upload HTML coverage artifact
114126
uses: actions/upload-artifact@v3
127+
if: steps.cov-report.outcome == 'success'
115128
with:
116129
name: html-coverage
117130
path: ${{ env.COVERAGE_HTML_FILE }}
118-
119-
- name: Upload sp_doc sample artifact
120-
uses: actions/upload-artifact@v3
121-
with:
122-
name: sp_doc-sample
123-
path: ${{ env.SP_DOC_FILE }}

0 commit comments

Comments
 (0)