From bd8f948efe32584bd92bca5b6044443e295510cc Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Thu, 19 Mar 2026 14:18:18 +0800 Subject: [PATCH] test: refactor ci testing Signed-off-by: Chawye Hsu --- .editorconfig | 3 ++ .github/scripts/e2e-test.ps1 | 27 +++++++++++++ .github/workflows/ci.yml | 75 +++++++++++------------------------- 3 files changed, 53 insertions(+), 52 deletions(-) create mode 100644 .github/scripts/e2e-test.ps1 diff --git a/.editorconfig b/.editorconfig index 295096e..bea7990 100644 --- a/.editorconfig +++ b/.editorconfig @@ -10,3 +10,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/scripts/e2e-test.ps1 b/.github/scripts/e2e-test.ps1 new file mode 100644 index 0000000..444fbe4 --- /dev/null +++ b/.github/scripts/e2e-test.ps1 @@ -0,0 +1,27 @@ +#Requires -Version 5.1 + +$ErrorActionPreference = 'Stop' + +if ($env:CI -ne $true -or $env:GITHUB_ACTIONS -ne $true) { + throw 'This script is intended to be run in GitHub Actions CI environment only' +} + +Write-Output "$Env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append +$WorkingRoot = "$PSScriptRoot\..\.." + +# Typical installation +& "$WorkingRoot\install.ps1" +if (-not (Test-Path -Path "$Env:USERPROFILE\.config\scoop\config.json")) { + throw 'Scoop config file should exist after installation' +} +scoop help +Remove-Item -Path "$Env:USERPROFILE\scoop" -Recurse -Force -ErrorAction SilentlyContinue + +# Fall back to download zips when git not available +git config --global protocol.https.allow never +# Custom installation directory +$CustomScoopDir = "$Env:USERPROFILE\custom_scoop" +& "$WorkingRoot\install.ps1" -ScoopDir $CustomScoopDir +Write-Output "$CustomScoopDir\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append +scoop help +Get-Content -Raw -Path "$env:USERPROFILE\.config\scoop\config.json" | Write-Output diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 64a62db..f7ef8e7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Scoop Installer CI Tests +name: CI on: push: @@ -6,68 +6,39 @@ on: workflow_dispatch: jobs: - test_powershell: - name: WindowsPowerShell + unit_test: + name: Unit Test runs-on: windows-latest + strategy: + matrix: + shell: [powershell, pwsh] + defaults: + run: + shell: ${{ matrix.shell }} steps: - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 with: + # Need at least 2 commits to properly gather changed files for linting fetch-depth: 2 - - name: Init Test Suite + - name: Install and cache test dependencies uses: potatoqualitee/psmodulecache@ee5e9494714abf56f6efbfa51527b2aec5c761b8 # v6.2.1 with: modules-to-cache: PSScriptAnalyzer, BuildHelpers, Pester - shell: powershell - - name: Test Scoop Installer - shell: powershell + shell: ${{ matrix.shell }} + - name: Run tests run: ./test/bin/test.ps1 - - name: Test Scoop Install command - shell: powershell - run: | - ./install.ps1 -RunAsAdmin - echo "$Env:USERPROFILE\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Test scoop command availability - shell: powershell - run: scoop help - test_pwsh_cloning: - name: PowerShell (with cloning) + e2e_test: + name: E2E Test runs-on: windows-latest + strategy: + matrix: + shell: [powershell, pwsh] + defaults: + run: + shell: ${{ matrix.shell }} steps: - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - with: - fetch-depth: 2 - - name: Init Test Suite - uses: potatoqualitee/psmodulecache@ee5e9494714abf56f6efbfa51527b2aec5c761b8 # v6.2.1 - with: - modules-to-cache: PSScriptAnalyzer, BuildHelpers, Pester - shell: pwsh - - name: Test Scoop Installer - shell: pwsh - run: ./test/bin/test.ps1 - - name: Test Scoop Install command - shell: pwsh - run: | - ./install.ps1 -RunAsAdmin - echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Test scoop command availability - shell: pwsh - run: scoop help - test_pwsh_download: - name: PowerShell (with downloading) - runs-on: windows-latest - steps: - - name: Checkout - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - with: - fetch-depth: 2 - - name: Test Scoop Install command - shell: pwsh - run: | - git config --global protocol.https.allow never - ./install.ps1 -RunAsAdmin - echo "~\scoop\shims" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append - - name: Test scoop command availability - shell: pwsh - run: scoop help + - name: Run tests + run: ./.github/scripts/e2e-test.ps1