Skip to content

Commit

Permalink
ci: Update Remove Finch VM step to only shutdown if required (#1182)
Browse files Browse the repository at this point in the history
* ci: Update Remove Finch VM step

Signed-off-by: Subash Kotha <[email protected]>

* ci: Shutdown only if there are running distributions

Signed-off-by: Subash Kotha <[email protected]>

* ci: Create and reuse script to clean up WSL

Signed-off-by: Subash Kotha <[email protected]>

---------

Signed-off-by: Subash Kotha <[email protected]>
Co-authored-by: Subash Kotha <[email protected]>
  • Loading branch information
subashkotha and Subash Kotha authored Nov 14, 2024
1 parent 3a81c08 commit f85dc03
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 64 deletions.
56 changes: 10 additions & 46 deletions .github/workflows/build-and-test-msi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,8 @@ jobs:
aws-region: ${{ secrets.WINDOWS_REGION }}
- name: Remove Finch VM
timeout-minutes: 2
run: |
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
shell: pwsh
run: ./scripts/cleanup_wsl.ps1
- name: Clean up previous files
run: |
takeown /F C:\actions-runner\_work\finch /R
Expand Down Expand Up @@ -148,16 +142,9 @@ jobs:
- name: Remove Finch VM and Clean Up Previous Environment
if: ${{ always() }}
timeout-minutes: 2
shell: pwsh
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
./scripts/cleanup_wsl.ps1
make clean
cd deps/finch-core && make clean
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore
Expand Down Expand Up @@ -203,15 +190,8 @@ jobs:
aws-region: ${{ secrets.REGION }}
- name: Remove Finch VM
timeout-minutes: 2
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
shell: pwsh
run: ./scripts/cleanup_wsl.ps1
- name: Clean up previous files
run: |
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
Expand Down Expand Up @@ -250,17 +230,8 @@ jobs:
make test-e2e-vm
- name: Remove Finch VM
timeout-minutes: 2
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
Start-Sleep -s 10
wsl --unregister lima-finch
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
wsl --list --verbose
shell: pwsh
run: ./scripts/cleanup_wsl.ps1
- name: Run container e2e tests
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
with:
Expand All @@ -287,16 +258,9 @@ jobs:
- name: Remove Finch VM and Clean Up Previous Environment
if: ${{ always() }}
timeout-minutes: 2
shell: pwsh
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
./scripts/cleanup_wsl.ps1
make clean
cd deps/finch-core && make clean
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore
20 changes: 2 additions & 18 deletions .github/workflows/e2e-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,7 @@ jobs:
aws-region: ${{ secrets.REGION }}
- name: Remove Finch VM
timeout-minutes: 2
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
run: ./scripts/cleanup_wsl.ps1
- name: Clean up previous files
run: |
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
Expand All @@ -94,15 +86,7 @@ jobs:
if: ${{ always() }}
timeout-minutes: 2
run: |
# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
wsl --list --verbose
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --shutdown
wsl --unregister lima-finch
wsl --list --verbose
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
./scripts/cleanup_wsl.ps1
make clean
cd deps/finch-core && make clean
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore
28 changes: 28 additions & 0 deletions scripts/cleanup_wsl.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0

# We want these cleanup commands to always run, ignore errors so the step completes.
$ErrorActionPreference = 'Ignore'

taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
wsl --list --verbose --all

# Attempt to shut down WSL if any distribution is running
if (wsl --list --verbose | findstr /C:"Running" > nul) {
timeout 60s wsl --shutdown
# Forcefully kill WSL if still running
if (Get-Process -Name "wsl" -ErrorAction SilentlyContinue) {
Stop-Process -Name "wsl" -Force
}
echo "WSL has been shut down successfully."
}

# Unregister 'lima-finch' distribution if it exists
if (wsl --list --quiet | findstr /C:"lima-finch" > nul) {
wsl --unregister lima-finch
echo "'lima-finch' has been unregistered successfully."
}

wsl --list --verbose --all
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse

0 comments on commit f85dc03

Please sign in to comment.