diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7ef8e7..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,5 +43,25 @@ 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: + 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 + with: + persist-credentials: false + - name: Run + run: | + Get-Content -Raw -Path ./install.ps1 | Invoke-Expression + scoop help diff --git a/install.ps1 b/install.ps1 index 74841db..48c6b61 100644 --- a/install.ps1 +++ b/install.ps1 @@ -712,6 +712,34 @@ 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 + $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 $IS_EXECUTED_FROM_IEX = ($null -eq $MyInvocation.MyCommand.Path) @@ -742,7 +770,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' {