Skip to content

Merge pull request #764 from erikdarlingdata/dev #2017

Merge pull request #764 from erikdarlingdata/dev

Merge pull request #764 from erikdarlingdata/dev #2017

Workflow file for this run

name: Format and Regenerate SQL Main File
on:
push:
branches:
- main
permissions:
contents: write
jobs:
build-sql-file:
runs-on: ubuntu-latest
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Configure Git
run: |
git config --global user.name 'Darling Data'
git config --global user.email 'erik@erikdarling.com'
- 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 and Push
run: |
git add .
git diff --staged --quiet && echo "No changes to commit" && exit 0
git commit -m "Automation: Format and Build SQL File [skip ci]"
git push