Package and Release(old) #37
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: Package and Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: 'Tag name (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| release_name: | |
| description: 'Release title' | |
| required: true | |
| type: string | |
| jobs: | |
| package-and-release: | |
| runs-on: windows-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.12' | |
| - name: UPX Setup | |
| run: | | |
| mkdir upx | |
| curl -o upx/upx.exe https://assets.ksable.top/github/upx/upx/v5.0.1/upx.exe | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pyinstaller pyyaml | |
| - name: Fix Python encoding (Windows) | |
| run: | | |
| # 设置Python使用UTF-8编码 | |
| [System.Environment]::SetEnvironmentVariable('PYTHONUTF8', '1', 'Process') | |
| # 设置控制台编码为UTF-8 | |
| chcp.com 65001 | |
| - name: Run packaging script | |
| run: | | |
| cd package | |
| python build.py config.yml | |
| - name: Create Release | |
| id: create_release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.event.inputs.tag_name }} | |
| release_name: ${{ github.event.inputs.release_name }} | |
| draft: false | |
| prerelease: false | |
| # 修复上传步骤 - 上传dist目录中的所有可执行文件 | |
| - name: Upload Release Assets | |
| run: | | |
| $releaseTag = "${{ github.event.inputs.tag_name }}" | |
| $uploadUrl = "${{ steps.create_release.outputs.upload_url }}" | |
| # 获取所有可执行文件 | |
| $exeFiles = Get-ChildItem -Path .\dist -Recurse -Filter *.exe | |
| foreach ($file in $exeFiles) { | |
| $fileName = $file.Name | |
| $filePath = $file.FullName | |
| Write-Host "Uploading: $fileName" | |
| # 使用curl上传文件 | |
| curl.exe --request POST ` | |
| --url "$uploadUrl?name=$fileName" ` | |
| --header "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" ` | |
| --header "Content-Type: application/octet-stream" ` | |
| --data-binary "@$filePath" | |
| } | |
| shell: pwsh |