-
Notifications
You must be signed in to change notification settings - Fork 140
56 lines (56 loc) · 1.94 KB
/
build-sqlfile.yml
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
name: Format and Regenerate SQL Main File
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build-sql-file:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout Code
run: |
git config --global user.name 'Darling Data'
git config --global user.email 'erik@erikdarling.com'
git checkout
- name: Trim trailing whitespace and replace Tabs
shell: pwsh
run: |
$changedFiles = git --no-pager diff --name-only --relative --diff-filter=AM "${{ github.event.before }}" "${{ github.sha }}" -- '***.sql'
$tabSize = 4
$changedFiles | ForEach-Object {
$outputString = ""
$fullPath = $_
$Content = Get-Content $fullPath
foreach ($Ctnt in $Content) {
$CharArray = $Ctnt.ToCharArray()
$lineOutput = ""
$slidingOffset = 0
for ($charIdx = 0; $charIdx -lt $CharArray.Length; $charIdx++) {
if ($CharArray[$charIdx] -eq "`t") {
$currentTab = $tabSize - (($charIdx + $slidingOffset) % $tabSize)
$slidingOffset += $currentTab - 1
$lineOutput += (" " * $currentTab)
}
else {
$lineOutput += $CharArray[$charIdx]
}
}
$outputString += $lineOutput.TrimEnd() + "`n" # Add line output with trailing spaces removed to the output string, and add newline
}
Set-Content -Path $fullPath -Value ($outputString.TrimEnd())
}
- name: Compile SQL File
shell: pwsh
run: |
cd Install-All
./Merge-All.ps1
- name: Commit Updated File
run: |
git add .
git commit -am "Automation: Format and Build SQL File"
git push