From 183da97a00d5d10757658c96ceca3c8536e1927a Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Fri, 28 Aug 2026 01:42:13 +0800 Subject: [PATCH 1/4] fix: allow dot-sourced install in CI with opt-out Signed-off-by: Chawye Hsu --- install.ps1 | 27 ++++++++++++++++++++++++++- test/install.Tests.ps1 | 8 ++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index 74841db..091d74d 100644 --- a/install.ps1 +++ b/install.ps1 @@ -712,6 +712,26 @@ function Write-DebugInfo { Write-Verbose "SCOOP_CONFIG_HOME: $SCOOP_CONFIG_HOME" } +function Test-ShouldRunInstall { + param( + [Parameter(Mandatory = $True)] + [String] $InvocationName + ) + + # not dot-sourced, run the install flow + if ($InvocationName -ne '.') { + return $true + } + + # dot-sourced, but not in CI, don't run the install flow + if (-not $env:CI) { + return $false + } + + # dot-sourced, in CI, determined by env SCOOP_NOINSTALL + return (-not $env:SCOOP_NOINSTALL) +} + # Prepare variables $IS_EXECUTED_FROM_IEX = ($null -eq $MyInvocation.MyCommand.Path) @@ -742,7 +762,12 @@ $SCOOP_MAIN_BUCKET_GIT_REPO = 'https://github.com/ScoopInstaller/Main.git' # not when dot-sourced. Dot-sourcing the installer will not trigger the # installation, and only the functions will be loaded, e.g., for testing. # Downstreams can call `Install-Scoop` explicitly to start the installation. -if ($MyInvocation.InvocationName -ne '.') { +# In CI, dot-sourced execution is allowed by default as GitHub Actions executors +# run the job step in a dot-sourced session. To disable the install flow in CI, +# set `SCOOP_NOINSTALL=true` to force dot-sourced CI sessions to only +# load functions. +$shouldRunInstall = Test-ShouldRunInstall -InvocationName $MyInvocation.InvocationName +if ($shouldRunInstall) { $oldErrorActionPreference = $ErrorActionPreference try { $ErrorActionPreference = 'Stop' diff --git a/test/install.Tests.ps1 b/test/install.Tests.ps1 index 4a6548d..3216745 100644 --- a/test/install.Tests.ps1 +++ b/test/install.Tests.ps1 @@ -1,9 +1,11 @@ BeforeAll { $script:OriginalScoop = $env:SCOOP $script:OriginalScoopGlobal = $env:SCOOP_GLOBAL + $script:OriginalScoopNoInstall = $env:SCOOP_NOINSTALL $env:SCOOP = Join-Path $TestDrive 'scoop' $env:SCOOP_GLOBAL = Join-Path $TestDrive 'scoop-global' + $env:SCOOP_NOINSTALL = 'true' # Load SUT $sut = (Split-Path -Leaf $PSCommandPath).Replace('.Tests.ps1', '.ps1') @@ -22,6 +24,12 @@ AfterAll { } else { $env:SCOOP_GLOBAL = $script:OriginalScoopGlobal } + + if ($null -eq $script:OriginalScoopNoInstall) { + Remove-Item Env:SCOOP_NOINSTALL -ErrorAction SilentlyContinue + } else { + $env:SCOOP_NOINSTALL = $script:OriginalScoopNoInstall + } } Describe 'Get-Downloader' -Tag 'Proxy' { From c33d455ea08e6efdc5c5ac337a53b8489876c0d6 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Fri, 28 Aug 2026 02:19:58 +0800 Subject: [PATCH 2/4] ci: add IEX simulation CI job Signed-off-by: Chawye Hsu --- .github/workflows/ci.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7ef8e7..788bbb9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,3 +42,19 @@ jobs: uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 - name: Run tests run: ./.github/scripts/e2e-test.ps1 + ci_iex: + name: CI IEX Simulation + runs-on: windows-latest + strategy: + matrix: + shell: [powershell, pwsh] + defaults: + run: + shell: ${{ matrix.shell }} + steps: + - name: Checkout + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + - name: Run + run: | + Get-Content -Raw -Path ./install.ps1 | Invoke-Expression + scoop help From 8499239ad390deae83054a4f951137286b9d5f77 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Fri, 28 Aug 2026 02:34:43 +0800 Subject: [PATCH 3/4] fix: parse SCOOP_NOINSTALL truthy values Signed-off-by: Chawye Hsu --- install.ps1 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/install.ps1 b/install.ps1 index 091d74d..48c6b61 100644 --- a/install.ps1 +++ b/install.ps1 @@ -729,7 +729,15 @@ function Test-ShouldRunInstall { } # dot-sourced, in CI, determined by env SCOOP_NOINSTALL - return (-not $env:SCOOP_NOINSTALL) + $should = $true + if ($null -ne $env:SCOOP_NOINSTALL) { + $value = $env:SCOOP_NOINSTALL.ToString().Trim().ToLowerInvariant() + if ($value -in @('1', 'true', 'yes', 'on')) { + $should = $false + } + } + + return $should } # Prepare variables From 6328555730066318b5a63833bd6a7786d79c8aa9 Mon Sep 17 00:00:00 2001 From: Chawye Hsu Date: Fri, 28 Aug 2026 02:36:54 +0800 Subject: [PATCH 4/4] ci: restrict workflow permissions and disable credential persistence Signed-off-by: Chawye Hsu --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 788bbb9..81f9e46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,8 @@ on: pull_request: workflow_dispatch: +permissions: {} + jobs: unit_test: name: Unit Test @@ -21,6 +23,7 @@ jobs: with: # Need at least 2 commits to properly gather changed files for linting fetch-depth: 2 + persist-credentials: false - name: Install and cache test dependencies uses: potatoqualitee/psmodulecache@ee5e9494714abf56f6efbfa51527b2aec5c761b8 # v6.2.1 with: @@ -40,6 +43,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false - name: Run tests run: ./.github/scripts/e2e-test.ps1 ci_iex: @@ -54,6 +59,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 + with: + persist-credentials: false - name: Run run: | Get-Content -Raw -Path ./install.ps1 | Invoke-Expression