refactor(main): improve asyncio event loop handling in main function #240
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PR Check | |
| on: | |
| pull_request: | |
| types: | |
| - opened | |
| - reopened | |
| - synchronize | |
| - ready_for_review | |
| permissions: | |
| contents: read | |
| env: | |
| PYTHON_VERSION: '3.14' | |
| jobs: | |
| ruff-lint: | |
| runs-on: windows-latest | |
| name: Ruff Format & Lint Check | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| - name: Install Ruff | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install ruff | |
| shell: pwsh | |
| - name: Run Ruff Format Check | |
| id: ruff_format | |
| continue-on-error: true | |
| run: | | |
| ruff format --check --diff . 2>&1 | Tee-Object -FilePath "format_output.txt" | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "::error::Ruff format check failed" | |
| exit 1 | |
| } | |
| shell: pwsh | |
| - name: Run Ruff Lint Check | |
| id: ruff_lint | |
| continue-on-error: true | |
| run: | | |
| ruff check --output-format=full . 2>&1 | Tee-Object -FilePath "lint_output.txt" | |
| if ($LASTEXITCODE -ne 0) { | |
| Write-Host "::error::Ruff lint check failed" | |
| exit 1 | |
| } | |
| shell: pwsh | |
| - name: Prepare Artifacts | |
| if: always() | |
| run: | | |
| $prNumber = "${{ github.event.pull_request.number }}" | |
| $prNumber | Out-File "pr_number.txt" -Encoding utf8 | |
| if ($env:Step_Ruff_Format_Outcome -eq 'failure' -or $env:Step_Ruff_Lint_Outcome -eq 'failure') { | |
| $comment = "## ❌ Ruff Lint Check Failed`n`n" | |
| $comment += "The code quality checks did not pass. Please review and fix the issues below:`n`n" | |
| if ($env:Step_Ruff_Format_Outcome -eq 'failure' -and (Test-Path "format_output.txt")) { | |
| $formatOutput = Get-Content "format_output.txt" -Raw | |
| if ($formatOutput -and $formatOutput.Trim() -ne "") { | |
| $comment += "### 📝 Format Issues`n`n" | |
| $comment += "The following code needs formatting. Here are the differences:`n`n" | |
| $comment += "``````diff`n" | |
| $comment += $formatOutput.TrimEnd() | |
| $comment += "`n``````" | |
| $comment += "`n`n**To fix:** Run ``ruff format .`` in your local repository.`n`n" | |
| } | |
| } | |
| if ($env:Step_Ruff_Lint_Outcome -eq 'failure' -and (Test-Path "lint_output.txt")) { | |
| $lintOutput = Get-Content "lint_output.txt" -Raw | |
| if ($lintOutput -and $lintOutput.Trim() -ne "") { | |
| $comment += "### 🔍 Lint Issues`n`n" | |
| $comment += "The following issues were found:`n`n" | |
| $comment += "``````text`n" | |
| $comment += $lintOutput.TrimEnd() | |
| $comment += "`n``````" | |
| $comment += "`n`n**To fix:** Run ``ruff check --fix .`` to automatically fix some issues, or fix them manually.`n`n" | |
| } | |
| } | |
| $comment += "---`n" | |
| $comment += "**Note:** The build will be skipped until these issues are resolved.`n" | |
| $comment += "Please commit the fixes and push to this PR branch." | |
| $comment | Out-File "comment.txt" -Encoding utf8 | |
| } | |
| env: | |
| Step_Ruff_Format_Outcome: ${{ steps.ruff_format.outcome }} | |
| Step_Ruff_Lint_Outcome: ${{ steps.ruff_lint.outcome }} | |
| shell: pwsh | |
| - name: Upload Artifacts | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: pr-metadata | |
| path: | | |
| pr_number.txt | |
| comment.txt | |
| retention-days: 1 | |
| - name: Fail if checks failed | |
| if: steps.ruff_format.outcome == 'failure' || steps.ruff_lint.outcome == 'failure' | |
| run: | | |
| Write-Host "Ruff checks failed." | |
| exit 1 | |
| shell: pwsh | |
| build-x64: | |
| needs: ruff-lint | |
| if: success() && github.event.pull_request.draft == false | |
| runs-on: windows-latest | |
| name: Build (x64) | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| architecture: x64 | |
| - name: Create virtual environment | |
| run: | | |
| python -m venv venv | |
| shell: pwsh | |
| - name: Get App Info | |
| id: get_info | |
| run: | | |
| .\venv\Scripts\Activate | |
| $currentDateTime = Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC' | |
| echo "BUILD_DATETIME=$currentDateTime" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| $prNumber = "${{ github.event.pull_request.number }}" | |
| echo "PR_NUMBER=$prNumber" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "BUILD_DATETIME=$currentDateTime" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| echo "PR_NUMBER=$prNumber" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| shell: pwsh | |
| - name: Update Release Channel | |
| run: | | |
| .\venv\Scripts\Activate | |
| $settingsPath = 'src/settings.py' | |
| $content = Get-Content $settingsPath -Raw | |
| $replacement = 'RELEASE_CHANNEL = "pr-' + $env:PR_NUMBER + '"' | |
| $content = $content -replace 'RELEASE_CHANNEL = "[^"]*"', $replacement | |
| Set-Content -Path $settingsPath -Value $content -NoNewline | |
| Write-Host "Updated RELEASE_CHANNEL to pr-$env:PR_NUMBER" | |
| shell: pwsh | |
| - name: Install dependencies | |
| run: | | |
| .\venv\Scripts\Activate | |
| python -m pip install --upgrade pip | |
| pip install --force --no-cache .[packaging] | |
| shell: pwsh | |
| - name: Build Installer | |
| run: | | |
| .\venv\Scripts\Activate | |
| cd src | |
| python build.py build | |
| python build.py bdist_msi | |
| shell: pwsh | |
| - name: Upload Build Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: yasb-dev-pr-${{ steps.get_info.outputs.PR_NUMBER }}-x64 | |
| path: | | |
| src/dist/out/*.msi | |
| retention-days: 7 | |
| build-arm64: | |
| needs: ruff-lint | |
| if: success() && github.event.pull_request.draft == false | |
| runs-on: windows-11-arm | |
| name: Build (arm64) | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.pull_request.head.sha }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PYTHON_VERSION }} | |
| architecture: arm64 | |
| - name: Create virtual environment | |
| run: | | |
| python -m venv venv | |
| shell: pwsh | |
| - name: Get App Info | |
| id: get_info | |
| run: | | |
| .\venv\Scripts\Activate | |
| $currentDateTime = Get-Date -Format 'yyyy-MM-dd HH:mm:ss UTC' | |
| echo "BUILD_DATETIME=$currentDateTime" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| $prNumber = "${{ github.event.pull_request.number }}" | |
| echo "PR_NUMBER=$prNumber" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "BUILD_DATETIME=$currentDateTime" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| echo "PR_NUMBER=$prNumber" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append | |
| shell: pwsh | |
| - name: Update Release Channel | |
| run: | | |
| .\venv\Scripts\Activate | |
| $settingsPath = 'src/settings.py' | |
| $content = Get-Content $settingsPath -Raw | |
| $replacement = 'RELEASE_CHANNEL = "pr-' + $env:PR_NUMBER + '"' | |
| $content = $content -replace 'RELEASE_CHANNEL = "[^"]*"', $replacement | |
| Set-Content -Path $settingsPath -Value $content -NoNewline | |
| Write-Host "Updated RELEASE_CHANNEL to pr-$env:PR_NUMBER" | |
| shell: pwsh | |
| - name: Install dependencies | |
| run: | | |
| .\venv\Scripts\Activate | |
| python -m pip install --upgrade pip | |
| pip install --force --no-cache .[packaging] | |
| shell: pwsh | |
| - name: Build EXE | |
| run: | | |
| .\venv\Scripts\Activate | |
| cd src | |
| python build.py build | |
| shell: pwsh | |
| - name: Build MSI | |
| run: | | |
| .\venv\Scripts\Activate | |
| cd src | |
| python build.py bdist_msi | |
| shell: pwsh | |
| - name: Upload Build Artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: yasb-dev-pr-${{ steps.get_info.outputs.PR_NUMBER }}-aarch64 | |
| path: | | |
| src/dist/out/*.msi | |
| retention-days: 7 |