Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
dca2b5f
show powershell info
vaind Feb 12, 2024
9ce0615
run on windows 2019
vaind Feb 12, 2024
19b7924
powershell setup action
vaind Feb 12, 2024
b08945b
fixup
vaind Feb 12, 2024
c8c6056
fixup
vaind Feb 12, 2024
4b2ab3d
improve checks
vaind Feb 12, 2024
6eefe4d
improve test names
vaind Feb 12, 2024
d7f7553
cleanup
vaind Feb 12, 2024
0489b2a
more info
vaind Feb 12, 2024
ab8ab00
job name
vaind Feb 12, 2024
cc17d08
print version
vaind Feb 12, 2024
f53d9cb
try to fix 6.0
vaind Feb 12, 2024
47f4a38
fix syntax
vaind Feb 12, 2024
81e3e91
fix order
vaind Feb 12, 2024
4a19204
try to fix pwsh 6
vaind Feb 12, 2024
6e5210b
set error action preference
vaind Feb 12, 2024
14a4e41
try fixing 6.0
vaind Feb 12, 2024
e8bea2f
try to fix v6
vaind Feb 12, 2024
a297240
6.0 custom tests
vaind Feb 12, 2024
1888edb
try to fix tests on 6.1
vaind Feb 12, 2024
2ae54a7
deduplicate settings
vaind Feb 12, 2024
34a40ff
hide Load assembly success stream output
vaind Feb 12, 2024
c14ea9a
fixup tests
vaind Feb 12, 2024
30455e0
enable debug logging in CI
vaind Feb 12, 2024
266b366
try to fix 6.0+
vaind Feb 12, 2024
4a05e51
fix stj assembly version for netstandard 2.0
vaind Feb 12, 2024
9b1905f
add missing dep
vaind Feb 12, 2024
90c21d5
change 6.1 testing
vaind Feb 12, 2024
64e8594
syntax error
vaind Feb 12, 2024
9e4d22c
missing deps
vaind Feb 12, 2024
755aaed
formatting
vaind Feb 12, 2024
2a4b246
try loading assemblies manually
vaind Feb 12, 2024
002b20d
logging
vaind Feb 12, 2024
998116f
logging fix
vaind Feb 12, 2024
81c55a3
test output log
vaind Feb 12, 2024
950ca15
disable broken CI versions
vaind Feb 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/actions/setup-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
name: Setup dependencies
description: Download dependent libraries

runs:
using: composite
steps:
Expand Down
52 changes: 52 additions & 0 deletions .github/actions/setup-powershell/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Setup PowerShell
description: Setup PowerShell (Core) at a given version
inputs:
version:
description: Powershell version to install
required: true

runs:
using: composite
steps:
# Download the powershell '.tar.gz' archive
- run: curl -L -o /tmp/powershell.tar.gz https://github.com/PowerShell/PowerShell/releases/download/v${{ inputs.version }}/powershell-${{ inputs.version }}-linux-x64.tar.gz
shell: bash

# Create the target folder where powershell will be placed
- run: sudo mkdir -p /opt/microsoft/powershell/${{ inputs.version }}
shell: bash

# Expand powershell to the target folder
- run: sudo tar zxf /tmp/powershell.tar.gz -C /opt/microsoft/powershell/${{ inputs.version }}
shell: bash

# Set execute permissions
- run: sudo chmod +x /opt/microsoft/powershell/${{ inputs.version }}/pwsh
shell: bash

# Unlink the original pwsh binary already present in the system
- run: sudo unlink /usr/bin/pwsh
shell: bash

# Create the symbolic link that points to pwsh
- run: sudo ln -s /opt/microsoft/powershell/${{ inputs.version }}/pwsh /usr/bin/pwsh
shell: bash

# Verify the installation by checking the `pwsh` command version.
- run: |
pwsh --version
[[ "$(pwsh --version)" == "PowerShell ${{ inputs.version == '6.0.0' && 'v6.0.0' || inputs.version }}" ]]
shell: bash

# Setup old OpenSSL necessary for .NET Core 2.1.
- if: ${{ startsWith(inputs.version, '6.') }}
shell: bash
run: |
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb

# Verify the installation by using the `pwsh` shell.
- run: |
$PSVersionTable
if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 }
shell: pwsh
63 changes: 54 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,36 @@ on:

