|
| 1 | +name: Package (Windows) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, master] |
| 6 | + pull_request: |
| 7 | + branches: [main, master] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: package-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + build-windows: |
| 16 | + runs-on: windows-latest |
| 17 | + permissions: |
| 18 | + contents: write |
| 19 | + env: |
| 20 | + APP_NAME: RPGTranslationAssistant |
| 21 | + SPEC_FILE: RPGTranslationAssistant.spec |
| 22 | + PYTHONUTF8: "1" |
| 23 | + PYTHONIOENCODING: "utf-8" |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + uses: actions/setup-python@v5 |
| 30 | + with: |
| 31 | + python-version: "3.11" |
| 32 | + cache: pip |
| 33 | + |
| 34 | + - name: Install dependencies |
| 35 | + shell: pwsh |
| 36 | + run: | |
| 37 | + python -m pip install --upgrade pip |
| 38 | + pip install -r requirements.txt |
| 39 | +
|
| 40 | + - name: Ensure app_config.json exists for packaging |
| 41 | + shell: pwsh |
| 42 | + run: | |
| 43 | + if (-not (Test-Path "app_config.json")) { |
| 44 | + "{}" | Set-Content -Path "app_config.json" -Encoding utf8 |
| 45 | + } |
| 46 | +
|
| 47 | + - name: Build with PyInstaller (.spec) |
| 48 | + shell: pwsh |
| 49 | + run: | |
| 50 | + python -m PyInstaller --noconfirm --clean $env:SPEC_FILE |
| 51 | +
|
| 52 | + - name: Zip dist output |
| 53 | + id: zip |
| 54 | + shell: pwsh |
| 55 | + run: | |
| 56 | + $shortSha = $env:GITHUB_SHA.Substring(0,7) |
| 57 | + if ($env:GITHUB_EVENT_NAME -eq "push") { |
| 58 | + $zipName = "$env:APP_NAME-windows-nightly.zip" |
| 59 | + } else { |
| 60 | + $zipName = "$env:APP_NAME-windows-sha-$shortSha.zip" |
| 61 | + } |
| 62 | + if (Test-Path $zipName) { Remove-Item -Force $zipName } |
| 63 | + Push-Location "dist" |
| 64 | + Compress-Archive -Path "$env:APP_NAME" -DestinationPath "..\\$zipName" -Force |
| 65 | + Pop-Location |
| 66 | + "zip_name=$zipName" | Out-File -FilePath $env:GITHUB_OUTPUT -Append -Encoding utf8 |
| 67 | +
|
| 68 | + - name: Upload artifact |
| 69 | + uses: actions/upload-artifact@v4 |
| 70 | + with: |
| 71 | + name: ${{ env.APP_NAME }}-windows |
| 72 | + path: ${{ steps.zip.outputs.zip_name }} |
| 73 | + if-no-files-found: error |
| 74 | + |
| 75 | + - name: Update nightly tag |
| 76 | + if: github.event_name == 'push' |
| 77 | + shell: pwsh |
| 78 | + run: | |
| 79 | + git config user.name "github-actions[bot]" |
| 80 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 81 | + git tag -f nightly $env:GITHUB_SHA |
| 82 | + git push -f origin nightly |
| 83 | +
|
| 84 | + - name: Publish/Update Nightly Release |
| 85 | + if: github.event_name == 'push' |
| 86 | + shell: pwsh |
| 87 | + env: |
| 88 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 89 | + run: | |
| 90 | + $tag = "nightly" |
| 91 | + $zip = "${{ steps.zip.outputs.zip_name }}" |
| 92 | + $notesFile = "release_notes.txt" |
| 93 | + $notes = "Automated build from $env:GITHUB_SHA`n`nCommit: $env:GITHUB_SERVER_URL/$env:GITHUB_REPOSITORY/commit/$env:GITHUB_SHA`n" |
| 94 | + $notes | Set-Content -Path $notesFile -Encoding utf8 |
| 95 | +
|
| 96 | + $exists = $true |
| 97 | + try { gh release view $tag | Out-Null } catch { $exists = $false } |
| 98 | +
|
| 99 | + if (-not $exists) { |
| 100 | + gh release create $tag $zip --title "Nightly" --notes-file $notesFile --prerelease --target $env:GITHUB_SHA |
| 101 | + } else { |
| 102 | + gh release edit $tag --title "Nightly" --notes-file $notesFile --prerelease |
| 103 | + gh release upload $tag $zip --clobber |
| 104 | + } |
0 commit comments