Skip to content

Fix import failure on some PowerShell Core installs by adjusting System.Management.Automation references and target frameworks #213

Fix import failure on some PowerShell Core installs by adjusting System.Management.Automation references and target frameworks

Fix import failure on some PowerShell Core installs by adjusting System.Management.Automation references and target frameworks #213

Workflow file for this run

name: Build and Publish Preview Release
on:
push:
pull_request:
workflow_dispatch:
inputs:
dbatools_branch:
description: 'dbatools branch to use (default: development)'
required: false
default: 'development'
env:
TENANTID: ${{ secrets.TENANTID }}
CLIENTID: ${{ secrets.CLIENTID }}
CLIENTSECRET: ${{ secrets.CLIENTSECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CLIENT_GUID_SECRET: ${{ secrets.CLIENT_GUID_SECRET }}
CLIENT_GUID: ${{ secrets.CLIENT_GUID }}
SMODefaultModuleName: dbatools
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
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
if: runner.os != 'Windows'
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:
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 }}
steps:
- uses: actions/checkout@v4
- name: Setup docker images (Linux only)
if: matrix.os == 'ubuntu-latest'
run: |
docker network create localnet
docker run -p 1433:1433 --volume shared:/shared:z --name mssql1 --hostname mssql1 --network localnet -d dbatools/sqlinstance
docker run -p 14333:1433 --volume shared:/shared:z --name mssql2 --hostname mssql2 --network localnet -d dbatools/sqlinstance2
- name: Install local SQL engine via mssqlsuite (Windows only)
if: matrix.os == 'windows-latest'
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
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@v2
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