Skip to content

Commit ff4a6aa

Browse files
authored
Transition to Github Runners instead of AppVeyor (#233)
1 parent 8ee1952 commit ff4a6aa

39 files changed

+589
-11723
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# These are supported funding model platforms
22

3-
github: LowlyDBA # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3+
github: lowlydba # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
44
patreon: # Replace with a single Patreon username
55
open_collective: # Replace with a single Open Collective username
66
ko_fi: # Replace with a single Ko-fi username
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "SQLCover"
2+
author: "lowlydba"
3+
branding:
4+
icon: "database"
5+
color: "purple"
6+
description: "Installs, starts, and stops SQLCover by GoEddie."
7+
inputs:
8+
sql-instance:
9+
description: "Target SQL instance. Only used by the 'start' action."
10+
required: false
11+
default: "localhost"
12+
database:
13+
description: "Target database."
14+
required: false
15+
default: "master"
16+
output-file:
17+
description: "File to output results to."
18+
required: false
19+
default: "cobertura.xml"
20+
runs:
21+
using: "composite"
22+
steps:
23+
- id: output
24+
shell: pwsh
25+
run: |
26+
$params = @{
27+
Database = "${{ inputs.database }}"
28+
SqlInstance = "${{ inputs.sql-instance }}"
29+
OutputFile = "${{ inputs.output-file }}"
30+
}
31+
32+
${{github.action_path}}\main.ps1 @params

.github/actions/sqlcover/main.ps1

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
param(
2+
[Parameter(Mandatory = $true)]
3+
[string]$Database,
4+
[Parameter(Mandatory = $true)]
5+
[string]$SqlInstance,
6+
[string]$Package = "GOEddie.SQLCover",
7+
[Parameter(Mandatory = $true)]
8+
[string]$OutputFile
9+
)
10+
11+
if ($Env:RUNNER_OS -ne "Windows") {
12+
Write-Error "This action only supported on Windows runners." -ErrorAction "Stop"
13+
}
14+
15+
# Install SQLCover
16+
Write-Output "Installing SQLCover."
17+
$null = Install-Package $Package -Force -Scope "CurrentUser"
18+
$NugetPath = (Get-Package $Package).Source | Convert-Path
19+
$SQLCoverRoot = Split-Path $NugetPath
20+
$SQLCoverDllPath = Join-Path $SQLCoverRoot "lib\SQLCover.dll"
21+
Add-Type -Path $SQLCoverDllPath
22+
23+
$connString = "server=$SqlInstance;Trusted_Connection=yes"
24+
$sqlCover = New-Object SQLCover.CodeCoverage($connString, $Database)
25+
$null = $sqlCover.Start()
26+
27+
# Run tests
28+
Invoke-Pester -Path ".\tests\*"
29+
30+
# Stop
31+
Write-Output "Stopping SQL Cover."
32+
$coverageResults = $sqlCover.Stop()
33+
34+
# Save results
35+
[xml]$coberturaXml = $coverageResults.Cobertura()
36+
$OutputFullPath = Join-Path -Path "." -ChildPath $OutputFile
37+
Write-Output "Saving Cobertura report to $OutputFullPath"
38+
39+
# Fix missing filename with best-effort value
40+
# https://github.com/GoEddie/SQLCover/issues/79
41+
foreach ($class in $coberturaXml.coverage.packages.package.classes.class) {
42+
$class.filename = $class.Name
43+
}
44+
$coberturaXml.Save($OutputFullPath)
45+
46+
# HTML artifact
47+
$HtmlFullPath = Join-Path -Path "." -ChildPath "coverage.html"
48+
Write-Output "Saving HTML report to $HtmlFullPath"
49+
Set-Content -Path $HtmlFullPath -Value $coverageResults.Html2() -Force
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1-
# TSQLLint Github Action
1+
# tSQLt Github Action
22

3-
This action runs [TSQLLint](https://git.io/JILDv) via a Github Action.
3+
This action installs [tSQLt](https://github.com/tSQLt-org/tSQLt) via a Github Action.
44

55
## Inputs
66

7-
### `file-dir-1`
7+
### `sqlinstance`
88

9-
**Required** First path to file or directory to lint.
9+
**Required** SQL Instance to install to.
1010

11-
### `file-dir-2`
11+
### `database`
1212

13-
**Required** Second path to file or directory to lint.
13+
**Required** Database to install to.
1414

15-
### `config`
15+
### `version`
1616

17-
**Optional** Location of a TSQLLint configuration file, otherwise defaults are used.
18-
19-
## Example usage
20-
21-
TBD
17+
**Optional** Version of tSQLt to install.

.github/actions/tsqlt/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# tSQLt
2+
3+
If intending to install on Azure SQL, version 1-0-5873-27393 or lower must be used. See <https://github.com/tSQLt-org/tSQLt/issues/70> for more information.

.github/actions/tsqlt/action.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: "tSQLt Installer"
2+
author: "lowlydba"
3+
branding:
4+
icon: "database"
5+
color: "blue"
6+
description: "Installs tSQLt."
7+
inputs:
8+
sql-instance:
9+
description: "Target SQL instance."
10+
required: false
11+
default: "localhost"
12+
database:
13+
description: "Target database to install to."
14+
required: false
15+
default: "master"
16+
user:
17+
description: "Optional user for SQL authentication."
18+
required: false
19+
password:
20+
description: "Optional password for SQL authentication."
21+
required: false
22+
version:
23+
description: "Version to install."
24+
required: false
25+
default: "latest"
26+
runs:
27+
using: "composite"
28+
steps:
29+
- shell: pwsh
30+
run: |
31+
$params = @{
32+
SqlInstance = "${{ inputs.sql-instance }}"
33+
Database = "${{ inputs.database }}"
34+
Version = "${{ inputs.version }}"
35+
User = "${{ inputs.user }}"
36+
Password = "${{ inputs.password }}"
37+
}
38+
39+
${{github.action_path}}/main.ps1 @params

.github/actions/tsqlt/main.ps1

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
param(
2+
[Parameter()]
3+
[string]$SqlInstance,
4+
[string]$Database,
5+
[string]$Version,
6+
[string]$TempDir = $Env:RUNNER_TEMP,
7+
[string]$User,
8+
[string]$Password
9+
)
10+
11+
$DownloadUrl = "http://tsqlt.org/download/tsqlt/?version=$Version"
12+
$zipFile = Join-Path $TempDir "tSQLt.zip"
13+
$zipFolder = Join-Path $TempDir "tSQLt"
14+
$CLRSecurityQuery = "
15+
/* Turn off CLR Strict for 2017+ fix */
16+
IF EXISTS (SELECT 1 FROM sys.configurations WHERE name = 'clr strict security')
17+
BEGIN
18+
EXEC sp_configure 'show advanced options', 1;
19+
RECONFIGURE;
20+
21+
EXEC sp_configure 'clr strict security', 0;
22+
RECONFIGURE;
23+
END
24+
GO"
25+
26+
try {
27+
Write-Output "Downloading $DownloadUrl"
28+
Invoke-WebRequest -Uri $DownloadUrl -OutFile $zipFile -ErrorAction Stop -UseBasicParsing
29+
Expand-Archive -Path $zipFile -DestinationPath $zipFolder -Force
30+
$installFile = (Get-ChildItem $zipFolder -Filter "tSQLt.class.sql").FullName
31+
$setupFile = (Get-ChildItem $zipFolder -Filter "PrepareServer.sql").FullName
32+
Write-Output "Download complete."
33+
}
34+
catch {
35+
Write-Error "Unable to download & extract tSQLt from '$DownloadUrl'. Ensure version is valid." -ErrorAction "Stop"
36+
}
37+
38+
if ($isMacOs) {
39+
Write-Output "Only Linux and Windows operation systems supported."
40+
}
41+
elseif ($IsLinux) {
42+
if ($User -and $Password) {
43+
sqlcmd -S $SqlInstance -d $Database -q $CLRSecurityQuery -U $User -P $Password
44+
sqlcmd -S $SqlInstance -d $Database -i $setupFile -U $User -P $Password
45+
sqlcmd -S $SqlInstance -d $Database -i $installFile -U $User -P $Password
46+
}
47+
else {
48+
sqlcmd -S $SqlInstance -d $Database -q $CLRSecurityQuery
49+
sqlcmd -S $SqlInstance -d $Database -i $setupFile
50+
sqlcmd -S $SqlInstance -d $Database -i $installFile
51+
}
52+
}
53+
elseif ($IsWindows) {
54+
$connSplat = @{
55+
ServerInstance = $SqlInstance
56+
}
57+
if ($User -and $Password) {
58+
$SecPass = ConvertTo-SecureString -String $Password -AsPlainText -Force
59+
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $SecPass
60+
$connSplat.add("Credential", $Credential)
61+
}
62+
63+
if (!(Get-SqlDatabase @connSplat -Name $Database)) {
64+
Write-Error "Database '$Database' not found." -ErrorAction "Stop"
65+
}
66+
Invoke-Sqlcmd @connSplat -Database $Database -Query $CLRSecurityQuery -OutputSqlErrors $true
67+
Invoke-Sqlcmd @connSplat -Database $Database -InputFile $setupFile -OutputSqlErrors $true
68+
Invoke-Sqlcmd @connSplat -Database $Database -InputFile $installFile -Verbose -OutputSqlErrors $true
69+
}
70+
71+
Write-Output "Installation completed."

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Set update schedule for GitHub Actions
2+
3+
version: 2
4+
updates:
5+
- package-ecosystem: "github-actions"
6+
directory: "/"
7+
schedule:
8+
# Check for updates to GitHub Actions every weekday
9+
interval: "daily"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
name: Unit Test (AzureSQL)
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- .vscode/*
10+
pull_request:
11+
paths-ignore:
12+
- .vscode/*
13+
14+
# Run CI once per day (at 06:00 UTC)
15+
schedule:
16+
- cron: "0 6 * * *"
17+
18+
# Cancel existing runs on new commits to a branch
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.ref }}
21+
cancel-in-progress: true
22+
23+
env:
24+
SQLINSTANCE: "localhost"
25+
DATABASE: "tsqlt"
26+
INSTALLER_FILE: "install_dba-multitool.sql"
27+
TSQLT_FILE: "run_tsqlt.sql"
28+
29+
jobs:
30+
integration:
31+
runs-on: ubuntu-latest
32+
name: azuresql
33+
defaults:
34+
run:
35+
shell: pwsh
36+
37+
steps:
38+
- name: Check out code
39+
uses: actions/[email protected]
40+
with:
41+
path: ""
42+
43+
- name: Create installer script
44+
run: |
45+
Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter "sp_*.sql" | Get-Content | Out-File $Env:INSTALLER_FILE -Encoding ascii
46+
Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Filter $Env:INSTALLER_FILE
47+
48+
- name: Create tsqlt runner script
49+
run: |
50+
New-Item -Path $Env:TSQLT_FILE -ItemType "File" -Value "EXEC tsqlt.RunAll;" -Force
51+
52+
- name: Install multitool
53+
uses: azure/[email protected]
54+
with:
55+
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
56+
sql-file: ${{ env.INSTALLER_FILE }}
57+
58+
- name: Run tSQLt tests
59+
uses: azure/[email protected]
60+
with:
61+
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
62+
sql-file: ${{ env.TSQLT_FILE }}
63+
64+
# Since database is re-used, assume tSQLt already exists in
65+
# Azure SQL database
66+
# - name: Install tSQLt
67+
# uses: ./.github/actions/tsqlt
68+
# with:
69+
# sql-instance: ${{ env.SQLINSTANCE }}
70+
# database: ${{ env.DATABASE }}
71+
# version: "latest"
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
name: Generate Bundled Installer
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
paths-ignore:
9+
- .vscode/*
10+
pull_request:
11+
paths-ignore:
12+
- .vscode/*
13+
14+
# Cancel existing runs on new commits to a branch
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
env:
20+
INSTALLER_FILE: "install_dba-multitool.sql"
21+
22+
jobs:
23+
bundle:
24+
runs-on: ubuntu-latest
25+
name: Create bundled installer script
26+
27+
steps:
28+
- name: Check out code
29+
uses: actions/[email protected]
30+
with:
31+
repository: ${{ github.event.pull_request.head.repo.full_name }}
32+
ref: ${{ github.event.pull_request.head.ref }}
33+
34+
- name: Create installer script
35+
shell: pwsh
36+
run: |
37+
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
39+
40+
- name: Commit bundled installer
41+
uses: stefanzweifel/[email protected]
42+
with:
43+
commit_message: Updated bundled installer
44+
file_pattern: "*.sql"

0 commit comments

Comments
 (0)