侧边栏壁纸
博主头像
996worker

祇園精舎の鐘の聲, 諸行無常の響き有り。

  • 累计撰写 186 篇文章
  • 累计创建 46 个标签
  • 累计收到 8 条评论

目 录CONTENT

文章目录

使用Github Action结合Pyinstaller把Python自动打包成exe应用

996worker
2022-08-02 / 0 评论 / 0 点赞 / 22 阅读 / 1,656 字
温馨提示:
本文最后更新于 2022-08-02,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

Github action script

name: PyInstaller Windows

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  push:
    branches: [ "main" ]
    
  pull_request:
    branches: [ "main" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build-windows:
    runs-on: windows-2019
    steps:
      - name: Checkout
        uses: actions/[email protected]
      - name: Install Python
        uses: actions/[email protected]
        with:
          python-version: '3.8'
          architecture: 'x64'
      - name: Install requirements and installer
        run: |
          pip install -r requirements.txt
          pip install pyinstaller
      - name: Run pyinstaller
        run: |
          python -m PyInstaller app.spec
      - uses: actions/[email protected]
        with:
          name: app
          path: dist/app
      
      - name: create release
        id: create_release
        uses: actions/[email protected]
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.run_number }}
          release_name: Release ${{ github.run_number }}
          body: |
            Test Release
          draft: false
          prerelease: false
          
      # Since we have a directory, create a zip
      - name: zip the artifect dir into a zip
        run: |
          powershell Compress-Archive D:\a\SWEN90013-Data-Platform-for-Biomaterial-Testing\SWEN90013-Data-Platform-for-Biomaterial-Testing\dist\app D:\a\SWEN90013-Data-Platform-for-Biomaterial-Testing\SWEN90013-Data-Platform-for-Biomaterial-Testing\dist\app.zip
      
      - name: Upload release asset
        id: upload-release-asset
        uses: actions/[email protected]
        env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
           upload_url: ${{ steps.create_release.outputs.upload_url }}
           asset_path: dist/app.zip
           asset_name: app.zip
           asset_content_type: application/zip

Known problem

Due to uses: actions/[email protected] item, the source code.zip in the Release will be assets that generated by pyinstaller, rather than source code. Be aware of that please.

0

评论区