Skip to content

Commit f85dc03

Browse files
subashkothaSubash Kotha
andauthored
ci: Update Remove Finch VM step to only shutdown if required (runfinch#1182)
* 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]>
1 parent 3a81c08 commit f85dc03

File tree

3 files changed

+40
-64
lines changed

3 files changed

+40
-64
lines changed

.github/workflows/build-and-test-msi.yaml

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,8 @@ jobs:
8181
aws-region: ${{ secrets.WINDOWS_REGION }}
8282
- name: Remove Finch VM
8383
timeout-minutes: 2
84-
run: |
85-
$ErrorActionPreference = 'Ignore'
86-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
87-
wsl --list --verbose
88-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
89-
wsl --shutdown
90-
wsl --unregister lima-finch
91-
wsl --list --verbose
84+
shell: pwsh
85+
run: ./scripts/cleanup_wsl.ps1
9286
- name: Clean up previous files
9387
run: |
9488
takeown /F C:\actions-runner\_work\finch /R
@@ -148,16 +142,9 @@ jobs:
148142
- name: Remove Finch VM and Clean Up Previous Environment
149143
if: ${{ always() }}
150144
timeout-minutes: 2
145+
shell: pwsh
151146
run: |
152-
# We want these cleanup commands to always run, ignore errors so the step completes.
153-
$ErrorActionPreference = 'Ignore'
154-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
155-
wsl --list --verbose
156-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
157-
wsl --shutdown
158-
wsl --unregister lima-finch
159-
wsl --list --verbose
160-
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
147+
./scripts/cleanup_wsl.ps1
161148
make clean
162149
cd deps/finch-core && make clean
163150
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore
@@ -203,15 +190,8 @@ jobs:
203190
aws-region: ${{ secrets.REGION }}
204191
- name: Remove Finch VM
205192
timeout-minutes: 2
206-
run: |
207-
# We want these cleanup commands to always run, ignore errors so the step completes.
208-
$ErrorActionPreference = 'Ignore'
209-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
210-
wsl --list --verbose
211-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
212-
wsl --shutdown
213-
wsl --unregister lima-finch
214-
wsl --list --verbose
193+
shell: pwsh
194+
run: ./scripts/cleanup_wsl.ps1
215195
- name: Clean up previous files
216196
run: |
217197
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
@@ -250,17 +230,8 @@ jobs:
250230
make test-e2e-vm
251231
- name: Remove Finch VM
252232
timeout-minutes: 2
253-
run: |
254-
# We want these cleanup commands to always run, ignore errors so the step completes.
255-
$ErrorActionPreference = 'Ignore'
256-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
257-
wsl --list --verbose
258-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
259-
wsl --shutdown
260-
Start-Sleep -s 10
261-
wsl --unregister lima-finch
262-
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
263-
wsl --list --verbose
233+
shell: pwsh
234+
run: ./scripts/cleanup_wsl.ps1
264235
- name: Run container e2e tests
265236
uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
266237
with:
@@ -287,16 +258,9 @@ jobs:
287258
- name: Remove Finch VM and Clean Up Previous Environment
288259
if: ${{ always() }}
289260
timeout-minutes: 2
261+
shell: pwsh
290262
run: |
291-
# We want these cleanup commands to always run, ignore errors so the step completes.
292-
$ErrorActionPreference = 'Ignore'
293-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
294-
wsl --list --verbose
295-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
296-
wsl --shutdown
297-
wsl --unregister lima-finch
298-
wsl --list --verbose
299-
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
263+
./scripts/cleanup_wsl.ps1
300264
make clean
301265
cd deps/finch-core && make clean
302266
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore

.github/workflows/e2e-windows.yaml

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,7 @@ jobs:
5959
aws-region: ${{ secrets.REGION }}
6060
- name: Remove Finch VM
6161
timeout-minutes: 2
62-
run: |
63-
# We want these cleanup commands to always run, ignore errors so the step completes.
64-
$ErrorActionPreference = 'Ignore'
65-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
66-
wsl --list --verbose
67-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
68-
wsl --shutdown
69-
wsl --unregister lima-finch
70-
wsl --list --verbose
62+
run: ./scripts/cleanup_wsl.ps1
7163
- name: Clean up previous files
7264
run: |
7365
Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore
@@ -94,15 +86,7 @@ jobs:
9486
if: ${{ always() }}
9587
timeout-minutes: 2
9688
run: |
97-
# We want these cleanup commands to always run, ignore errors so the step completes.
98-
$ErrorActionPreference = 'Ignore'
99-
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
100-
wsl --list --verbose
101-
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
102-
wsl --shutdown
103-
wsl --unregister lima-finch
104-
wsl --list --verbose
105-
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse
89+
./scripts/cleanup_wsl.ps1
10690
make clean
10791
cd deps/finch-core && make clean
10892
exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore

scripts/cleanup_wsl.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# We want these cleanup commands to always run, ignore errors so the step completes.
5+
$ErrorActionPreference = 'Ignore'
6+
7+
taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0"
8+
sc query LxssManager | findstr "STATE" | findstr /C:"STOPPED" > nul && net start LxssManager
9+
wsl --list --verbose --all
10+
11+
# Attempt to shut down WSL if any distribution is running
12+
if (wsl --list --verbose | findstr /C:"Running" > nul) {
13+
timeout 60s wsl --shutdown
14+
# Forcefully kill WSL if still running
15+
if (Get-Process -Name "wsl" -ErrorAction SilentlyContinue) {
16+
Stop-Process -Name "wsl" -Force
17+
}
18+
echo "WSL has been shut down successfully."
19+
}
20+
21+
# Unregister 'lima-finch' distribution if it exists
22+
if (wsl --list --quiet | findstr /C:"lima-finch" > nul) {
23+
wsl --unregister lima-finch
24+
echo "'lima-finch' has been unregistered successfully."
25+
}
26+
27+
wsl --list --verbose --all
28+
Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse

0 commit comments

Comments
 (0)