Skip to content

Commit

Permalink
Merge pull request #179 from LowlyDBA/development
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlydba authored Dec 18, 2020
2 parents fb04d3f + ab83e6e commit 7ce0bad
Show file tree
Hide file tree
Showing 22 changed files with 2,216 additions and 1,180 deletions.
2 changes: 1 addition & 1 deletion .github/linter-conf/.markdown-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ MD013:
tables: false
MD024: false
MD033:
allowed_elements: ["details", "summary", "img", "sub"]
allowed_elements: ["details", "summary", "img", "sub", "br"]



17 changes: 17 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"markdownlint.config": {
"MD024": false,
"MD010": {
"code_blocks": false
},
"MD033": {
"allowed_elements": ["details", "summary", "img", "sub", "br"]
},
"MD013": {
"code_blocks": false,
"tables": false
}
},
"powershell.codeFormatting.trimWhitespaceAroundPipe": true,
"powershell.codeFormatting.useCorrectCasing": true
}
18 changes: 9 additions & 9 deletions appveyor/appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pull_requests:
do_not_increment_build_number: false
max_jobs: 2
build: off
skip_commits:
author: Appveyor
# skip_commits:
# author: Appveyor

environment:
access_token:
secure: 'E5I+i+CQyj9EHusDrPSQKHRXmzmpTujYAoFxlvJjvSRSEQHHzqTBIFR1VuPbwLMi'
AZURE_SQL_PASS:
secure: 'rYm3nE1kwpbdE7QtyLb8CjvA1ENjY3usz3Qqskf1TXU='

CI_COMMIT_MSG: 'CI produced files'
APPVEYOR_RDP_PASSWORD: Np^VNSzJI5#OmRdUNqro2T9UVkCdZ
TARGET_DB: tSQLt
COV_REPORT: appveyor\sqlcover\Coverage.opencoverxml
Expand Down Expand Up @@ -68,10 +68,10 @@ clone_script:
- cd %APPVEYOR_BUILD_FOLDER%

install:
- ps: Install-Product node ''
- ps: .\appveyor\install_dependencies.ps1
- ps: .\appveyor\start_sqlserver.ps1
- ps: .\appveyor\install_tsqlt.ps1
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

# Non-covered test run
test_script:
Expand All @@ -86,21 +86,21 @@ for:

# Setup codecov, SQL Cover
before_test:
- ps: .\appveyor\install_dependencies.ps1 -CodeCoverage
- ps: .\appveyor\install_dependencies.ps1 -CodeCoverageOnly

# Run tests with SQL Cover analysis
test_script:
- ps: .\appveyor\run_pester_tests.ps1 -CodeCoverage

# Build markdown w/ sp_doc
# Build markdown with sp_doc
# Upload code coverage report, push generated files
after_test:
- ps: .\appveyor\generate_sample_markdown.ps1

# Upload code coverage report, push generated files
on_success:
- codecov -f %COV_REPORT%
- ps: .\appveyor\push_git_changes.ps1

# on_finish:

# Azure SQL: No need to start SQL Server locally
-
matrix:
Expand Down
2 changes: 1 addition & 1 deletion appveyor/generate_sample_markdown.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ Invoke-DbaQuery -SqlInstance $SqlInstance -Database $UtilityDatabase -Query $Que

# Remove footer to avoid eternal appveyor build loop from file diffs
$Temp = Get-Content $SampleMarkdown
$Temp[0..($Temp.Length - 4)] | Out-File $SampleMarkdown -Encoding utf8
$Temp[0..($Temp.Length - 4)] | Out-File $SampleMarkdown -Encoding ascii
52 changes: 28 additions & 24 deletions appveyor/install_dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,15 @@

param(
[Parameter()]
[switch]$CodeCoverage,
[switch]$CodeCoverageOnly,
$Color = "Green"
)

Write-Host "Installing dependencies..." -ForegroundColor $Color

# DbaTools
if (!(Get-Module -ListAvailable -Name DbaTools)) {
$DbaToolsJob = Start-Job -ScriptBlock { Install-Module DbaTools -Force -AllowClobber }
}

# Pester
if (!(Get-InstalledModule -Name Pester -MinimumVersion 5.0.0 -ErrorAction SilentlyContinue)) {
Install-Module Pester -Force -AllowClobber -WarningAction SilentlyContinue -SkipPublisherCheck -MinimumVersion 5.0.0
}

