diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 716cc079..377cdaef 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,8 +25,6 @@ jobs: run: go tool golangci-lint run --timeout=5m - name: Unit Tests run: make test - - name: Install Tests - run: make test-install - name: Upload coverage to Codecov uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0 with: @@ -34,6 +32,30 @@ jobs: files: ./coverage.out fail_ci_if_error: false + install-tests: + name: Install Tests + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + runs-on: ${{ matrix.os }} + permissions: + contents: read + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - name: Install Tests (Unix) + if: runner.os != 'Windows' + run: make test-install + - name: Install Tests (Windows) + if: runner.os == 'Windows' + shell: pwsh + run: ./scripts/install-windows-test.ps1 + # Monitor code coverage and TODO/FIXME-type comments health-score: name: Health Score diff --git a/scripts/install-windows-dev.ps1 b/scripts/install-windows-dev.ps1 index e24cfd22..b389c23a 100644 --- a/scripts/install-windows-dev.ps1 +++ b/scripts/install-windows-dev.ps1 @@ -163,7 +163,7 @@ function install_slack_cli { $slack_cli_new_binary_path = "$($slack_cli_dir)\bin\${confirmed_alias}.exe" delay 0.3 "Extracting the executable to:`n $slack_cli_new_binary_path" - Expand-Archive "$($slack_cli_dir)\slack_cli.zip" -DestinationPath "$($slack_cli_dir)" -Force + Microsoft.PowerShell.Archive\Expand-Archive "$($slack_cli_dir)\slack_cli.zip" -DestinationPath "$($slack_cli_dir)" -Force Move-Item -Path $slack_cli_binary_path -Destination $slack_cli_new_binary_path -Force $User = [System.EnvironmentVariableTarget]::User diff --git a/scripts/install-windows-test.ps1 b/scripts/install-windows-test.ps1 new file mode 100644 index 00000000..d5b6e11f --- /dev/null +++ b/scripts/install-windows-test.ps1 @@ -0,0 +1,76 @@ +# Copyright 2022-2026 Salesforce, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +$ErrorActionPreference = "Stop" + +$qualifiedCommand = "Microsoft.PowerShell.Archive\Expand-Archive" # https://github.com/slackapi/slack-cli/issues/651 +$installDir = Join-Path $env:LOCALAPPDATA "slack-cli" + +$cases = @( + @{ Installer = "install-windows.ps1"; Alias = "slack-test"; Version = "4.6.0"; ExpectVersion = $true }, + @{ Installer = "install-windows-dev.ps1"; Alias = "slack-dev-test"; Version = "dev"; ExpectVersion = $false } +) + +function Remove-Install { + if (Test-Path -LiteralPath $installDir) { + Remove-Item -LiteralPath $installDir -Recurse -Force + } +} + +foreach ($case in $cases) { + $installer = Join-Path $PSScriptRoot $case.Installer + $aliasBinary = Join-Path $installDir "bin\$($case.Alias).exe" + + $tokens = $null + $parseErrors = $null + $ast = [System.Management.Automation.Language.Parser]::ParseFile( + $installer, + [ref]$tokens, + [ref]$parseErrors + ) + + if ($parseErrors.Count -gt 0) { + throw "PowerShell parser errors in $installer" + } + + $archiveCommands = $ast.FindAll({ + param($node) + $node -is [System.Management.Automation.Language.CommandAst] -and + $node.GetCommandName() -like "*Expand-Archive" + }, $true) + + if ($archiveCommands.Count -ne 1 -or $archiveCommands[0].GetCommandName() -ne $qualifiedCommand) { + throw "$installer must call $qualifiedCommand exactly once" + } + + try { + Remove-Install + + & $installer -Alias $case.Alias -Version $case.Version -SkipGit $true + + if (!(Test-Path -LiteralPath $aliasBinary)) { + throw "$($case.Installer) did not place $($case.Alias).exe at $aliasBinary (extraction failed?)" + } + + $versionOutput = & $aliasBinary --version + if ($case.ExpectVersion -and $versionOutput -notmatch [regex]::Escape($case.Version)) { + throw "Version mismatch: expected '$($case.Version)' in output, got '$versionOutput'" + } + + Write-Host "$($case.Installer) E2E passed: $($case.Alias).exe installed, version '$versionOutput'" + } + finally { + Remove-Install + } +} diff --git a/scripts/install-windows.ps1 b/scripts/install-windows.ps1 index 63f6d70a..aa648390 100644 --- a/scripts/install-windows.ps1 +++ b/scripts/install-windows.ps1 @@ -154,7 +154,7 @@ function install_slack_cli { $slack_cli_new_binary_path = "$($slack_cli_dir)\bin\${confirmed_alias}.exe" delay 0.3 "Extracting the executable to:`n $slack_cli_new_binary_path" - Expand-Archive "$($slack_cli_dir)\slack_cli.zip" -DestinationPath "$($slack_cli_dir)" -Force + Microsoft.PowerShell.Archive\Expand-Archive "$($slack_cli_dir)\slack_cli.zip" -DestinationPath "$($slack_cli_dir)" -Force Move-Item -Path $slack_cli_binary_path -Destination $slack_cli_new_binary_path -Force $User = [System.EnvironmentVariableTarget]::User