Archive dbatools repo as tar.gz in CI workflow #197
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
name: Build and Publish Preview Release | |
# This workflow builds the module and creates a preview release on GitHub | |
# It triggers automatically when: | |
# - The module version contains "preview" (checked on every push) | |
# - Manually triggered via workflow_dispatch (useful when module is not found on PowerShell Gallery) | |
# | |
# To trigger a preview release: | |
# 1. Set ModuleVersion in dbatools.library.psd1 to include "preview" (e.g., '2025.7.11-preview') | |
# 2. OR manually trigger the workflow from GitHub Actions tab | |
on: | |
push: | |
# Runs on any branch, checks module version for "preview" | |
pull_request: | |
workflow_dispatch: | |
# Manual trigger for when module is not available on PowerShell Gallery | |
inputs: | |
dbatools_branch: | |
description: 'dbatools branch to use (default: development)' | |
required: false | |
default: 'development' | |
jobs: | |
# Setup job - downloads dependencies once for all other jobs | |
setup-dependencies: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout dbatools repo | |
uses: actions/checkout@v4 | |
with: | |
repository: dataplat/dbatools | |
ref: ${{ github.event.inputs.dbatools_branch || 'development' }} | |
path: dbatools | |
- name: Clone appveyor repo | |
run: git clone https://github.com/dataplat/appveyor-lab.git appveyor-lab | |
- name: Create tar archive with dot files | |
run: | | |
cd dbatools | |
tar -czf ../dbatools-repo.tar.gz --exclude='.git' . | |
cd .. | |
- name: Upload dbatools repo artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dbatools-repo | |
path: dbatools-repo.tar.gz | |
- name: Upload appveyor repo artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: appveyor-repo | |
path: appveyor-lab | |
# Windows build job - builds complete library with all components | |
build-library: | |
runs-on: windows-latest | |
needs: setup-dependencies | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: | | |
8.0.x | |
6.0.x | |
- name: Install .NET Framework targeting packs | |
shell: pwsh | |
run: choco install netfx-4.7.2-devpack -y --no-progress | |
- name: Build complete library | |
shell: pwsh | |
run: .\build\build.ps1 -BuildZip | |
- name: Make sqlpackage executable | |
shell: pwsh | |
run: | | |
chmod +x ./artifacts/dbatools.library/core/lib/dac/linux/sqlpackage || true | |
chmod +x ./artifacts/dbatools.library/core/lib/dac/mac/sqlpackage || true | |
- name: Verify critical files | |
shell: pwsh | |
run: | | |
$artifactsDir = "./artifacts/dbatools.library" | |
$criticalPaths = @( | |
"desktop/lib", | |
"desktop/lib/runtimes/win-x64/native", | |
"core/lib/dac/windows", | |
"desktop/third-party", | |
"core/lib", | |
"core/lib/runtimes/win-x64/native", | |
"core/lib/dac/linux", | |
"core/lib/dac/mac", | |
"core/third-party" | |
) | |
$missingPaths = @() | |
foreach ($path in $criticalPaths) { | |
$fullPath = Join-Path $artifactsDir $path | |
if (Test-Path $fullPath) { | |
Write-Host "✅ Found: $path" -ForegroundColor Green | |
} else { | |
Write-Host "❌ Missing: $path" -ForegroundColor Red | |
$missingPaths += $path | |
} | |
} | |
if ($missingPaths.Count -gt 0) { | |
Write-Host "Critical paths missing:" -ForegroundColor Red | |
$missingPaths | ForEach-Object { Write-Host " - $_" -ForegroundColor Red } | |
exit 1 | |
} | |
Write-Host "All critical paths verified!" -ForegroundColor Green | |
- name: Upload library artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dbatools-library | |
path: artifacts/dbatools.library/ | |
- name: Upload release zip | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dbatools-library-zip | |
path: artifacts/dbatools.library.zip | |
# Test matrix - tests on all platforms with proper dependencies and environment | |
test-matrix: | |
name: Test on ${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
needs: build-library | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: ubuntu-latest | |
script: ./dbatools/.github/scripts/gh-actions.ps1 | |
shell: pwsh | |
working-directory: ${{ github.workspace }} | |
- os: macos-latest | |
script: ./dbatools/.github/scripts/gh-macactions.ps1 | |
shell: pwsh | |
working-directory: ${{ github.workspace }} | |
- os: windows-latest | |
script: ./dbatools/.github/scripts/gh-winactions.ps1 | |
shell: pwsh | |
working-directory: ${{ github.workspace }} | |
env: | |
TENANTID: ${{ secrets.TENANTID }} | |
CLIENTID: ${{ secrets.CLIENTID }} | |
CLIENTSECRET: ${{ secrets.CLIENTSECRET }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SMODefaultModuleName: dbatools | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install local SQL engine via mssqlsuite | |
uses: potatoqualitee/[email protected] | |
with: | |
install: sqlengine | |
sa-password: dbatools.I0 | |
- name: Download dbatools.library artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dbatools-library-zip | |
- name: Download dbatools repo artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dbatools-repo | |
- name: Extract dbatools repo | |
run: | | |
mkdir -p dbatools | |
tar -xzf dbatools-repo.tar.gz -C dbatools | |
- name: Download appveyor repo artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: appveyor-repo | |
path: appveyor-lab | |
- name: Extract library | |
shell: pwsh | |
run: | | |
New-Item -ItemType Directory -Path ./artifacts -Force | Out-Null | |
Expand-Archive -Path ./dbatools.library.zip -DestinationPath ./artifacts -Force | |
if (Test-Path ./artifacts/dbatools.library/dbatools.library.psd1) { | |
Write-Host "✅ Library extracted successfully" -ForegroundColor Green | |
} else { | |
Write-Error "❌ Failed to extract library" | |
exit 1 | |
} | |
- name: Configure dbatools | |
shell: pwsh | |
run: | | |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force | |
Import-Module ./dbatools/dbatools.psd1 -Force | |
Set-DbatoolsConfig -FullName sql.connection.trustcert -Value $true -Register | |
Set-DbatoolsConfig -FullName sql.connection.encrypt -Value $false -Register | |
if ($IsLinux) { | |
New-Item -ItemType Directory -Path /tmp/DbatoolsExport -Force | Out-Null | |
} | |
- name: Debug working directory | |
shell: pwsh | |
run: | | |
Write-Host "Current working directory: $(Get-Location)" | |
Write-Host "Repository workspace: ${{ github.workspace }}" | |
Write-Host "Script path to execute: ${{ matrix.script }}" | |
Write-Host "Full script path: ${{ github.workspace }}/${{ matrix.script }}" | |
Write-Host "Directory tree from workspace root:" | |
Get-ChildItem -Recurse | Select-Object -ExpandProperty FullName | Where-Object Name -match github | |
- name: Run integration tests (PowerShell Core) | |
shell: pwsh | |
working-directory: ${{ github.workspace }} | |
run: | | |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force | |
Import-Module ./dbatools/dbatools.psd1 -Force | |
$ErrorActionPreference = "Stop" | |
Write-Host "Running integration tests with ${{ matrix.script }}" | |
$null = Invoke-Pester ${{ matrix.script }} -Output Detailed -PassThru | |
- name: Run integration tests (Windows PowerShell) | |
if: matrix.os == 'windows-latest' | |
shell: powershell | |
working-directory: ${{ github.workspace }} | |
run: | | |
Import-Module ./artifacts/dbatools.library/dbatools.library.psd1 -Force | |
Import-Module ./dbatools/dbatools.psd1 -Force | |
$ErrorActionPreference = "Stop" | |
Write-Host "Running integration tests with ${{ matrix.script }} (Windows PowerShell)" | |
$null = Invoke-Pester ${{ matrix.script }} -Output Detailed -PassThru | |
# Release job - creates GitHub release | |
create-preview-release: | |
needs: test-matrix | |
runs-on: windows-latest | |
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Download release zip | |
uses: actions/download-artifact@v4 | |
with: | |
name: dbatools-library-zip | |
- name: Extract library for version info | |
shell: pwsh | |
run: | | |
New-Item -ItemType Directory -Path ./artifacts -Force | Out-Null | |
Expand-Archive -Path ./dbatools.library.zip -DestinationPath ./artifacts -Force | |
- name: Generate preview version and update manifest | |
id: get_version | |
shell: pwsh | |
run: | | |
$date = Get-Date -Format "yyyy.M.d" | |
$timestamp = Get-Date -Format "yyyyMMddHHmmss" | |
$branch = "${{ github.ref_name }}" -replace '[^A-Za-z0-9]', '' | |
if ("${{ github.event_name }}" -eq "workflow_dispatch") { | |
$previewVersion = "$date-preview-$branch-$timestamp" | |
} else { | |
$manifestPath = "./artifacts/dbatools.library/dbatools.library.psd1" | |
$manifest = Import-PowerShellDataFile $manifestPath | |
$currentVersion = $manifest.ModuleVersion | |
if ($currentVersion -like "*preview*") { | |
$previewVersion = "$currentVersion-$branch-$timestamp" | |
} else { | |
$previewVersion = "$date-preview-$branch-$timestamp" | |
} | |
} | |
Write-Host "Preview version: $previewVersion" | |
$psd1Version = if ($previewVersion -match '^(.*?-preview)') { $matches[1] } else { $previewVersion } | |
$manifestPath = "./artifacts/dbatools.library/dbatools.library.psd1" | |
$content = Get-Content $manifestPath -Raw | |
$content = $content -replace "ModuleVersion\s*=\s*'[^']*'", "ModuleVersion = '$psd1Version'" | |
Set-Content $manifestPath $content | |
"version=$previewVersion" >> $env:GITHUB_OUTPUT | |
"branch=$branch" >> $env:GITHUB_OUTPUT | |
- name: Create Preview Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: v${{ steps.get_version.outputs.version }} | |
name: Preview Release v${{ steps.get_version.outputs.version }} | |
body: | | |
This is an automated preview release. | |
**Trigger Reason:** ${{ github.event_name == 'workflow_dispatch' && 'Manual workflow dispatch' || 'Version contains preview' }} | |
**Module Version:** ${{ steps.get_version.outputs.version }} | |
**Branch:** ${{ steps.get_version.outputs.branch }} | |
**Commit:** ${{ github.sha }} | |
**Build Date:** ${{ github.event.head_commit.timestamp }} | |
## Installation | |
```powershell | |
# Download and extract the zip file | |
Invoke-WebRequest -Uri "https://github.com/${{ github.repository }}/releases/download/v${{ steps.get_version.outputs.version }}/dbatools.library.zip" -OutFile dbatools.library.zip | |
Expand-Archive -Path dbatools.library.zip -DestinationPath . -Force | |
# Import the module | |
Import-Module ./dbatools.library.psd1 | |
``` | |
⚠️ **Note:** This is a preview release and should not be used in production. | |
draft: false | |
prerelease: true | |
files: ./dbatools.library.zip |