if (!(Get-Module -Name Pester | Where-Object { $PSItem.Version -lt 5.0.0 })) {
if (Get-Module -Name Pester) {
Remove-Module Pester -Force
}
Import-Module Pester -MinimumVersion 4.0.0
}
if ($CodeCoverageOnly.IsPresent) {
Write-Host "Installing code coverage tool..." -ForegroundColor $Color

# GoEddie SQLCover
If ($CodeCoverage.IsPresent) {
# Install code coverage tool
# GoEddie SQLCover
If (!(Get-Package -Name GOEddie.SQLCover -ErrorAction SilentlyContinue)) {
Install-Package GOEddie.SQLCover -Force | Out-Null
}
Expand All @@ -37,6 +20,27 @@ If ($CodeCoverage.IsPresent) {
choco install codecov --no-progress --limit-output | Out-Null
}

If ($DbaToolsJob) {
Wait-Job $DbaToolsJob.Id | Out-Null
}
else {
Write-Host "Installing dependencies..." -ForegroundColor $Color

# DbaTools
if (!(Get-Module -ListAvailable -Name DbaTools)) {
$DbaToolsJob = Start-Job -ScriptBlock { Install-Module DbaTools -Force -AllowClobber }
}

# Pester
if (!(Get-InstalledModule -Name Pester -MaximumVersion 5.1.9 -ErrorAction SilentlyContinue)) {
Install-Module Pester -Force -AllowClobber -WarningAction SilentlyContinue -SkipPublisherCheck -MaximumVersion 5.1.9
}

if (!(Get-Module -Name Pester | Where-Object { $PSItem.Version -lt 5.1.0 })) {
if (Get-Module -Name Pester) {
Remove-Module Pester -Force
}
Import-Module Pester -MaximumVersion 5.1.9 -Force
}

If ($DbaToolsJob) {
Wait-Job $DbaToolsJob.Id | Out-Null
}
}
44 changes: 22 additions & 22 deletions appveyor/install_tsqlt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ param(

Write-Host "Downloading and installing tSQLt..." -ForegroundColor $Color

# BaseUrl gets the latest version by default - blocked by https://github.com/LowlyDBA/dba-multitool/issues/165
$Version = "1-0-5873-27393"
$DownloadUrl = "http://tsqlt.org/download/tsqlt/?version=" + $Version
$DownloadUrl = "http://tsqlt.org/download/tsqlt/?version="
$TempPath = [System.IO.Path]::GetTempPath()
$ZipFile = Join-Path $TempPath "tSQLt.zip"
$ZipFolder = Join-Path $TempPath "tSQLt"
#$SetupFile = Join-Path $ZipFolder "PrepareServer.sql" # Used in latest version after 1.0.5873.27393
$SetupFile = Join-Path $ZipFolder "SetClrEnabled.sql"
$InstallFile = Join-Path $ZipFolder "tSQLt.class.sql"
$CreateDbQuery = "CREATE DATABASE [tSQLt];"
$SetupFile = Join-Path $ZipFolder "PrepareServer.sql"
$CLRSecurityQuery = "
/* Turn off CLR Strict for 2017+ fix */
IF EXISTS (SELECT 1 FROM sys.configurations WHERE name = 'clr strict security')
Expand All @@ -36,36 +32,40 @@ BEGIN
END
GO"


# Download
Try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipFile -ErrorAction Stop -UseBasicParsing
Expand-Archive -Path $ZipFile -DestinationPath $ZipFolder -Force
}

Catch {
Write-Error -Message "Error downloading tSQLt - try manually fetching from $DownloadUrl"
}

$Hash = @{
SqlInstance = $SqlInstance
Database = $Database
EnableException = $true
}

# Setup
# Cant use latest for AzureSQL yet
# https://github.com/LowlyDBA/dba-multitool/issues/165
If ($IsAzureSQL) {
$Version = "1-0-5873-27393"
$DownloadUrl = $DownloadUrl + $Version

# Azure creds
$SecPass = ConvertTo-SecureString -String $Pass -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $SecPass
$Hash.add("SqlCredential", $Credential)
}

Else {
Invoke-DbaQuery -SqlInstance $SqlInstance -Database "master" -Query $CreateDbQuery
# DbaQuery doesn't play nice with the setup script GOs - default back to sqlcmd
# Download
Try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $ZipFile -ErrorAction Stop -UseBasicParsing
Expand-Archive -Path $ZipFile -DestinationPath $ZipFolder -Force
}

Catch {
Write-Error -Message "Error downloading tSQLt - try manually fetching from $DownloadUrl"
}

# Prep
If (-not $IsAzureSQL) {
New-DbaDatabase -SqlInstance $SqlInstance -Database $Database -Recoverymodel Simple | Out-Null
Invoke-Command -ScriptBlock { sqlcmd -S $SqlInstance -d $Database -i $SetupFile } | Out-Null
Invoke-DbaQuery @Hash -Query $CLRSecurityQuery
}

# Install
Invoke-DbaQuery @Hash -File $InstallFile
Invoke-DbaQuery @Hash -File $InstallFile -Verbose
2 changes: 1 addition & 1 deletion appveyor/push_git_changes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ $StagedFiles = git diff --staged

# Commit & push if stated
If ($StagedFiles) {
git commit -a -m "CI produced files" -q
git commit -a -m $env:CI_COMMIT_MSG -q
git push origin $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH -f -q
}
28 changes: 13 additions & 15 deletions appveyor/run_pester_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ $TestFiles = Get-ChildItem -Path .\tests\*.Tests.ps1
$FailedTests = 0

function Start-CodeCoverage {
param(
[string]$SqlInstance,
[string]$Database,
[string]$User,
[string]$Pass,
[bool]$IsAzureSQL,
[System.ConsoleColor]$Color
)
param(
[string]$SqlInstance,
[string]$Database,
[string]$User,
[string]$Pass,
[bool]$IsAzureSQL,
[System.ConsoleColor]$Color
)

# Setup vars
$ConnString = "server=$SqlInstance;initial catalog=$Database;Trusted_Connection=yes"
If ($IsAzureSQL) {
Expand All @@ -52,10 +53,10 @@ param(
}

function Complete-CodeCoverage {
param (
[string]$CoverageXMLPath,
[string]$Color
)
param (
[string]$CoverageXMLPath,
[string]$Color
)
# Stop covering
Write-Host "Stopping SQLCover..." -ForegroundColor $Color
$coverageResults = $global:SQLCover.Stop()
Expand Down Expand Up @@ -91,9 +92,6 @@ If ($CodeCoverage.IsPresent) {
Start-CodeCoverage @Hash
}

# Generate all-in-one installer script
Get-ChildItem -Path ".\" -Filter "sp_*.sql" | Get-Content | Out-File $InstallerFile -Encoding utf8

# Run Tests
ForEach ($file in $TestFiles) {
If (!$LocalTest.IsPresent) { Add-AppveyorTest -Name $file.BaseName -Framework NUnit -Filename $file.FullName -Outcome Running }
Expand Down
Loading

0 comments on commit 7ce0bad

Please sign in to comment.