From dbd3b7c43f12b676ea4a9218336c0f8c62485f46 Mon Sep 17 00:00:00 2001 From: Austin Vazquez Date: Wed, 3 Jul 2024 07:11:35 -0700 Subject: [PATCH] ci: apply WSL hanging workaround to MSI builder This change refactors the WSL hanging workaround into a reusable GitHub composite action and applies it to the MSI builder workflow. Signed-off-by: Austin Vazquez --- .../actions/cleanup-windows-env/action.yml | 46 ++++++++++++ .github/workflows/build-and-test-msi.yaml | 73 +++---------------- .github/workflows/ci.yaml | 29 +------- 3 files changed, 62 insertions(+), 86 deletions(-) create mode 100644 .github/actions/cleanup-windows-env/action.yml diff --git a/.github/actions/cleanup-windows-env/action.yml b/.github/actions/cleanup-windows-env/action.yml new file mode 100644 index 000000000..2fe9d6295 --- /dev/null +++ b/.github/actions/cleanup-windows-env/action.yml @@ -0,0 +1,46 @@ +name: "Clean Up Windows Environment" +description: "Reusable action to clean up the virtual machine for Finch on Windows" +inputs: + deep-clean: + default: true + description: "Clean up Finch virtual machine and configuration files only" + +runs: + using: composite + steps: + - name: Remove Finch VM + timeout: 3 minutes + run: | + wsl --list --verbose + wsl --shutdown + wsl --unregister lima-finch + wsl --list --verbose + + # This is a workaround for https://github.com/microsoft/WSL/issues/8529 + # + # If WSL is suspected of hanging for longer than 180 seconds, then + # kill the WSL service and retry the shutdown command. + - name: Force remove Finch VM + needs: remove-vm + if: failure() + timeout: 3 minutes + run: | + $ErrorActionPreference = 'Ignore' + taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0" + wsl --list --verbose + wsl --shutdown + Start-Sleep -s 10 + wsl --unregister lima-finch + wsl --list --verbose + + - name: Clean up Finch application data + run: | + Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore + exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore + + - name: Clean up Finch configuration and artifacts + if: inputs.deep-clean + run: | + Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore + make clean + exit 0 # Cleanup may set the exit code e.g. if a file doesn't exist; just ignore diff --git a/.github/workflows/build-and-test-msi.yaml b/.github/workflows/build-and-test-msi.yaml index 71c7166a6..7dd3fc856 100644 --- a/.github/workflows/build-and-test-msi.yaml +++ b/.github/workflows/build-and-test-msi.yaml @@ -73,27 +73,14 @@ jobs: fetch-depth: 0 persist-credentials: false submodules: recursive + - name: Ensure runner environment is in clean state + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env - name: configure aws credentials uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 with: role-to-assume: ${{ secrets.WINDOWS_ROLE }} role-session-name: windows-msi aws-region: ${{ secrets.WINDOWS_REGION }} - - name: Remove Finch VM - run: | - $ErrorActionPreference = 'Ignore' - taskkill /f /im wslservice.exe 2> nul || cmd /c "exit /b 0" - wsl --list --verbose - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - - name: Clean up previous files - run: | - takeown /F C:\actions-runner\_work\finch /R - Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore - make clean - cd deps/finch-core && make clean - name: Build project run: | make FINCH_OS_IMAGE_LOCATION_ROOT=__INSTALLFOLDER__ @@ -143,20 +130,9 @@ jobs: run: | $tag="${{ needs.get-tag-name.outputs.tag }}" aws s3 cp "./msi-builder/build/signed/Finch-$tag.msi" "s3://${{ secrets.INSTALLER_PRIVATE_BUCKET_NAME }}/Finch-$tag.msi" --no-progress - - name: Remove Finch VM and Clean Up Previous Environment + - name: Clean up runner if: ${{ always() }} - 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 - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse - 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 + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env msi-e2e-tests: needs: @@ -185,6 +161,8 @@ jobs: fetch-depth: 0 persist-credentials: false submodules: recursive + - name: Ensure runner environment is in clean state + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env - name: Set output variables id: vars run: | @@ -197,18 +175,6 @@ jobs: role-to-assume: ${{ secrets.ROLE }} role-session-name: msi-test aws-region: ${{ secrets.REGION }} - - name: Remove Finch VM - run: | - wsl --list --verbose - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - - name: Clean up previous files - run: | - Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore - make clean - cd deps/finch-core && make clean - name: Uninstall Finch silently run: | $productCode = (Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "*Finch*" } | Select-Object -ExpandProperty IdentifyingNumber) @@ -239,14 +205,10 @@ jobs: git clean -f -d $env:INSTALLED="true" make test-e2e-vm - - name: Remove Finch VM - run: | - wsl --list --verbose - wsl --shutdown - Start-Sleep -s 10 - wsl --unregister lima-finch - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse - wsl --list --verbose + - name: Remove Finch VM and application data + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env + with: + deep-clean: false - name: Run container e2e tests uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0 with: @@ -270,17 +232,6 @@ jobs: } else { Write-Output "Finch not found or it wasn't installed using MSI." } - - name: Remove Finch VM and Clean Up Previous Environment + - name: Clean up runner if: ${{ always() }} - 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 - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse - 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 + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b2a917b1e..892a500d1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -225,6 +225,8 @@ jobs: fetch-depth: 0 persist-credentials: false submodules: recursive + - name: Ensure runner environment is in clean state + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env - name: Set output variables id: vars run: | @@ -238,18 +240,6 @@ jobs: role-to-assume: ${{ secrets.ROLE }} role-session-name: credhelper-test aws-region: ${{ secrets.REGION }} - - name: Remove Finch VM - run: | - wsl --list --verbose - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - - name: Clean up previous files - run: | - Remove-Item C:\Users\Administrator\.finch -Recurse -ErrorAction Ignore - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse -ErrorAction Ignore - make clean - cd deps/finch-core && make clean - name: Build project run: | git status @@ -266,20 +256,9 @@ jobs: git status git clean -f -d make ${{ matrix.test-command }} - - name: Remove Finch VM and Clean Up Previous Environment + - name: Clean up runner if: ${{ always() }} - 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 - wsl --shutdown - wsl --unregister lima-finch - wsl --list --verbose - Remove-Item C:\Users\Administrator\AppData\Local\.finch -Recurse - 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 + uses: ${{ github.workspace }}/.github/actions/cleanup-windows-env mdlint: runs-on: ubuntu-latest steps: