This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Notes: | |
| # - Pull request workflows creates and validate DBmaestro packages. | |
| # - Windows shell runner executes native PowerShell for every job. | |
| # Pull request to Release_Source branch will create package with a names derived from the changed folders/files. | |
| # Execution order will be alphabetical by package name. | |
| # PR merge will trigger upgrade to RS with workflow 'upgrade-environment.yml' | |
| name: Git - Build Package | |
| # on: | |
| # pull_request: | |
| # branches: | |
| # - Release_Source | |
| env: | |
| GIT_DEPTH: 1 | |
| AGENT_JAR: "C:\\Program Files (x86)\\DBmaestro\\DOP Server\\Agent\\DBmaestroAgent.jar" | |
| PROJECT_NAME: "Demo-PSQL" | |
| DBMAESTRO_USE_SSL: "True" | |
| DBMAESTRO_SERVER: "${{ vars.DBMAESTRO_SERVER }}" | |
| DBMAESTRO_AUTH_TYPE: "DBmaestroAccount" | |
| DBMAESTRO_USER: "${{ secrets.DBMAESTRO_USER }}" | |
| DBMAESTRO_PASSWORD: "${{ secrets.DBMAESTRO_PASSWORD }}" | |
| jobs: | |
| # This job detects changed packages by comparing with the base branch | |
| detect_changed_packages: | |
| name: Detect Changed Packages | |
| runs-on: self-hosted | |
| outputs: | |
| matrix: ${{ steps.set-matrix.outputs.matrix }} | |
| has-packages: ${{ steps.set-matrix.outputs.has-packages }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Detect Changed Folders in packages/ | |
| id: set-matrix | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| # Get the list of changed files | |
| $changedFiles = git diff --name-only origin/${{ github.base_ref }} HEAD | |
| # Extract unique package folders (first directory under packages/) | |
| $packages = @() | |
| foreach ($file in $changedFiles) { | |
| if ($file -match '^packages/([^/]+)') { | |
| $packageName = $matches[1] | |
| if ($packageName -notin $packages) { | |
| $packages += $packageName | |
| } | |
| } | |
| } | |
| if ($packages.Count -eq 0) { | |
| Write-Host "No changes in packages/ folder detected" | |
| $matrix = @([PSCustomObject]@{package = ""}) | |
| Add-Content -Path $env:GITHUB_OUTPUT -Value "has-packages=false" | |
| } else { | |
| Write-Host "Detected changed packages: $($packages -join ', ')" | |
| $matrix = $packages | Sort-Object | ForEach-Object { [PSCustomObject]@{package = $_} } | |
| Add-Content -Path $env:GITHUB_OUTPUT -Value "has-packages=true" | |
| } | |
| # Convert to JSON array (compatible with PowerShell 5.1) | |
| # Ensure we always get an array format for the matrix | |
| if (@($matrix).Count -eq 1) { | |
| $matrixJson = @($matrix) | ConvertTo-Json -Compress | |
| $matrixJson = "[$matrixJson]" | |
| } else { | |
| $matrixJson = @($matrix) | ConvertTo-Json -Compress | |
| } | |
| Write-Host "matrix=$matrixJson" | |
| Add-Content -Path $env:GITHUB_OUTPUT -Value "matrix=$matrixJson" | |
| create_package: | |
| name: Create Package | |
| runs-on: self-hosted | |
| needs: detect_changed_packages | |
| if: needs.detect_changed_packages.outputs.has-packages == 'true' | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| item: ${{ fromJson(needs.detect_changed_packages.outputs.matrix) }} | |
| env: | |
| PACKAGE_NAME: ${{ matrix.item.package }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Summary | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| $summary = @" | |
| ## :package: Package Creation Summary | |
| | Property | Value | | |
| |----------|-------| | |
| | **Package Name** | $env:PACKAGE_NAME | | |
| | **Project Name** | $env:PROJECT_NAME | | |
| | **Target Branch** | ${{ github.base_ref }} | | |
| | **PR Number** | ${{ github.event.pull_request.number }} | | |
| | **Created By** | ${{ github.actor }} | | |
| "@ | |
| Write-Host $summary | |
| Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value $summary | |
| - name: Create Package | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| # ===== Create Package ===== | |
| Write-Host "==== Branch name: $env:PACKAGE_NAME ====" | |
| Write-Host "==== Target branch: ${{ github.base_ref }} ====" | |
| Write-Host "==== PR Number: ${{ github.event.pull_request.number }} ====" | |
| if (-not (Test-Path -Path ("packages\" + $env:PACKAGE_NAME) -PathType Container)) { | |
| Write-Host "==== Folder $env:PACKAGE_NAME does not exist. ====" | |
| exit 1 | |
| } else { | |
| Write-Host "==== Found folder: $env:PACKAGE_NAME ====" | |
| } | |
| Write-Host "==== Creating manifest for package $env:PACKAGE_NAME ====" | |
| & java -jar "$env:AGENT_JAR" -CreateManifestFile ` | |
| -PathToScriptsFolder "packages\$env:PACKAGE_NAME" ` | |
| -Operation "CreateOrUpdate" ` | |
| -PackageType "Regular" | |
| Write-Host "==== Creating tar archive from $env:PACKAGE_NAME ====" | |
| Push-Location "packages\$env:PACKAGE_NAME" | |
| tar -czf "..\..\$env:PACKAGE_NAME.tar.gz" * | |
| Pop-Location | |
| Write-Host "==== Create package $env:PACKAGE_NAME ====" | |
| & java -jar "$env:AGENT_JAR" -Package ` | |
| -ProjectName "$env:PROJECT_NAME" ` | |
| -IgnoreScriptWarnings True ` | |
| -FilePath ($env:PACKAGE_NAME + ".tar.gz") ` | |
| -Server "$env:DBMAESTRO_SERVER" ` | |
| -UseSSL "$env:DBMAESTRO_USE_SSL" ` | |
| -AuthType "$env:DBMAESTRO_AUTH_TYPE" ` | |
| -UserName "$env:DBMAESTRO_USER" ` | |
| -Password "$env:DBMAESTRO_PASSWORD" | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "==== Failed to create package ====" | |
| exit 1 | |
| } | |
| Write-Host "==== Create package completed successfully ====" | |
| - name: Comment on PR - Package Created | |
| if: success() | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| $headers = @{ | |
| Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}" | |
| Accept = "application/vnd.github.v3+json" | |
| } | |
| $body = @{ | |
| body = ":white_check_mark: **Package Created Successfully**`n`nPackage Name: **$env:PACKAGE_NAME**`n`nReady for precheck validation." | |
| } | ConvertTo-Json | |
| $api = "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | |
| Invoke-RestMethod -Uri $api -Headers $headers -Method Post -Body $body -ContentType "application/json" | |
| - name: Comment on PR - Package Creation Failed | |
| if: failure() | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| $headers = @{ | |
| Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}" | |
| Accept = "application/vnd.github.v3+json" | |
| } | |
| $body = @{ | |
| body = ":x: **Package Creation Failed**`n`nPackage Name: **$env:PACKAGE_NAME**`n`nPlease check the logs for details." | |
| } | ConvertTo-Json | |
| $api = "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | |
| Invoke-RestMethod -Uri $api -Headers $headers -Method Post -Body $body -ContentType "application/json" | |
| precheck: | |
| name: Precheck Package | |
| runs-on: self-hosted | |
| needs: [detect_changed_packages, create_package] | |
| if: needs.detect_changed_packages.outputs.has-packages == 'true' | |
| strategy: | |
| max-parallel: 1 | |
| matrix: | |
| item: ${{ fromJson(needs.detect_changed_packages.outputs.matrix) }} | |
| env: | |
| PACKAGE_NAME: ${{ matrix.item.package }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Precheck Package | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| # ===== Precheck Package ===== | |
| Write-Host "==== Pre-Checking package $env:PACKAGE_NAME... ====" | |
| & java -jar "$env:AGENT_JAR" -PreCheck ` | |
| -ProjectName "$env:PROJECT_NAME" ` | |
| -PackageName "$env:PACKAGE_NAME" ` | |
| -Server "$env:DBMAESTRO_SERVER" ` | |
| -UseSSL "$env:DBMAESTRO_USE_SSL" ` | |
| -AuthType "$env:DBMAESTRO_AUTH_TYPE" ` | |
| -UserName "$env:DBMAESTRO_USER" ` | |
| -Password "$env:DBMAESTRO_PASSWORD" | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "==== Precheck failed ====" | |
| exit 1 | |
| } | |
| Write-Host "==== Precheck completed successfully ====" | |
| - name: Comment on PR - Precheck Passed | |
| if: success() | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| $headers = @{ | |
| Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}" | |
| Accept = "application/vnd.github.v3+json" | |
| } | |
| $body = @{ | |
| body = ":white_check_mark: **Precheck Validation Passed**`n`nPackage Name: **$env:PACKAGE_NAME**`n`nReady to merge and deploy to Release Source." | |
| } | ConvertTo-Json | |
| $api = "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | |
| Invoke-RestMethod -Uri $api -Headers $headers -Method Post -Body $body -ContentType "application/json" | |
| - name: Comment on PR - Precheck Failed | |
| if: failure() | |
| shell: powershell -ExecutionPolicy Bypass -Command ". '{0}'" | |
| run: | | |
| $headers = @{ | |
| Authorization = "Bearer ${{ secrets.GITHUB_TOKEN }}" | |
| Accept = "application/vnd.github.v3+json" | |
| } | |
| $body = @{ | |
| body = ":x: **Precheck Validation Failed**`n`nPackage Name: **$env:PACKAGE_NAME**`n`nPlease review the validation errors in the logs." | |
| } | ConvertTo-Json | |
| $api = "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" | |
| Invoke-RestMethod -Uri $api -Headers $headers -Method Post -Body $body -ContentType "application/json" |