Skip to content

[WIP] Nonadmin on windows #165

[WIP] Nonadmin on windows

[WIP] Nonadmin on windows #165

name: Windows Nightly Run
on: [pull_request]
jobs:
start-ec2-instance:
uses: ./.github/workflows/provision-runner.yml
with:
ec2-image-id: ami-01fa2492704e48175
ec2-instance-type: t2.micro
security-group-id: sg-0a3e6b53e86d0e69d
subnet-id: subnet-06113672589e7e836
ec2-os-type: windows
secrets:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
github-token: ${{ secrets.GH_RUNNER_API_TOKEN }}
nonadmin-password: ${{ secrets.NONADMIN_PASSWORD }}
run-tests:
needs: start-ec2-instance
runs-on: ${{ needs.start-ec2-instance.outputs.instance_label }}
steps:
# - name: Write Test Script
# shell: powershell
# run: |
# # Ensure the directory exists
# $runnerDir = "C:\Users\nonadmin\Documents\actions-runner\work"
# if (-not (Test-Path -Path $runnerDir)) {
# New-Item -Path $runnerDir -ItemType Directory -Force
# }
#
# # Create the test script
# $scriptContent = @"
# # Redirect output directly in the script
# code --version >> "C:\Users\nonadmin\Documents\actions-runner\work\run-tests-output.log" 2>> "C:\Users\nonadmin\Documents\actions-runner\work\run-tests-error.log"
# node --version >> "C:\Users\nonadmin\Documents\actions-runner\work\run-tests-output.log" 2>> "C:\Users\nonadmin\Documents\actions-runner\work\run-tests-error.log"
# "@
#
# $scriptPath = "$runnerDir\run-tests.ps1"
# $scriptContent | Out-File -FilePath $scriptPath -Encoding utf8 -Force
- name: Run Test Script with PsExec
shell: powershell
run: |
# Define paths
$psExecUrl = "https://download.sysinternals.com/files/PSTools.zip"
$toolsDir = "C:\tools"
$psExecPath = "$toolsDir\PsExec64.exe"
$logDir = "C:\Users\nonadmin\Documents\actions-runner\work"
$logPathOut = "$logDir\run-tests-output.log"
$logPathErr = "$logDir\run-tests-error.log"
# Step 1: Install PsExec
Write-Output "Downloading and installing PsExec..."
if (Test-Path -Path $toolsDir) { Remove-Item -Recurse -Force $toolsDir }
New-Item -Path $toolsDir -ItemType Directory -Force
Invoke-WebRequest -Uri $psExecUrl -OutFile "$toolsDir\PSTools.zip"
Expand-Archive -Path "$toolsDir\PSTools.zip" -DestinationPath $toolsDir -Force
Write-Output "PsExec installed successfully."
# Step 3: Execute the command using PsExec
Write-Output "Executing PsExec as nonadmin to run 'code --version'..."
Write-Output "PsExec Path: $psExecPath"
Write-Output "Executing command: & $psExecPath -accepteula -nobanner -u nonadmin -p 'pass123!' powershell.exe -Command \"hostname > 'C:\Users\nonadmin\abcde.txt' 2>&1\""
# Check if the log file exists remotely and print its content
Write-Output "Reading the log file from the EC2 instance..."
& $psExecPath -accepteula -nobanner -u nonadmin -p 'pass123!' powershell.exe -Command "Get-Content 'C:\Users\nonadmin\abcde.txt'"
Write-Output "==========="
# stop-ec2-instance:
# needs: [ start-ec2-instance, run-tests ]
# if: always()
# uses: ./.github/workflows/remove-runner.yml
# with:
# ec2-instance-id: ${{ needs.start-ec2-instance.outputs.ec2-instance-id }}
# ec2-runner-label: ${{ needs.start-ec2-instance.outputs.instance_label }}
# secrets:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# github-token: ${{ secrets.GH_RUNNER_API_TOKEN }}