-
Notifications
You must be signed in to change notification settings - Fork 2
259 lines (209 loc) · 9.6 KB
/
Copy pathrelease.yml
File metadata and controls
259 lines (209 loc) · 9.6 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: Create Release Artifacts
on:
push:
tags:
- 'v*.*.*'
jobs:
build-and-release:
runs-on: windows-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup MSBuild
uses: microsoft/setup-msbuild@v2
- name: Setup NuGet
uses: nuget/setup-nuget@v2
- name: Restore NuGet packages
run: nuget restore FastWrappers-TSQL.sln
- name: Build SQL Project
run: msbuild FastWrappers_TSQL.sqlproj /p:Configuration=Release /p:Platform="Any CPU" /t:Build
- name: Verify Build Artifacts
shell: powershell
run: |
Write-Host "Checking for build output..."
if (Test-Path "bin") {
Get-ChildItem -Path "bin" -Recurse -File | Format-Table FullName, Length
} else {
Write-Host "bin folder does not exist!"
}
# Check for DACPAC in bin\Output (SQL Projects output here)
$dacpacPath = "bin\Output\FastWrappers_TSQL.dacpac"
if (Test-Path $dacpacPath) {
Write-Host "DACPAC found at: $dacpacPath"
} else {
Write-Host "DACPAC not found at: $dacpacPath"
Write-Host "Looking for .dacpac files..."
Get-ChildItem -Path . -Filter "*.dacpac" -Recurse -ErrorAction SilentlyContinue | Format-Table FullName
exit 1
}
- name: Setup SQL Server (LocalDB)
shell: powershell
run: |
# Ensure SQL LocalDB instance exists
sqllocaldb info MSSQLLocalDB > $null 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "MSSQLLocalDB instance not found. Creating..."
sqllocaldb create MSSQLLocalDB
} else {
Write-Host "MSSQLLocalDB instance already exists."
}
# Ensure SQL LocalDB is started
sqllocaldb start MSSQLLocalDB
# Wait for SQL Server to be ready
Start-Sleep -Seconds 10
- name: Deploy Database and Create Artifacts
shell: powershell
run: |
# Variables
$serverInstance = "(localdb)\MSSQLLocalDB"
$dbName = "FastWrappers-TSQL"
$dacpacPath = "bin\Output\FastWrappers_TSQL.dacpac"
$outputDir = "bin\Release"
$bakPath = "$outputDir\FastWrappers-TSQL.bak"
$generatedSqlPath = "$outputDir\FastWrappers-TSQL.sql"
$templateSqlPath = "FastWrappers-TSQL.sql"
# Ensure output directory exists
if (!(Test-Path $outputDir)) {
Write-Host "Creating $outputDir directory..."
New-Item -Path $outputDir -ItemType Directory -Force | Out-Null
}
# Verify DACPAC exists
if (!(Test-Path $dacpacPath)) {
Write-Error "DACPAC not found at: $dacpacPath"
exit 1
}
# Download SqlPackage if needed
if (!(Test-Path "SqlPackage\SqlPackage.exe")) {
Write-Host "Downloading SqlPackage..."
Invoke-WebRequest -Uri "https://aka.ms/sqlpackage-windows" -OutFile "SqlPackage.zip"
Expand-Archive -Path "SqlPackage.zip" -DestinationPath "SqlPackage" -Force
Remove-Item "SqlPackage.zip"
}
$sqlPackage = "SqlPackage\SqlPackage.exe"
# Deploy the DACPAC to create the database
Write-Host "Deploying DACPAC to create database..."
& $sqlPackage /Action:Publish /SourceFile:$dacpacPath /TargetServerName:$serverInstance /TargetDatabaseName:$dbName /p:IncludeCompositeObjects=True
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to deploy DACPAC"
exit 1
}
# Wait for deployment to complete
Start-Sleep -Seconds 5
# Test the assembly
Write-Host "Testing assembly..."
$testResult = sqlcmd -S $serverInstance -d $dbName -Q "SELECT dbo.EncryptString('test') AS Result" 2>&1
if ($LASTEXITCODE -eq 0) {
Write-Host "Assembly test successful!"
Write-Host $testResult
} else {
Write-Warning "Assembly test failed: $testResult"
Write-Warning "Continuing with artifact creation..."
}
# Create backup file
Write-Host "Creating SQL Server backup..."
$bakFullPath = Join-Path $PWD $bakPath
sqlcmd -S $serverInstance -Q "BACKUP DATABASE [$dbName] TO DISK = N'$bakFullPath' WITH STATS = 10"
if ($LASTEXITCODE -ne 0) {
Write-Warning "Failed to create BAK file, continuing..."
}
# Generate SQL script with current assembly binary
Write-Host "Generating SQL script with assembly binary..."
# Extract assembly binary from deployed database using SqlClient (no size limitations)
$connectionString = "Server=$serverInstance;Database=$dbName;Integrated Security=True;TrustServerCertificate=True;"
$connection = New-Object System.Data.SqlClient.SqlConnection($connectionString)
$connection.Open()
$command = $connection.CreateCommand()
$command.CommandText = "SELECT content FROM sys.assembly_files WHERE assembly_id = (SELECT assembly_id FROM sys.assemblies WHERE name = 'FastWrappers_TSQL')"
$reader = $command.ExecuteReader()
$assemblyHex = $null
if ($reader.Read()) {
$bytes = $reader.GetSqlBytes(0).Value
$hexString = [System.BitConverter]::ToString($bytes) -replace '-',''
$assemblyHex = "0x$hexString"
Write-Host "Assembly binary extracted (length: $($assemblyHex.Length) chars, $($bytes.Length) bytes)"
}
$reader.Close()
$connection.Close()
if ($assemblyHex) {
# Read template and inject assembly binary
$sqlTemplate = Get-Content $templateSqlPath -Raw
$finalSql = $sqlTemplate -replace '__ASSEMBLY_FROM_0X__', $assemblyHex
$finalSql | Out-File -FilePath $generatedSqlPath -Encoding UTF8
Write-Host "SQL script generated successfully"
} else {
Write-Warning "Failed to extract assembly binary"
}
# List all created artifacts
Write-Host "`nCreated artifacts:"
Get-ChildItem -Path $outputDir -File | Format-Table Name, Length
Write-Host "All artifacts processing completed!"
- name: Get version from tag
id: get_version
shell: bash
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Prepare Release Files
shell: powershell
run: |
# Create a release directory with all available artifacts
New-Item -Path "release" -ItemType Directory -Force | Out-Null
# Copy available files
$files = @(
@{Source="bin\Release\FastWrappers-TSQL.bak"; Name="FastWrappers-TSQL.bak"},
@{Source="bin\Release\FastWrappers-TSQL.sql"; Name="FastWrappers-TSQL.sql"}
)
foreach ($file in $files) {
if (Test-Path $file.Source) {
Copy-Item $file.Source "release\$($file.Name)" -Force
Write-Host "Copied $($file.Name)"
} else {
Write-Warning "$($file.Name) not found, skipping"
}
}
Write-Host "`nRelease files:"
Get-ChildItem -Path "release" | Format-Table Name, Length
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
name: Release v${{ steps.get_version.outputs.VERSION }}
body: |
## FastWrappers-TSQL v${{ steps.get_version.outputs.VERSION }}
### Installation Files
- **FastWrappers-TSQL.bak** - SQL Server Backup (restore using SSMS)
- **FastWrappers-TSQL.sql** - SQL Script (execute using sqlcmd or SSMS)
### Installation
**Option 1: Restore from backup (.bak file)**
```sql
-- Restore database
RESTORE DATABASE [FastWrappers-TSQL] FROM DISK = 'FastWrappers-TSQL.bak';
GO
-- Enable TRUSTWORTHY and CLR
ALTER DATABASE [FastWrappers-TSQL] SET TRUSTWORTHY ON;
GO
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'clr enabled', 1;
RECONFIGURE;
GO
-- IMPORTANT: Change database owner to 'sa'
-- Required for signed UNSAFE assemblies to load properly
USE [FastWrappers-TSQL];
GO
EXEC sp_changedbowner 'sa';
GO
-- Test
SELECT dbo.EncryptString('test');
```
**Option 2: Execute SQL Script (.sql file)**
```sql
-- Simply execute the script in SSMS or using sqlcmd
sqlcmd -S YourServer -i FastWrappers-TSQL.sql
```
### Usage
See [README.md](https://github.com/${{ github.repository }}/blob/main/README.md) for examples.
files: |
release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}