jobs:
test:
name: ${{ matrix.os }} - ${{ matrix.shell }}
runs-on: ${{ matrix.os }}-latest
name: ${{ matrix.os }} - ${{ matrix.shell }} ${{ matrix.version }}
runs-on: ${{ matrix.os == 'ubuntu' && 'ubuntu-latest' || matrix.os == 'macos' && 'macos-latest' || matrix.os == 'windows' && 'windows-latest' || matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu, windows, macos]
# Test all Powershell (core) versions on Ubuntu.
# See https://github.com/getsentry/sentry-powershell/issues/13 and PR #12 about the disabled versions.
os: [ubuntu]
shell: [pwsh]
version:
- '7.4.0'
- '7.3.0'
- '7.2.0'
# - '7.1.0'
# - '7.0.0'
- '6.2.0'
- '6.1.0'
# - '6.0.0'
# And test all built-in PowerShell/Windows Powershell versions on latest CI runner images
include:
- os: ubuntu
shell: pwsh
- os: macos
shell: pwsh
- os: windows
shell: pwsh
- os: windows-2019
shell: powershell
- os: windows-2022 # same as windows-latest as of 02/2024
shell: powershell

defaults:
Expand All @@ -32,23 +52,48 @@ jobs:
- name: Setup dependencies
uses: ./.github/actions/setup-dependencies

- name: Setup PowerShell ${{ matrix.version }}
if: ${{ matrix.version != '' }}
uses: ./.github/actions/setup-powershell
with:
version: ${{ matrix.version }}

- run: $PSVersionTable

# We don't test module loading with Pester because we're unable to unload the module between tests.
# Testing as a separate step allows unloads it automatically at the step end.
- name: Module loading
run: |
. ./tools/settings.ps1
# Loading the first time
Get-Item ./module/Sentry.psd1 | Import-Module -PassThru
# This needs to return actual types (method overloads)
'[Sentry.SentrySdk]::init'
[Sentry.SentrySdk]::init
# Loading the second time must be possible, without errors
Get-Item ./module/Sentry.psd1 | Import-Module
# And accessing APIs must still work too
'[Sentry.SentrySdk]::init'
[Sentry.SentrySdk]::init

- name: Unit tests
run: |
. ./tools/settings.ps1
Get-Item ./module/Sentry.psd1 | Import-Module
$config = New-PesterConfiguration
$config.Run.Path = "tests"
$config.TestResult.Enabled = $true
Invoke-Pester -Configuration $config

# Pester doesn't work on PowerShell 6.0 so our testing here is extremely limited.
# Also, PowerShell 6.1 doesn't break when there's an error, regardless of the $ErrorActionPreference.
if (("${{ matrix.version }}" -eq "6.0.0") -or ("${{ matrix.version }}" -eq "6.1.0"))
{
if ([Sentry.SentrySdk].GetType().Name -ne 'RuntimeType') { throw "Invalid type on Sentry.SentrySdk" }
[Sentry.SentrySdk]::init('https://key@host/1')
if (-not [Sentry.SentrySdk]::IsEnabled) { throw "Sentry isn't enabled after init" }
[Sentry.SentrySdk]::close()
if ([Sentry.SentrySdk]::IsEnabled) { throw "Sentry is still enabled after close" }
Write-Host -ForegroundColor Green "All tests successful"
}
else
{
$config = New-PesterConfiguration
$config.Run.Path = "tests"
$config.TestResult.Enabled = $true
Invoke-Pester -Configuration $config
}
38 changes: 23 additions & 15 deletions dependencies/download.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'

. "$PSScriptRoot/../tools/settings.ps1"
$downloadDir = "$PSScriptRoot/downloads"
$propsDir = "$PSScriptRoot"
$moduleDir = "$PSScriptRoot/../module"
Expand All @@ -17,13 +15,17 @@ function CheckAssemblyVersion([string] $libFile, [string] $assemblyVersion)
}
}

