Skip to content

Commit 2f048d9

Browse files
authored
Merge pull request #126 from LowlyDBA/development
Auto build sample documentation for sp_doc
2 parents ae5c585 + 4756db4 commit 2f048d9

File tree

10 files changed

+2361
-2274
lines changed

10 files changed

+2361
-2274
lines changed

appveyor/appveyor.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 1.1.{build}
1+
version: 1.2.{build}
22

33
pull_requests:
44
do_not_increment_build_number: false
@@ -17,7 +17,7 @@ environment:
1717
matrix:
1818
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
1919
MSSQL: SQL2019
20-
DB_INSTANCE: (local)\SQL2019
20+
DB_INSTANCE: localhost\SQL2019
2121
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_150
2222
LATEST: True
2323

@@ -34,28 +34,28 @@ environment:
3434

3535
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
3636
MSSQL: SQL2017
37-
DB_INSTANCE: (local)\SQL2017
37+
DB_INSTANCE: localhost\SQL2017
3838
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_140
3939
LATEST: False
4040
AzureSQL: False
4141

4242
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
4343
MSSQL: SQL2016
44-
DB_INSTANCE: (local)\SQL2016
44+
DB_INSTANCE: localhost\SQL2016
4545
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_130
4646
LATEST: False
4747
AzureSQL: False
4848

4949
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
5050
MSSQL: SQL2014
51-
DB_INSTANCE: (local)\SQL2014
51+
DB_INSTANCE: localhost\SQL2014
5252
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_120
5353
LATEST: False
5454
AzureSQL: False
5555

5656
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
5757
MSSQL: SQL2012SP1
58-
DB_INSTANCE: (local)\SQL2012SP1
58+
DB_INSTANCE: localhost\SQL2012SP1
5959
LINT_CONFIG: appveyor\tsqllint\.tsqllintrc_110
6060
LATEST: False
6161
AzureSQL: False
@@ -75,7 +75,7 @@ install:
7575
- ps: .\appveyor\install_tsqlt.ps1
7676

7777
build_script:
78-
- ps: .\appveyor\make_combined_script.ps1
78+
- ps: .\appveyor\generate_combined_script.ps1
7979
- ps: .\appveyor\install_expsql.ps1
8080
- ps: .\appveyor\build_tsqlt_tests.ps1
8181

@@ -85,7 +85,7 @@ test_script:
8585
- ps: .\appveyor\run_tsqlt_tests.ps1
8686

8787
for:
88-
# Latest SQL Server - Code cov & Upload
88+
# Latest SQL Server: Code cov & Upload
8989
-
9090
matrix:
9191
only:
@@ -99,12 +99,16 @@ for:
9999
test_script:
100100
- ps: .\appveyor\sqlcover\Run_SQLCover.ps1
101101

102+
# Build markdown w/ sp_doc
103+
after_test:
104+
- ps: .\appveyor\generate_sample_markdown.ps1
105+
102106
# Upload code coverage report, push generated files
103107
on_success:
104108
- codecov -f %COV_REPORT%
105109
- ps: .\appveyor\push_git_changes.ps1
106110

107-
# Azure SQL
111+
# Azure SQL: No need to start SQL Server locally
108112
-
109113
matrix:
110114
only:
@@ -113,15 +117,3 @@ for:
113117
install:
114118
- ps: .\appveyor\install_dependencies.ps1
115119
- ps: .\appveyor\install_tsqlt.ps1
116-
117-
# Setup codecov, SQL Cover
118-
#before_test:
119-
# - ps: .\appveyor\install_coverage_dependencies.ps1
120-
121-
# Run tests with SQL Cover analysis
122-
#test_script:
123-
# - ps: .\appveyor\sqlcover\Run_SQLCover.ps1
124-
125-
# Upload code coverage report, push generated files
126-
#on_success:
127-
# - codecov -f %COV_REPORT%
File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
param(
2+
[Parameter()]
3+
[string]$SqlInstance = $env:DB_INSTANCE,
4+
[string]$UtilityDatabase = $env:TARGET_DB,
5+
[bool]$IsAzureSQL = [System.Convert]::ToBoolean($env:AzureSQL),
6+
[string]$User = $env:AZURE_SQL_USER,
7+
[string]$Pass = $env:AZURE_SQL_PASS,
8+
[string]$Color = "Green"
9+
)
10+
11+
$ErrorActionPreference = "Stop";
12+
$Url = "https://github.com/Microsoft/sql-server-samples/releases/download/wide-world-importers-v1.0/WideWorldImporters-Full.bak"
13+
$BackupPath = "C:\WideWorldImporters-Full.bak"
14+
$SampleDatabase = "WideWorldImporters"
15+
$SampleMarkdown = "docs/$SampleDatabase.md"
16+
17+
Write-Host "Generating $SampleDatabase markdown sample..." -ForegroundColor $Color
18+
19+
# Suppress DbaTools warning about SqlServer module also being loaded
20+
Set-DbatoolsConfig -Name Import.SqlpsCheck -Value $false -PassThru | Register-DbatoolsConfig
21+
22+
# Download and restore WideWorldImporters sample database
23+
If (!(Get-DbaDatabase -SqlInstance $SqlInstance -Database $SampleDatabase)) {
24+
Invoke-WebRequest -Uri $Url -OutFile $BackupPath
25+
26+
If (Test-Path $BackupPath) { Restore-DbaDatabase -SqlInstance $SqlInstance -DatabaseName $SampleDatabase -Path $BackupPath -WithReplace | Out-Null }
27+
Else { Write-Error "$SampleDatabase backup failed to download properly." }
28+
}
29+
30+
# Generate documentation
31+
sqlcmd -S $SqlInstance -d $UtilityDatabase -Q "EXEC sp_doc @DatabaseName = '$SampleDatabase';" -o $SampleMarkdown -y 0
32+
33+
# Remove footer to avoid eternal appveyor build loop from file diffs
34+
$Temp = Get-Content $SampleMarkdown
35+
$Temp[0..($Temp.Length - 4)] | Out-File $SampleMarkdown -Encoding utf8

appveyor/install_dependencies.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ Write-Host "Installing dependencies..." -ForegroundColor $Color
1010
Try { npm install tsqllint -g | Out-Null }
1111
Catch { }
1212

13-
1413
# SQLServer Module
1514
if (!(Get-Module -ListAvailable -Name SqlServer)) {
1615
Install-Module SqlServer -Force -AllowClobber
17-
}
16+
}
17+
18+
# DbaTools Module
19+
Install-Module DbaTools -Force -AllowClobber

appveyor/install_expsql.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ param(
1010

1111
Write-Host "Installing ExpressSQL scripts..." -ForegroundColor $Color
1212

13+
$ErrorActionPreference = "Stop";
14+
1315
If ($IsAzureSQL) {
1416
Invoke-SqlCmd -ServerInstance $SqlInstance -Database $Database -InputFile "install_expsql.sql" -Username $User -Password $Pass
1517
}

0 commit comments

Comments
 (0)