From dca2b5f70c3d12ce245e4f36c42ff7e3a6028609 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:04:32 +0100 Subject: [PATCH 01/36] show powershell info --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9608a4d..f6734a5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,6 +29,8 @@ jobs: steps: - uses: actions/checkout@v4 + - run: $PSVersionTable + - name: Setup dependencies uses: ./.github/actions/setup-dependencies From 9ce0615d5737a407353d38aedea922bfaadb2a1c Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:10:47 +0100 Subject: [PATCH 02/36] run on windows 2019 --- .github/workflows/test.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f6734a5..0b93b13 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,15 +11,17 @@ on: jobs: test: name: ${{ matrix.os }} - ${{ matrix.shell }} - runs-on: ${{ matrix.os }}-latest + runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [ubuntu, windows, macos] + os: [ubuntu-latest, windows-latest, macos-latest] shell: [pwsh] include: - - os: windows + - os: windows-2019 + shell: powershell + - os: windows-2022 shell: powershell defaults: From 19b79249da49b308a44fa15454afd209dfbda5a1 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:36:35 +0100 Subject: [PATCH 03/36] powershell setup action --- .github/actions/setup-dependencies/action.yml | 2 ++ .github/actions/setup-powershell/action.yml | 29 +++++++++++++++ .github/workflows/test.yml | 35 ++++++++++++++----- 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 .github/actions/setup-powershell/action.yml diff --git a/.github/actions/setup-dependencies/action.yml b/.github/actions/setup-dependencies/action.yml index 56233e6..fc5d13c 100644 --- a/.github/actions/setup-dependencies/action.yml +++ b/.github/actions/setup-dependencies/action.yml @@ -1,4 +1,6 @@ name: Setup dependencies +description: Download dependent libraries + runs: using: composite steps: diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml new file mode 100644 index 0000000..815fcfd --- /dev/null +++ b/.github/actions/setup-powershell/action.yml @@ -0,0 +1,29 @@ +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 + + # Create the symbolic link that points to pwsh + - run: sudo ln -s /opt/microsoft/powershell/${{ inputs.version }}/pwsh /usr/bin/pwsh + shell: bash diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0b93b13..3c3d372 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,32 +10,49 @@ on: jobs: test: - name: ${{ matrix.os }} - ${{ matrix.shell }} + name: ${{ matrix.os }} - ${{ matrix.shell }} ${{ matrix.version }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest, macos-latest] + # Test all Powershell (core) versions on Ubuntu + os: [ubuntu-latest] 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-latest + shell: pwsh + - os: macos-latest + shell: pwsh - os: windows-2019 shell: powershell - - os: windows-2022 + - os: windows-2022 # same as windows-latest as of 02/2024 shell: powershell - defaults: - run: - shell: ${{ matrix.shell }} - steps: - uses: actions/checkout@v4 - - run: $PSVersionTable - - name: Setup dependencies uses: ./.github/actions/setup-dependencies + - name: Setup PowerShell + 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 From b08945b7cdcfc81bdd2f8390998c8ff23a33a137 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:43:58 +0100 Subject: [PATCH 04/36] fixup --- .github/actions/setup-powershell/action.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index 815fcfd..5f6bc1d 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -24,6 +24,13 @@ runs: - 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 + + - run: '[[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]]' + shell: bash From c8c6056b246b95fc313c0ad2871a26420bbaa373 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:45:14 +0100 Subject: [PATCH 05/36] fixup --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3c3d372..c152f83 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,10 +52,12 @@ jobs: version: ${{ matrix.version }} - run: $PSVersionTable + shell: pwsh # 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 + shell: pwsh run: | # Loading the first time Get-Item ./module/Sentry.psd1 | Import-Module -PassThru @@ -67,6 +69,7 @@ jobs: '[Sentry.SentrySdk]::init' - name: Unit tests + shell: pwsh run: | Get-Item ./module/Sentry.psd1 | Import-Module $config = New-PesterConfiguration From 4b2ab3d6902989b484030c90b725add7d87d5fe2 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:50:50 +0100 Subject: [PATCH 06/36] improve checks --- .github/actions/setup-powershell/action.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index 5f6bc1d..19ce32d 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -32,5 +32,10 @@ runs: - 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)" == "PowerShell ${{ inputs.version }}" ]]' shell: bash + + # Verify the installation by using the `pwsh` shell. + - run: if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } + shell: pwsh \ No newline at end of file From 6eefe4dbe75d6e642f6bf48df3866fa190d52384 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:52:54 +0100 Subject: [PATCH 07/36] improve test names --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c152f83..1d915e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,13 +11,13 @@ on: jobs: test: name: ${{ matrix.os }} - ${{ matrix.shell }} ${{ matrix.version }} - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os == 'ubuntu' && 'ubuntu-latest' || matrix.os == 'macos' && 'macos-latest' || matrix.os }} strategy: fail-fast: false matrix: # Test all Powershell (core) versions on Ubuntu - os: [ubuntu-latest] + os: [ubuntu] shell: [pwsh] version: - '7.4.0' @@ -30,9 +30,9 @@ jobs: - '6.0.0' # And test all built-in PowerShell/Windows Powershell versions on latest CI runner images include: - - os: ubuntu-latest + - os: ubuntu shell: pwsh - - os: macos-latest + - os: macos shell: pwsh - os: windows-2019 shell: powershell From d7f7553063bfb386f29d739777dd79cbb970e14e Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:55:58 +0100 Subject: [PATCH 08/36] cleanup --- .github/actions/setup-powershell/action.yml | 2 +- .github/workflows/test.yml | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index 19ce32d..5fc71cf 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -38,4 +38,4 @@ runs: # Verify the installation by using the `pwsh` shell. - run: if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } - shell: pwsh \ No newline at end of file + shell: pwsh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1d915e0..4beae88 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ on: jobs: test: name: ${{ matrix.os }} - ${{ matrix.shell }} ${{ matrix.version }} - runs-on: ${{ matrix.os == 'ubuntu' && 'ubuntu-latest' || matrix.os == 'macos' && 'macos-latest' || matrix.os }} + runs-on: ${{ matrix.os == 'ubuntu' && 'ubuntu-latest' || matrix.os == 'macos' && 'macos-latest' || matrix.os == 'windows' && 'windows-latest' || matrix.os }} strategy: fail-fast: false @@ -34,11 +34,17 @@ jobs: 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: + run: + shell: ${{ matrix.shell }} + steps: - uses: actions/checkout@v4 @@ -52,12 +58,10 @@ jobs: version: ${{ matrix.version }} - run: $PSVersionTable - shell: pwsh # 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 - shell: pwsh run: | # Loading the first time Get-Item ./module/Sentry.psd1 | Import-Module -PassThru @@ -69,7 +73,6 @@ jobs: '[Sentry.SentrySdk]::init' - name: Unit tests - shell: pwsh run: | Get-Item ./module/Sentry.psd1 | Import-Module $config = New-PesterConfiguration From 0489b2a80f5c89c688d1fd300ab1f047489349ba Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 14:58:52 +0100 Subject: [PATCH 09/36] more info --- .github/actions/setup-powershell/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index 5fc71cf..a74bf92 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -37,5 +37,7 @@ runs: shell: bash # Verify the installation by using the `pwsh` shell. - - run: if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } + - run: | + $PSVersionTable + if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } shell: pwsh From ab8ab00b8ae86706adb26038140bc95b255d29df Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:01:29 +0100 Subject: [PATCH 10/36] job name --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4beae88..d0bfbe9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,7 +51,7 @@ jobs: - name: Setup dependencies uses: ./.github/actions/setup-dependencies - - name: Setup PowerShell + - name: Setup PowerShell ${{ matrix.version }} if: ${{ matrix.version != '' }} uses: ./.github/actions/setup-powershell with: From cc17d080e23e6a85c51b8774646d66e2011d7679 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:02:34 +0100 Subject: [PATCH 11/36] print version --- .github/actions/setup-powershell/action.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index a74bf92..fad4e70 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -33,7 +33,9 @@ runs: shell: bash # Verify the installation by checking the `pwsh` command version. - - run: '[[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]]' + - run: | + pwsh --version + '[[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]]' shell: bash # Verify the installation by using the `pwsh` shell. From f53d9cb3bf609617340b55ab8426b2d52d28e819 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:10:14 +0100 Subject: [PATCH 12/36] try to fix 6.0 --- .github/actions/setup-powershell/action.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index fad4e70..2edb7fc 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -39,7 +39,18 @@ runs: shell: bash # Verify the installation by using the `pwsh` shell. - - run: | + - run: | $PSVersionTable if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } shell: pwsh + + # Setup old OpenSSL necessary for .NET Core 2.1. + - if: ${{ startsWith(inputs.version, '6.') }} + shell: bash + run: | + wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz + tar -xzvf openssl-1.1.1c.tar.gz + cd openssl-1.1.1c + ./config + make + sudo make install \ No newline at end of file From 47f4a3845eb9e9259e30a19f9f97847012d4bb56 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:20:27 +0100 Subject: [PATCH 13/36] fix syntax --- .github/actions/setup-powershell/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index 2edb7fc..feeb455 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -35,7 +35,7 @@ runs: # Verify the installation by checking the `pwsh` command version. - run: | pwsh --version - '[[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]]' + [[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]] shell: bash # Verify the installation by using the `pwsh` shell. From 81e3e91309ae531e9e7724162726c912b8e7baa8 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:25:40 +0100 Subject: [PATCH 14/36] fix order --- .github/actions/setup-powershell/action.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index feeb455..ab9a9e7 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -38,12 +38,6 @@ runs: [[ "$(pwsh --version)" == "PowerShell ${{ inputs.version }}" ]] shell: bash - # Verify the installation by using the `pwsh` shell. - - run: | - $PSVersionTable - if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } - shell: pwsh - # Setup old OpenSSL necessary for .NET Core 2.1. - if: ${{ startsWith(inputs.version, '6.') }} shell: bash @@ -53,4 +47,10 @@ runs: cd openssl-1.1.1c ./config make - sudo make install \ No newline at end of file + sudo make install + + # Verify the installation by using the `pwsh` shell. + - run: | + $PSVersionTable + if ( $PSVersionTable.PSVersion.ToString() -ne "${{ inputs.version }}" ) { exit 1 } + shell: pwsh From 4a19204f3cb76229dc3993fcc96f2b8cf96a007b Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:29:49 +0100 Subject: [PATCH 15/36] try to fix pwsh 6 --- .github/actions/setup-powershell/action.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index ab9a9e7..bfa372c 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -42,12 +42,8 @@ runs: - if: ${{ startsWith(inputs.version, '6.') }} shell: bash run: | - wget https://www.openssl.org/source/openssl-1.1.1c.tar.gz - tar -xzvf openssl-1.1.1c.tar.gz - cd openssl-1.1.1c - ./config - make - sudo make install + 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: | From 6e5210b32321c7e7c42833fdd9a138e1f2f8f2bd Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:42:12 +0100 Subject: [PATCH 16/36] set error action preference --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d0bfbe9..bddde7f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,6 +63,8 @@ jobs: # Testing as a separate step allows unloads it automatically at the step end. - name: Module loading run: | + Set-StrictMode -Version latest + $ErrorActionPreference = 'Stop' # Loading the first time Get-Item ./module/Sentry.psd1 | Import-Module -PassThru # This needs to return actual types (method overloads) @@ -74,6 +76,8 @@ jobs: - name: Unit tests run: | + Set-StrictMode -Version latest + $ErrorActionPreference = 'Stop' Get-Item ./module/Sentry.psd1 | Import-Module $config = New-PesterConfiguration $config.Run.Path = "tests" From 14a4e41a47308b3518c6efb928181bb1c640dbc0 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:42:22 +0100 Subject: [PATCH 17/36] try fixing 6.0 --- .github/actions/setup-powershell/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-powershell/action.yml b/.github/actions/setup-powershell/action.yml index bfa372c..064d870 100644 --- a/.github/actions/setup-powershell/action.yml +++ b/.github/actions/setup-powershell/action.yml @@ -35,7 +35,7 @@ runs: # Verify the installation by checking the `pwsh` command version. - run: | pwsh --version - [[ "$(pwsh --version)" == "PowerShell ${{ inputs.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. From e8bea2fb2cfba045242103d3d0c5b24e3c33cb4f Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 15:58:46 +0100 Subject: [PATCH 18/36] try to fix v6 --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bddde7f..bbd0ac7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,6 +78,8 @@ jobs: run: | Set-StrictMode -Version latest $ErrorActionPreference = 'Stop' + Import-Module Pester + Get-Module Pester Get-Item ./module/Sentry.psd1 | Import-Module $config = New-PesterConfiguration $config.Run.Path = "tests" From a2972402d6a57de369f080b88e1cdb5655153c12 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:06:17 +0100 Subject: [PATCH 19/36] 6.0 custom tests --- .github/workflows/test.yml | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bbd0ac7..fae7f8a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -78,10 +78,18 @@ jobs: run: | Set-StrictMode -Version latest $ErrorActionPreference = 'Stop' - Import-Module Pester - Get-Module Pester 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. + if ("${{ matrix.version }}" -eq "6.0.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" } + } else { + $config = New-PesterConfiguration + $config.Run.Path = "tests" + $config.TestResult.Enabled = $true + Invoke-Pester -Configuration $config + } From 1888edbfe9dea301ccb93c9d5762c74cfddb7291 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:09:28 +0100 Subject: [PATCH 20/36] try to fix tests on 6.1 --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fae7f8a..6b7b2af 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,4 +92,5 @@ jobs: $config.Run.Path = "tests" $config.TestResult.Enabled = $true Invoke-Pester -Configuration $config + exit $LASTEXITCODE } From 2ae54a72c164c66492aa7cccb5982bc09824b6a8 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:20:08 +0100 Subject: [PATCH 21/36] deduplicate settings --- .github/workflows/test.yml | 7 ++----- dependencies/download.ps1 | 4 +--- tools/settings.ps1 | 4 ++++ 3 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 tools/settings.ps1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6b7b2af..b337398 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -63,8 +63,7 @@ jobs: # Testing as a separate step allows unloads it automatically at the step end. - name: Module loading run: | - Set-StrictMode -Version latest - $ErrorActionPreference = 'Stop' + . ./tools/settings.ps1 # Loading the first time Get-Item ./module/Sentry.psd1 | Import-Module -PassThru # This needs to return actual types (method overloads) @@ -76,8 +75,7 @@ jobs: - name: Unit tests run: | - Set-StrictMode -Version latest - $ErrorActionPreference = 'Stop' + . ./tools/settings.ps1 Get-Item ./module/Sentry.psd1 | Import-Module # Pester doesn't work on PowerShell 6.0 so our testing here is extremely limited. @@ -92,5 +90,4 @@ jobs: $config.Run.Path = "tests" $config.TestResult.Enabled = $true Invoke-Pester -Configuration $config - exit $LASTEXITCODE } diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index cb24ce5..0d12b3d 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -1,6 +1,4 @@ -Set-StrictMode -Version latest -$ErrorActionPreference = 'Stop' - +. "$PSScriptRoot/../tools/settings.ps1" $downloadDir = "$PSScriptRoot/downloads" $propsDir = "$PSScriptRoot" $moduleDir = "$PSScriptRoot/../module" diff --git a/tools/settings.ps1 b/tools/settings.ps1 new file mode 100644 index 0000000..ac334d2 --- /dev/null +++ b/tools/settings.ps1 @@ -0,0 +1,4 @@ +# Common settings - use this in all scripts by sourcing: `. ./tools/settings.ps1` +Set-StrictMode -Version latest +$ErrorActionPreference = 'Stop' +$PSNativeCommandUseErrorActionPreference = $true From 34a40ffb83d9c8f12a17506f413857c7067b83d7 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:24:47 +0100 Subject: [PATCH 22/36] hide Load assembly success stream output --- module/assemblies-loader.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/assemblies-loader.ps1 b/module/assemblies-loader.ps1 index 97b6963..fa8e870 100644 --- a/module/assemblies-loader.ps1 +++ b/module/assemblies-loader.ps1 @@ -49,5 +49,5 @@ if ($type) else { Write-Debug "Loading Sentry assembly from $lib" - [Reflection.Assembly]::LoadFrom($lib) + [Reflection.Assembly]::LoadFrom($lib) | Write-Debug } From c14ea9aa577b913c1fd87b3aeb7617ceba50f2b8 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:27:33 +0100 Subject: [PATCH 23/36] fixup tests --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b337398..cc288c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,11 +67,11 @@ jobs: # 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: | From 30455e0fee18d1d3c9cbbc6977f8071e581d00a0 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:53:48 +0100 Subject: [PATCH 24/36] enable debug logging in CI --- module/assemblies-loader.ps1 | 4 ++++ tools/settings.ps1 | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/module/assemblies-loader.ps1 b/module/assemblies-loader.ps1 index fa8e870..feca9a5 100644 --- a/module/assemblies-loader.ps1 +++ b/module/assemblies-loader.ps1 @@ -45,6 +45,10 @@ if ($type) 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 { diff --git a/tools/settings.ps1 b/tools/settings.ps1 index ac334d2..fb051b8 100644 --- a/tools/settings.ps1 +++ b/tools/settings.ps1 @@ -2,3 +2,9 @@ Set-StrictMode -Version latest $ErrorActionPreference = 'Stop' $PSNativeCommandUseErrorActionPreference = $true + +# Enable debug logging in CI +if (Test-Path env:CI) +{ + $DebugPreference = 'Continue' +} \ No newline at end of file From 266b36628276b6c6dbe19e0c31e428534271ecff Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 16:57:06 +0100 Subject: [PATCH 25/36] try to fix 6.0+ --- dependencies/download.ps1 | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index 0d12b3d..195962d 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -15,9 +15,9 @@ function CheckAssemblyVersion([string] $libFile, [string] $assemblyVersion) } } -function Download([string] $dependency, [string] $sourceTFM, [string] $targetTFM = $null) +function Download([string] $dependency, [string] $TFM, [string] $targetTFM = $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) @@ -84,7 +84,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 @@ -103,10 +103,13 @@ 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' From 4a05e51d884fcdb30c8bc661ad75c4576eb13de5 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:00:54 +0100 Subject: [PATCH 26/36] fix stj assembly version for netstandard 2.0 --- dependencies/download.ps1 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index 195962d..39a6f7d 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -15,13 +15,17 @@ function CheckAssemblyVersion([string] $libFile, [string] $assemblyVersion) } } -function Download([string] $dependency, [string] $TFM, [string] $targetTFM = $null) +function Download([string] $dependency, [string] $TFM, [string] $targetTFM = $null, [string] $assemblyVersion = $null) { $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" @@ -112,4 +116,4 @@ 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' +Download -Dependency 'System.Text.Json' -TFM 'netstandard2.0' -assemblyVersion '6.0.0.0' From 9b1905f93cae5d75833e61cc1555ef8897fbfc6b Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:03:11 +0100 Subject: [PATCH 27/36] add missing dep --- dependencies/download.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index 39a6f7d..91652ee 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -117,3 +117,4 @@ Download -Dependency 'Microsoft.Bcl.AsyncInterfaces' -TFM 'net461' -TargetTFM 'n 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' From 90c21d58f2fd253f7ef8f5ad4f6bf4b559e3edf4 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:04:34 +0100 Subject: [PATCH 28/36] change 6.1 testing --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc288c8..56f3e59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -79,7 +79,8 @@ jobs: Get-Item ./module/Sentry.psd1 | Import-Module # Pester doesn't work on PowerShell 6.0 so our testing here is extremely limited. - if ("${{ matrix.version }}" -eq "6.0.0") { + # 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" } From 64e8594ceaeff722bda0c88e62ad0542d5049699 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:05:46 +0100 Subject: [PATCH 29/36] syntax error --- .github/workflows/test.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 56f3e59..9019c04 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -81,12 +81,15 @@ jobs: # 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" } - } else { + } + else + { $config = New-PesterConfiguration $config.Run.Path = "tests" $config.TestResult.Enabled = $true From 9e4d22c6751b97439fe9b7d4b6dfce2ab13623b4 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:09:00 +0100 Subject: [PATCH 30/36] missing deps --- dependencies/download.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index 91652ee..7824f81 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -118,3 +118,4 @@ Download -Dependency 'System.Threading.Tasks.Extensions' -TFM 'net461' -TargetTF 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' From 755aaed62f19f76b5185b85d181b9cbee3982d2d Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:15:10 +0100 Subject: [PATCH 31/36] formatting --- tools/settings.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/settings.ps1 b/tools/settings.ps1 index fb051b8..be7d058 100644 --- a/tools/settings.ps1 +++ b/tools/settings.ps1 @@ -7,4 +7,4 @@ $PSNativeCommandUseErrorActionPreference = $true if (Test-Path env:CI) { $DebugPreference = 'Continue' -} \ No newline at end of file +} From 2a4b246889f21f988a02c437c3eed7e84c5a10a0 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:28:10 +0100 Subject: [PATCH 32/36] try loading assemblies manually --- module/assemblies-loader.ps1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module/assemblies-loader.ps1 b/module/assemblies-loader.ps1 index feca9a5..146307a 100644 --- a/module/assemblies-loader.ps1 +++ b/module/assemblies-loader.ps1 @@ -30,14 +30,13 @@ 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()) { @@ -52,6 +51,9 @@ if ($type) } else { - Write-Debug "Loading Sentry assembly from $lib" - [Reflection.Assembly]::LoadFrom($lib) | Write-Debug + Write-Debug "Loading assemblies from $($dir):" + Get-ChildItem -Path $dir -Filter '*.dll' | ForEach-Object { + Write-Debug "Loading assembly: $($_.Name)" + [Reflection.Assembly]::LoadFrom($_.FullName) + } } From 002b20dc6e3035e8c1593b504e651c301ce9e0ca Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:38:32 +0100 Subject: [PATCH 33/36] logging --- dependencies/download.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dependencies/download.ps1 b/dependencies/download.ps1 index 7824f81..adec923 100644 --- a/dependencies/download.ps1 +++ b/dependencies/download.ps1 @@ -36,11 +36,12 @@ function Download([string] $dependency, [string] $TFM, [string] $targetTFM = $nu 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" } } From 998116f6f27d3dd3c47d2395f96b2aed44ed3094 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 17:39:29 +0100 Subject: [PATCH 34/36] logging fix --- module/assemblies-loader.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/assemblies-loader.ps1 b/module/assemblies-loader.ps1 index 146307a..05a6039 100644 --- a/module/assemblies-loader.ps1 +++ b/module/assemblies-loader.ps1 @@ -54,6 +54,6 @@ else Write-Debug "Loading assemblies from $($dir):" Get-ChildItem -Path $dir -Filter '*.dll' | ForEach-Object { Write-Debug "Loading assembly: $($_.Name)" - [Reflection.Assembly]::LoadFrom($_.FullName) + [Reflection.Assembly]::LoadFrom($_.FullName) | Write-Debug } } From 81c55a3ac76a6f2e4b162c1bf25bc20ece9a65a5 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 18:36:26 +0100 Subject: [PATCH 35/36] test output log --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9019c04..55644a8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -87,6 +87,7 @@ jobs: 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 { From 950ca157db6596bb036bc1c4ed7f484bade63569 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 12 Feb 2024 21:08:28 +0100 Subject: [PATCH 36/36] disable broken CI versions --- .github/workflows/test.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 55644a8..7ee6440 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,18 +16,19 @@ jobs: strategy: fail-fast: false matrix: - # Test all Powershell (core) versions on Ubuntu + # 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' + # - '7.1.0' + # - '7.0.0' - '6.2.0' - '6.1.0' - - '6.0.0' + # - '6.0.0' # And test all built-in PowerShell/Windows Powershell versions on latest CI runner images include: - os: ubuntu