Build and Release for Linux and Windows #17
  
    
      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: Build and Release for Linux and Windows | |
| on: | |
| push: | |
| tags: | |
| - "v[0-9]+.[0-9]+.[0-9]+*" | |
| workflow_dispatch: | |
| inputs: | |
| tag_version: | |
| description: 'Version tag (e.g., v1.2.3)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: write | |
| jobs: | |
| create-packages: | |
| strategy: | |
| matrix: | |
| os: [ "ubuntu-latest", "windows-latest" ] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up environment for Linux (Ubuntu) | |
| if: matrix.os == 'ubuntu-latest' | |
| run: | | |
| sudo apt update | |
| sudo apt install -y python3-venv build-essential | |
| echo "Environment setup complete." | |
| - name: Set up environment for Windows | |
| if: matrix.os == 'windows-latest' | |
| run: | | |
| choco install python --yes | |
| python -m ensurepip | |
| echo "Environment setup complete." | |
| - name: Install dependencies and build for Linux | |
| if: matrix.os == 'ubuntu-latest' | |
| shell: bash | |
| run: | | |
| chmod +x build.sh # 确保脚本可执行 | |
| ./build.sh # 运行Bash脚本 | |
| - name: Install dependencies and build for Windows | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| .\build.ps1 # 运行PowerShell脚本 | |
| - name: Upload build output as artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: app-${{ matrix.os }} | |
| path: | | |
| build/app.dist/** | |
| if-no-files-found: error | |
| release: | |
| runs-on: "ubuntu-latest" | |
| needs: ["create-packages"] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: release | |
| pattern: app-* | |
| merge-multiple: true | |
| - name: Determine Version | |
| id: determine_version | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| echo "version=${{ github.event.inputs.tag_version }}" >> $GITHUB_OUTPUT | |
| else | |
| echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Show the output tree of release | |
| run: | | |
| tree release | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.determine_version.outputs.version }} # 使用确定的版本作为标签 | |
| prerelease: ${{ contains(github.ref_name, '-pre') || contains(steps.determine_version.outputs.version, '-pre') }} # 示例:如果版本包含'-pre',标记为预发布 | |
| make_latest: legacy | |
| draft: true | |
| files: | | |
| release/app-*/**/* # 上传所有下载的工件 | |
| - name: Clean up artifacts | |
| uses: geekyeggo/delete-artifact@v5 | |
| with: | |
| name: app-* |