function Download([string] $dependency, [string] $sourceTFM, [string] $targetTFM = $null)
function Download([string] $dependency, [string] $TFM, [string] $targetTFM = $null, [string] $assemblyVersion = $null)
{
$targetTFM = "$targetTFM" -eq '' ? $sourceTFM : $targetTFM
$targetTFM = "$targetTFM" -eq '' ? $TFM : $targetTFM
New-Item "$libDir/$targetTFM" -ItemType Directory -Force | Out-Null

$props = (Get-Content "$propsDir/$dependency.properties" -Raw | ConvertFrom-StringData)
$assemblyVersion = $props.ContainsKey('assemblyVersion') ? $props.assemblyVersion : "$($props.version).0"

if ("$assemblyVersion" -eq '')
{
$assemblyVersion = $props.ContainsKey('assemblyVersion') ? $props.assemblyVersion : "$($props.version).0"
}

$targetLibFile = "$libDir/$targetTFM/$dependency.dll"
$targetVersionFile = "$libDir/$targetTFM/$dependency.version"
Expand All @@ -34,11 +36,12 @@ function Download([string] $dependency, [string] $sourceTFM, [string] $targetTFM
try
{
CheckAssemblyVersion $targetLibFile $assemblyVersion
Write-Debug "Dependency $targetLibFile already exists and has the expected assembly version ($assemblyVersion), skipping."
return
}
catch
{
Write-Warning "$_, downloading again".
Write-Warning "$_, downloading again"
}
}

Expand Down Expand Up @@ -86,7 +89,7 @@ function Download([string] $dependency, [string] $sourceTFM, [string] $targetTFM

try
{
extract "lib/$sourceTFM/$dependency.dll" $targetLibFile
extract "lib/$TFM/$dependency.dll" $targetLibFile
if ($props.ContainsKey('licenseFile'))
{
extract $props.licenseFile $targetLicenseFile
Expand All @@ -105,10 +108,15 @@ function Download([string] $dependency, [string] $sourceTFM, [string] $targetTFM
$assemblyVersion | Out-File -NoNewline $targetVersionFile
}

Download -Dependency 'Sentry' -SourceTFM 'net8.0'
Download -Dependency 'Sentry' -SourceTFM 'net6.0'
Download -Dependency 'Sentry' -SourceTFM 'netstandard2.0'
Download -Dependency 'Sentry' -SourceTFM 'net462'
Download -Dependency 'System.Text.Json' -SourceTFM 'net461' -TargetTFM 'net462'
Download -Dependency 'Microsoft.Bcl.AsyncInterfaces' -SourceTFM 'net461' -TargetTFM 'net462'
Download -Dependency 'System.Threading.Tasks.Extensions' -SourceTFM 'net461' -TargetTFM 'net462'
Download -Dependency 'Sentry' -TFM 'net8.0'
Download -Dependency 'Sentry' -TFM 'net6.0'
Download -Dependency 'Sentry' -TFM 'netstandard2.0'
Download -Dependency 'Sentry' -TFM 'net462'

Download -Dependency 'System.Text.Json' -TFM 'net461' -TargetTFM 'net462'
Download -Dependency 'Microsoft.Bcl.AsyncInterfaces' -TFM 'net461' -TargetTFM 'net462'
Download -Dependency 'System.Threading.Tasks.Extensions' -TFM 'net461' -TargetTFM 'net462'

Download -Dependency 'System.Text.Json' -TFM 'netstandard2.0' -assemblyVersion '6.0.0.0'
Download -Dependency 'Microsoft.Bcl.AsyncInterfaces' -TFM 'netstandard2.0'
Download -Dependency 'System.Threading.Tasks.Extensions' -TFM 'netstandard2.0'
14 changes: 10 additions & 4 deletions module/assemblies-loader.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,30 @@ function GetTFM
}

$dir = Join-Path $dir (GetTFM)
$lib = Join-Path $dir 'Sentry.dll'

# Check if the assembly is already loaded.
$type = 'Sentry.SentrySdk' -as [type]
if ($type)
{
$loadedAsssembly = $type.Assembly
$expectedAssembly = [Reflection.Assembly]::LoadFile($lib)
$expectedAssembly = [Reflection.Assembly]::LoadFile((Join-Path $dir 'Sentry.dll'))

if ($loadedAsssembly.ToString() -ne $expectedAssembly.ToString())
{
throw "Sentry assembly is already loaded but it's not the expected version.
Found: ($loadedAsssembly), location: $($loadedAsssembly.Location)
Expected: ($expectedAssembly), location: $($expectedAssembly.Location)"
}
else
{
Write-Debug "Sentry assembly is already loaded and at the expected version ($($expectedAssembly.GetName().Version)"
}
}
else
{
Write-Debug "Loading Sentry assembly from $lib"
[Reflection.Assembly]::LoadFrom($lib)
Write-Debug "Loading assemblies from $($dir):"
Get-ChildItem -Path $dir -Filter '*.dll' | ForEach-Object {
Write-Debug "Loading assembly: $($_.Name)"
[Reflection.Assembly]::LoadFrom($_.FullName) | Write-Debug
}
}
10 changes: 10 additions & 0 deletions tools/settings.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Common settings - use this in all scripts by sourcing: `. ./tools/settings.ps1`
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true

Check warning

Code scanning / PSScriptAnalyzer

The variable 'PSNativeCommandUseErrorActionPreference' is assigned but never used.

The variable 'PSNativeCommandUseErrorActionPreference' is assigned but never used.

# Enable debug logging in CI
if (Test-Path env:CI)
{
$DebugPreference = 'Continue'
}