Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exempt -RunAsAdmin requirement when run in GitHub Actions #77

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

sirredbeard
Copy link
Contributor

Addresses issue ScoopInstaller/Scoop#5800

Copy link
Member

@chawyehsu chawyehsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is currently already an exception for Windows Sandbox -and $env:USERNAME -ne 'WDAGUtilityAccount' in LOC121, it would be preferable to gather these conditions to one new line of if statement.

diff --git a/install.ps1 b/install.ps1
index 4e82228..00f48ae 100644
--- a/install.ps1
+++ b/install.ps1
@@ -118,7 +118,7 @@ function Test-ValidateParameter {
 function Test-IsAdministrator {
     return ([Security.Principal.WindowsPrincipal]`
             [Security.Principal.WindowsIdentity]::GetCurrent()`
-    ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -and $env:USERNAME -ne 'WDAGUtilityAccount'
+    ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
 }
 
 function Test-Prerequisite {
@@ -139,7 +139,12 @@ function Test-Prerequisite {
 
     # Detect if RunAsAdministrator, there is no need to run as administrator when installing Scoop.
     if (!$RunAsAdmin -and (Test-IsAdministrator)) {
-        Deny-Install "Running the installer as administrator is disabled by default, see https://github.com/ScoopInstaller/Install#for-admin for details."
+        # Exception: Windows Sandbox, GitHub Actions CI
+        $exception = ($env:USERNAME -eq 'WDAGUtilityAccount') -or ($env:GITHUB_ACTIONS -eq 'true' -and $env:CI -eq 'true')
+
+        if (!$exception) {
+            Deny-Install "Running the installer as administrator is disabled by default, see https://github.com/ScoopInstaller/Install#for-admin for details."
+        }
     }

@sirredbeard
Copy link
Contributor Author

That would work for me. Should I push that implementation to my branch, @chawyehsu?

@chawyehsu
Copy link
Member

yes please go ahead.

@sirredbeard sirredbeard force-pushed the gha_exempt_admin_check branch from 76216c9 to 7876856 Compare February 21, 2024 16:02
@sirredbeard
Copy link
Contributor Author

Pushed changes.

@chawyehsu chawyehsu merged commit 6cb16d3 into ScoopInstaller:master Feb 22, 2024
3 checks passed
@sirredbeard
Copy link
Contributor Author

Thank you @chawyehsu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants